// Copyright 2023 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include #include #include #include namespace DB { template struct AggregateFunctionGroupBitOrData { T value = 0; static const char * name() { return "groupBitOr"; } void update(T x) { value |= x; } }; template struct AggregateFunctionGroupBitAndData { T value = -1; /// Two's complement arithmetic, sign extension. static const char * name() { return "groupBitAnd"; } void update(T x) { value &= x; } }; template struct AggregateFunctionGroupBitXorData { T value = 0; static const char * name() { return "groupBitXor"; } void update(T x) { value ^= x; } }; /// Counts bitwise operation on numbers. template class AggregateFunctionBitwise final : public IAggregateFunctionDataHelper> { public: String getName() const override { return Data::name(); } DataTypePtr getReturnType() const override { return std::make_shared>(); } void add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena *) const override { this->data(place).update(static_cast &>(*columns[0]).getData()[row_num]); } void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, Arena *) const override { this->data(place).update(this->data(rhs).value); } void serialize(ConstAggregateDataPtr __restrict place, WriteBuffer & buf) const override { writeBinary(this->data(place).value, buf); } void deserialize(AggregateDataPtr __restrict place, ReadBuffer & buf, Arena *) const override { readBinary(this->data(place).value, buf); } void insertResultInto(ConstAggregateDataPtr __restrict place, IColumn & to, Arena *) const override { static_cast &>(to).getData().push_back(this->data(place).value); } const char * getHeaderFilePath() const override { return __FILE__; } }; } // namespace DB