// 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 namespace DB { class UniqRawResReformatBlockOutputStream : public IProfilingBlockInputStream { public: explicit UniqRawResReformatBlockOutputStream(const BlockInputStreamPtr & in_) : in(in_) {} String getName() const override { return "UniqRawResReformat"; } Block getHeader() const override { return in->getHeader(); } protected: Block readImpl() override { while (true) { Block block = in->read(); if (!block) return block; size_t num_columns = block.columns(); MutableColumns columns(num_columns); for (size_t i = 0; i < num_columns; ++i) { ColumnWithTypeAndName & ori_column = block.getByPosition(i); if (std::string::npos != ori_column.name.find_first_of(uniq_raw_res_name)) { MutableColumnPtr mutable_holder = ori_column.column->cloneEmpty(); for (size_t j = 0; j < ori_column.column->size(); ++j) { Field field; ori_column.column->get(j, field); auto & str_ref = field.safeGet(); ReadBufferFromString in(str_ref); AggregateFunctionUniqUniquesHashSetDataForVariadicRawRes set; set.set.read(in); mutable_holder->insert(std::to_string(set.set.size())); } ori_column.column = std::move(mutable_holder); } } return block; } } private: BlockInputStreamPtr in; }; } // namespace DB