github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/agg/bit_or.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 BitOr[T1 types.Ints | types.UInts | types.Floats] struct {
    23  }
    24  
    25  func BitOrReturnType(_ []types.Type) types.Type {
    26  	return types.New(types.T_uint64, 0, 0, 0)
    27  }
    28  
    29  func NewBitOr[T1 types.Ints | types.UInts | types.Floats]() *BitOr[T1] {
    30  	return &BitOr[T1]{}
    31  }
    32  
    33  func (bo *BitOr[T1]) Grows(_ int) {
    34  }
    35  
    36  func (bo *BitOr[T1]) Eval(vs []uint64) []uint64 {
    37  	return vs
    38  }
    39  
    40  func (bo *BitOr[T1]) Merge(_, _ int64, x, y uint64, IsEmpty1 bool, IsEmpty2 bool, _ any) (uint64, bool) {
    41  	if IsEmpty1 && !IsEmpty2 {
    42  		return y, false
    43  	} else if IsEmpty2 && !IsEmpty1 {
    44  		return x, false
    45  	} else if IsEmpty1 && IsEmpty2 {
    46  		return x, true
    47  	} else {
    48  		return x | y, false
    49  	}
    50  }
    51  
    52  func (bo *BitOr[T1]) Fill(_ int64, v1 T1, v2 uint64, _ int64, IsEmpty bool, hasNull bool) (uint64, bool) {
    53  	if hasNull {
    54  		return v2, IsEmpty
    55  	} else if IsEmpty {
    56  		if float64(v1) > math.MaxUint64 {
    57  			return math.MaxInt64, false
    58  		}
    59  		if float64(v1) < 0 {
    60  			return uint64(int64(v1)), false
    61  		}
    62  		return uint64(v1), false
    63  	} else {
    64  		if float64(v1) > math.MaxUint64 {
    65  			return math.MaxInt64 | v2, false
    66  		}
    67  		if float64(v1) < 0 {
    68  			return uint64(int64(v1)) | v2, false
    69  		}
    70  		return uint64(v1) | v2, false
    71  	}
    72  }
    73  
    74  func (bo *BitOr[T1]) MarshalBinary() ([]byte, error) {
    75  	return nil, nil
    76  }
    77  
    78  func (bo *BitOr[T1]) UnmarshalBinary(data []byte) error {
    79  	return nil
    80  }