// 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. #include #include #include #include namespace DB::GatherUtils { /// Creates IArraySink from ColumnArray template struct ArraySinkCreator; template struct ArraySinkCreator { static std::unique_ptr create(ColumnArray & col, NullMap * null_map, size_t column_size) { if (typeid_cast *>(&col.getData())) { if (null_map) return std::make_unique>>(col, *null_map, column_size); return std::make_unique>(col, column_size); } return ArraySinkCreator::create(col, null_map, column_size); } }; template <> struct ArraySinkCreator<> { static std::unique_ptr create(ColumnArray & col, NullMap * null_map, size_t column_size) { if (null_map) return std::make_unique>(col, *null_map, column_size); return std::make_unique(col, column_size); } }; std::unique_ptr createArraySink(ColumnArray & col, size_t column_size) { using Creator = ApplyTypeListForClass::Type; if (auto * column_nullable = typeid_cast(&col.getData())) { auto column = ColumnArray::create( column_nullable->getNestedColumnPtr()->assumeMutable(), col.getOffsetsPtr()->assumeMutable()); return Creator::create(*column, &column_nullable->getNullMapData(), column_size); } return Creator::create(col, nullptr, column_size); } } // namespace DB::GatherUtils