diff --git a/cpp-ch/local-engine/Common/BlockTypeUtils.cpp b/cpp-ch/local-engine/Common/BlockTypeUtils.cpp new file mode 100644 index 0000000000000..f6dcd0959225b --- /dev/null +++ b/cpp-ch/local-engine/Common/BlockTypeUtils.cpp @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 "BlockTypeUtils.h" + +#include +#include + +namespace local_engine +{ +DB::NamesAndTypesList blockToNameAndTypeList(const DB::Block & header) +{ + DB::NamesAndTypesList types; + for (const auto & name : header.getNames()) + { + const auto * column = header.findByName(name); + types.push_back(DB::NameAndTypePair(column->name, column->type)); + } + return types; +} + +DB::DataTypePtr wrapNullableType(bool nullable, DB::DataTypePtr nested_type) +{ + if (nullable && !nested_type->isNullable()) + { + if (nested_type->isLowCardinalityNullable()) + return nested_type; + else if (!nested_type->lowCardinality()) + return std::make_shared(nested_type); + else + return std::make_shared( + std::make_shared(dynamic_cast(*nested_type).getDictionaryType())); + } + + + if (nullable && !nested_type->isNullable()) + return std::make_shared(nested_type); + else + return nested_type; +} + +} \ No newline at end of file diff --git a/cpp-ch/local-engine/Common/BlockTypeUtils.h b/cpp-ch/local-engine/Common/BlockTypeUtils.h new file mode 100644 index 0000000000000..af01b528d6e9c --- /dev/null +++ b/cpp-ch/local-engine/Common/BlockTypeUtils.h @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 local_engine +{ +inline DB::DataTypePtr BIGINT() +{ + return std::make_shared(); +} +inline DB::DataTypePtr INT() +{ + return std::make_shared(); +} +inline DB::DataTypePtr INT16() +{ + return std::make_shared(); +} +inline DB::DataTypePtr INT8() +{ + return std::make_shared(); +} +inline DB::DataTypePtr UBIGINT() +{ + return std::make_shared(); +} +inline DB::DataTypePtr UINT() +{ + return std::make_shared(); +} +inline DB::DataTypePtr UINT16() +{ + return std::make_shared(); +} +inline DB::DataTypePtr UINT8() +{ + return std::make_shared(); +} + +inline DB::DataTypePtr DOUBLE() +{ + return std::make_shared(); +} + +inline DB::DataTypePtr STRING() +{ + return std::make_shared(); +} + +inline DB::DataTypePtr DATE() +{ + return std::make_shared(); +} + +inline DB::Block makeBlockHeader(const DB::ColumnsWithTypeAndName & data_) +{ + return DB::Block(data_); +} + +DB::NamesAndTypesList blockToNameAndTypeList(const DB::Block & header); +DB::DataTypePtr wrapNullableType(bool nullable, DB::DataTypePtr nested_type); + +inline DB::DataTypePtr wrapNullableType(const substrait::Type_Nullability nullable, const DB::DataTypePtr & nested_type) +{ + return wrapNullableType(nullable == substrait::Type_Nullability_NULLABILITY_NULLABLE, nested_type); +} + +} diff --git a/cpp-ch/local-engine/Parser/FunctionParser.cpp b/cpp-ch/local-engine/Parser/FunctionParser.cpp index 206fb6c50ec97..513470d0c250b 100644 --- a/cpp-ch/local-engine/Parser/FunctionParser.cpp +++ b/cpp-ch/local-engine/Parser/FunctionParser.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include namespace DB diff --git a/cpp-ch/local-engine/Parser/SerializedPlanParser.cpp b/cpp-ch/local-engine/Parser/SerializedPlanParser.cpp index 7189c215e6a47..17612b9f9d10c 100644 --- a/cpp-ch/local-engine/Parser/SerializedPlanParser.cpp +++ b/cpp-ch/local-engine/Parser/SerializedPlanParser.cpp @@ -78,6 +78,7 @@ #include #include #include +#include #include #include #include @@ -99,19 +100,7 @@ extern const int ILLEGAL_TYPE_OF_ARGUMENT; extern const int INVALID_JOIN_ON_EXPRESSION; } } -namespace -{ -DB::NamesAndTypesList blockToNameAndTypeList(const DB::Block & header) -{ - DB::NamesAndTypesList types; - for (const auto & name : header.getNames()) - { - const auto * column = header.findByName(name); - types.push_back(DB::NameAndTypePair(column->name, column->type)); - } - return types; -} -} + namespace local_engine { using namespace DB; @@ -360,37 +349,6 @@ IQueryPlanStep * SerializedPlanParser::addRollbackFilterHeaderStep(QueryPlanPtr return step_ptr; } -DataTypePtr wrapNullableType(substrait::Type_Nullability nullable, DataTypePtr nested_type) -{ - return wrapNullableType(nullable == substrait::Type_Nullability_NULLABILITY_NULLABLE, nested_type); -} - -DataTypePtr wrapNullableType(bool nullable, DataTypePtr nested_type) -{ - if (nullable && !nested_type->isNullable()) - { - if (nested_type->isLowCardinalityNullable()) - { - return nested_type; - } - else - { - if (!nested_type->lowCardinality()) - return std::make_shared(nested_type); - else - return std::make_shared( - std::make_shared( - dynamic_cast(*nested_type).getDictionaryType())); - } - } - - - if (nullable && !nested_type->isNullable()) - return std::make_shared(nested_type); - else - return nested_type; -} - void adjustOutput(const DB::QueryPlanPtr & query_plan, const substrait::PlanRel & root_rel) { if (root_rel.root().names_size()) @@ -795,16 +753,13 @@ const ActionsDAG::Node * SerializedPlanParser::parseFunctionWithDAG( } void SerializedPlanParser::parseFunctionArguments( - ActionsDAGPtr & actions_dag, - ActionsDAG::NodeRawConstPtrs & parsed_args, - const substrait::Expression_ScalarFunction & scalar_function) + ActionsDAGPtr & actions_dag, ActionsDAG::NodeRawConstPtrs & parsed_args, const substrait::Expression_ScalarFunction & scalar_function) { auto function_signature = function_mapping.at(std::to_string(scalar_function.function_reference())); const auto & args = scalar_function.arguments(); parsed_args.reserve(args.size()); for (const auto & arg : args) parsed_args.emplace_back(parseExpression(actions_dag, arg.value())); - } // Convert signed integer index into unsigned integer index diff --git a/cpp-ch/local-engine/Parser/SerializedPlanParser.h b/cpp-ch/local-engine/Parser/SerializedPlanParser.h index 76002c80d786b..a7d77fde84c1b 100644 --- a/cpp-ch/local-engine/Parser/SerializedPlanParser.h +++ b/cpp-ch/local-engine/Parser/SerializedPlanParser.h @@ -35,9 +35,6 @@ namespace local_engine { -DataTypePtr wrapNullableType(substrait::Type_Nullability nullable, DataTypePtr nested_type); -DataTypePtr wrapNullableType(bool nullable, DataTypePtr nested_type); - std::string join(const ActionsDAG::NodeRawConstPtrs & v, char c); class SerializedPlanParser; diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/arithmetic.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/arithmetic.cpp index 7d8c3f948c631..b621798c3b308 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/arithmetic.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/arithmetic.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace DB::ErrorCodes diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/arrayPosition.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/arrayPosition.cpp index d3eed7c67568d..528a80c075a64 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/arrayPosition.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/arrayPosition.cpp @@ -14,10 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include +#include #include +#include +#include #include -#include namespace DB { diff --git a/cpp-ch/local-engine/Parser/scalar_function_parser/slice.cpp b/cpp-ch/local-engine/Parser/scalar_function_parser/slice.cpp index 2dca0cee182e2..46f00ce7cf552 100644 --- a/cpp-ch/local-engine/Parser/scalar_function_parser/slice.cpp +++ b/cpp-ch/local-engine/Parser/scalar_function_parser/slice.cpp @@ -14,10 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include #include #include +#include +#include +#include namespace DB {