github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/agg/bit_and.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package agg 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 "math" 20 ) 21 22 type BitAnd[T1 types.Ints | types.UInts | types.Floats] struct { 23 } 24 25 func BitAndReturnType(typs []types.Type) types.Type { 26 switch typs[0].Oid { 27 case types.T_float32, types.T_float64: 28 return types.New(types.T_uint64, 0, 0, 0) 29 case types.T_int8, types.T_int16, types.T_int32, types.T_int64: 30 return types.New(types.T_uint64, 0, 0, 0) 31 case types.T_uint8, types.T_uint16, types.T_uint32, types.T_uint64: 32 return types.New(types.T_uint64, 0, 0, 0) 33 } 34 return types.Type{} 35 } 36 37 func NewBitAnd[T1 types.Ints | types.UInts | types.Floats]() *BitAnd[T1] { 38 return &BitAnd[T1]{} 39 } 40 41 func (ba *BitAnd[T1]) Grows(_ int) { 42 } 43 44 func (ba *BitAnd[T1]) Eval(vs []uint64) []uint64 { 45 return vs 46 } 47 48 func (ba *BitAnd[T1]) Merge(groupIndex1, groupIndex2 int64, x, y uint64, isEmpty1 bool, isEmpty2 bool, agg any) (uint64, bool) { 49 if isEmpty1 { 50 x = ^uint64(0) 51 } 52 if isEmpty2 { 53 y = ^uint64(0) 54 } 55 return x & y, isEmpty1 && isEmpty2 56 } 57 58 func (ba *BitAnd[T1]) Fill(groupIndex int64, v1 T1, v2 uint64, z int64, isEmpty bool, hasNull bool) (uint64, bool) { 59 if hasNull { 60 return v2, isEmpty 61 } 62 if isEmpty { 63 v2 = ^uint64(0) 64 } 65 66 if float64(v1) > math.MaxUint64 { 67 return math.MaxInt64 & v2, false 68 } 69 if float64(v1) < 0 { 70 return uint64(int64(v1)) & v2, false 71 } 72 return uint64(v1) & v2, false 73 } 74 75 func (ba *BitAnd[T1]) MarshalBinary() ([]byte, error) { 76 return nil, nil 77 } 78 79 func (ba *BitAnd[T1]) UnmarshalBinary(data []byte) error { 80 return nil 81 }