#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 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 place, ConstAggregateDataPtr rhs, Arena *) const override { this->data(place).update(this->data(rhs).value); } void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override { writeBinary(this->data(place).value, buf); } void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override { readBinary(this->data(place).value, buf); } void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override { static_cast &>(to).getData().push_back(this->data(place).value); } const char * getHeaderFilePath() const override { return __FILE__; } }; }