Skip to content

Commit

Permalink
Fix Build due to ClickHouse/ClickHouse#68107
Browse files Browse the repository at this point in the history
  • Loading branch information
baibaichen committed Aug 15, 2024
1 parent f330845 commit 16465e3
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 29 deletions.
15 changes: 9 additions & 6 deletions cpp-ch/local-engine/Common/CHUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@
#include <Interpreters/JIT/CompiledExpressionCache.h>
#include <Parser/RelParser.h>
#include <Parser/SerializedPlanParser.h>
#include <Planner/PlannerActionsVisitor.h>
#include <Processors/Chunk.h>
#include <Processors/QueryPlan/ExpressionStep.h>
#include <Processors/QueryPlan/QueryPlan.h>
#include <QueryPipeline/QueryPipelineBuilder.h>
#include <QueryPipeline/printPipeline.h>
#include <Storages/Cache/CacheManager.h>
#include <Storages/Output/WriteBufferBuilder.h>
#include <Storages/StorageMergeTreeFactory.h>
#include <Storages/SubstraitSource/ReadBufferBuilder.h>
Expand All @@ -72,7 +74,6 @@
#include <Common/LoggerExtend.h>
#include <Common/logger_useful.h>
#include <Common/typeid_cast.h>
#include <Storages/Cache/CacheManager.h>

namespace DB
{
Expand Down Expand Up @@ -463,20 +464,22 @@ const DB::ColumnWithTypeAndName * NestedColumnExtractHelper::findColumn(const DB
const DB::ActionsDAG::Node * ActionsDAGUtil::convertNodeType(
DB::ActionsDAG & actions_dag,
const DB::ActionsDAG::Node * node,
const std::string & type_name,
const DataTypePtr & cast_to_type,
const std::string & result_name,
CastType cast_type)
{
DB::ColumnWithTypeAndName type_name_col;
type_name_col.name = type_name;
type_name_col.name = cast_to_type->getName();
type_name_col.column = DB::DataTypeString().createColumnConst(0, type_name_col.name);
type_name_col.type = std::make_shared<DB::DataTypeString>();
const auto * right_arg = &actions_dag.addColumn(std::move(type_name_col));
const auto * left_arg = node;
DB::CastDiagnostic diagnostic = {node->result_name, node->result_name};
ColumnWithTypeAndName left_column{nullptr, node->result_type, {}};
DB::ActionsDAG::NodeRawConstPtrs children = {left_arg, right_arg};
return &actions_dag.addFunction(
DB::createInternalCastOverloadResolver(cast_type, std::move(diagnostic)), std::move(children), result_name);
auto func_base_cast = createInternalCast(std::move(left_column), cast_to_type, cast_type, diagnostic);

return &actions_dag.addFunction(func_base_cast, std::move(children), result_name);
}

const DB::ActionsDAG::Node * ActionsDAGUtil::convertNodeTypeIfNeeded(
Expand All @@ -489,7 +492,7 @@ const DB::ActionsDAG::Node * ActionsDAGUtil::convertNodeTypeIfNeeded(
if (node->result_type->equals(*dst_type))
return node;

return convertNodeType(actions_dag, node, dst_type->getName(), result_name, cast_type);
return convertNodeType(actions_dag, node, dst_type, result_name, cast_type);
}

String QueryPipelineUtil::explainPipeline(DB::QueryPipeline & pipeline)
Expand Down
4 changes: 2 additions & 2 deletions cpp-ch/local-engine/Common/CHUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ class ActionsDAGUtil
public:
static const DB::ActionsDAG::Node * convertNodeType(
DB::ActionsDAG & actions_dag,
const DB::ActionsDAG::Node * node,
const std::string & type_name,
const DB::ActionsDAG::Node * node_to_cast,
const DB::DataTypePtr & cast_to_type,
const std::string & result_name = "",
DB::CastType cast_type = DB::CastType::nonAccurate);

Expand Down
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Parser/AggregateFunctionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const DB::ActionsDAG::Node * AggregateFunctionParser::convertNodeTypeIfNeeded(
if (need_convert_type)
{
func_node = ActionsDAGUtil::convertNodeType(
actions_dag, func_node, TypeParser::parseType(output_type)->getName(), func_node->result_name);
actions_dag, func_node, TypeParser::parseType(output_type), func_node->result_name);
actions_dag.addOrReplaceInOutputs(*func_node);
}

Expand Down
8 changes: 4 additions & 4 deletions cpp-ch/local-engine/Parser/FunctionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ const ActionsDAG::Node * FunctionParser::convertNodeTypeIfNeeded(
actions_dag,
func_node,
// as stated in isTypeMatched, currently we don't change nullability of the result type
func_node->result_type->isNullable() ? local_engine::wrapNullableType(true, result_type)->getName()
: local_engine::removeNullable(result_type)->getName(),
func_node->result_type->isNullable() ? local_engine::wrapNullableType(true, result_type)
: local_engine::removeNullable(result_type),
func_node->result_name,
CastType::accurateOrNull);
}
Expand All @@ -91,8 +91,8 @@ const ActionsDAG::Node * FunctionParser::convertNodeTypeIfNeeded(
actions_dag,
func_node,
// as stated in isTypeMatched, currently we don't change nullability of the result type
func_node->result_type->isNullable() ? local_engine::wrapNullableType(true, TypeParser::parseType(output_type))->getName()
: DB::removeNullable(TypeParser::parseType(output_type))->getName(),
func_node->result_type->isNullable() ? local_engine::wrapNullableType(true, TypeParser::parseType(output_type))
: DB::removeNullable(TypeParser::parseType(output_type)),
func_node->result_name);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ ActionsDAG::NodeRawConstPtrs SerializedPlanParser::parseArrayJoinWithDAG(

/// pos = cast(arrayJoin(arg_not_null).1, "Int32")
const auto * pos_node = add_tuple_element(array_join_node, 1);
pos_node = ActionsDAGUtil::convertNodeType(actions_dag, pos_node, "Int32");
pos_node = ActionsDAGUtil::convertNodeType(actions_dag, pos_node, INT());

/// if is_map is false, output col = arrayJoin(arg_not_null).2
/// if is_map is true, output (key, value) = arrayJoin(arg_not_null).2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <DataTypes/DataTypeNullable.h>
#include <DataTypes/DataTypesNumber.h>
#include <Interpreters/ActionsDAG.h>
#include <Common/BlockTypeUtils.h>
#include <Common/CHUtil.h>

namespace local_engine
Expand All @@ -41,7 +42,7 @@ LeadParser::parseFunctionArguments(const CommonFunctionInfo & func_info, DB::Act
node = ActionsDAGUtil::convertNodeType(
actions_dag,
&actions_dag.findInOutputs(arg0_col_name),
DB::makeNullable(arg0_col_type)->getName(),
DB::makeNullable(arg0_col_type),
arg0_col_name);
actions_dag.addOrReplaceInOutputs(*node);
args.push_back(node);
Expand All @@ -52,7 +53,7 @@ LeadParser::parseFunctionArguments(const CommonFunctionInfo & func_info, DB::Act
}

node = parseExpression(actions_dag, arg1);
node = ActionsDAGUtil::convertNodeType(actions_dag, node, DB::DataTypeInt64().getName());
node = ActionsDAGUtil::convertNodeType(actions_dag, node, BIGINT());
actions_dag.addOrReplaceInOutputs(*node);
args.push_back(node);

Expand Down Expand Up @@ -84,7 +85,7 @@ LagParser::parseFunctionArguments(const CommonFunctionInfo & func_info, DB::Acti
node = ActionsDAGUtil::convertNodeType(
actions_dag,
&actions_dag.findInOutputs(arg0_col_name),
DB::makeNullable(arg0_col_type)->getName(),
makeNullable(arg0_col_type),
arg0_col_name);
actions_dag.addOrReplaceInOutputs(*node);
args.push_back(node);
Expand All @@ -100,7 +101,7 @@ LagParser::parseFunctionArguments(const CommonFunctionInfo & func_info, DB::Acti
auto real_field = 0 - literal_result.second.safeGet<Int32>();
node = &actions_dag.addColumn(ColumnWithTypeAndName(
literal_result.first->createColumnConst(1, real_field), literal_result.first, getUniqueName(toString(real_field))));
node = ActionsDAGUtil::convertNodeType(actions_dag, node, DB::DataTypeInt64().getName());
node = ActionsDAGUtil::convertNodeType(actions_dag, node, BIGINT());
actions_dag.addOrReplaceInOutputs(*node);
args.push_back(node);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <Parser/TypeParser.h>
#include <Parser/scalar_function_parser/lambdaFunction.h>
#include <Poco/Logger.h>
#include <Common/BlockTypeUtils.h>
#include <Common/CHUtil.h>
#include <Common/Exception.h>
#include <Common/logger_useful.h>
Expand Down Expand Up @@ -60,7 +61,7 @@ class ArrayFilter : public FunctionParser
/// filter with index argument.
const auto * range_end_node = toFunctionNode(actions_dag, "length", {toFunctionNode(actions_dag, "assumeNotNull", {parsed_args[0]})});
range_end_node = ActionsDAGUtil::convertNodeType(
actions_dag, range_end_node, "Nullable(Int32)", range_end_node->result_name);
actions_dag, range_end_node, makeNullable(INT()), range_end_node->result_name);
const auto * index_array_node = toFunctionNode(
actions_dag,
"range",
Expand Down Expand Up @@ -106,7 +107,7 @@ class ArrayTransform : public FunctionParser
/// transform with index argument.
const auto * range_end_node = toFunctionNode(actions_dag, "length", {toFunctionNode(actions_dag, "assumeNotNull", {parsed_args[0]})});
range_end_node = ActionsDAGUtil::convertNodeType(
actions_dag, range_end_node, "Nullable(Int32)", range_end_node->result_name);
actions_dag, range_end_node, makeNullable(INT()), range_end_node->result_name);
const auto * index_array_node = toFunctionNode(
actions_dag,
"range",
Expand Down Expand Up @@ -141,7 +142,7 @@ class ArrayAggregate : public FunctionParser
parsed_args[1] = ActionsDAGUtil::convertNodeType(
actions_dag,
parsed_args[1],
function_type->getReturnType()->getName(),
function_type->getReturnType(),
parsed_args[1]->result_name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class FunctionParserArrayPosition : public FunctionParser
DataTypePtr wrap_arr_nullable_type = wrapNullableType(true, ch_function_node->result_type);

const auto * wrap_index_of_node = ActionsDAGUtil::convertNodeType(
actions_dag, ch_function_node, wrap_arr_nullable_type->getName(), ch_function_node->result_name);
actions_dag, ch_function_node, wrap_arr_nullable_type, ch_function_node->result_name);
const auto * null_const_node = addColumnToActionsDAG(actions_dag, wrap_arr_nullable_type, Field{});
const auto * or_condition_node = toFunctionNode(actions_dag, "or", {arr_is_null_node, val_is_null_node});

Expand Down
2 changes: 1 addition & 1 deletion cpp-ch/local-engine/Parser/scalar_function_parser/elt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FunctionParserElt : public FunctionParser
auto nullable_result_type = makeNullable(result_type);

const auto * nullable_array_element_node = ActionsDAGUtil::convertNodeType(
actions_dag, array_element_node, nullable_result_type->getName(), array_element_node->result_name);
actions_dag, array_element_node, nullable_result_type, array_element_node->result_name);

const auto * null_const_node = addColumnToActionsDAG(actions_dag, nullable_result_type, Field());
const auto * is_null_node = toFunctionNode(actions_dag, "isNull", {index_arg});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/IDataType.h>
#include <Parser/FunctionParser.h>
#include <Common/BlockTypeUtils.h>
#include <Common/CHUtil.h>

namespace DB
Expand Down Expand Up @@ -73,9 +74,9 @@ class FunctionParserFindInSet : public FunctionParser
if (!str_is_nullable && !str_array_is_nullable)
return convertNodeTypeIfNeeded(substrait_func, index_of_node, actions_dag);

auto nullable_result_type = makeNullable(std::make_shared<DataTypeInt32>());
auto nullable_result_type = makeNullable(INT());
const auto * nullable_index_of_node = ActionsDAGUtil::convertNodeType(
actions_dag, index_of_node, nullable_result_type->getName(), index_of_node->result_name);
actions_dag, index_of_node, nullable_result_type, index_of_node->result_name);
const auto * null_const_node = addColumnToActionsDAG(actions_dag, nullable_result_type, Field());

const auto * str_is_null_node = toFunctionNode(actions_dag, "isNull", {str_arg});
Expand Down
3 changes: 2 additions & 1 deletion cpp-ch/local-engine/Parser/scalar_function_parser/locate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <DataTypes/IDataType.h>
#include <Parser/FunctionParser.h>
#include <Common/BlockTypeUtils.h>
#include <Common/CHUtil.h>

namespace DB
Expand Down Expand Up @@ -50,7 +51,7 @@ class FunctionParserLocate : public FunctionParser

const auto * substr_arg = parsed_args[0];
const auto * str_arg = parsed_args[1];
const auto * start_pos_arg = ActionsDAGUtil::convertNodeType(actions_dag, parsed_args[2], "Nullable(UInt32)");
const auto * start_pos_arg = ActionsDAGUtil::convertNodeType(actions_dag, parsed_args[2], makeNullable(UINT()));
const auto * is_start_pos_null_node = toFunctionNode(actions_dag, "isNull", {start_pos_arg});
const auto * const_1_node = addColumnToActionsDAG(actions_dag, std::make_shared<DataTypeUInt64>(), 0);
const auto * position_node = toFunctionNode(actions_dag, "positionUTF8Spark", {str_arg, substr_arg, start_pos_arg});
Expand Down
4 changes: 2 additions & 2 deletions cpp-ch/local-engine/Parser/scalar_function_parser/repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <DataTypes/DataTypeNumberBase.h>
#include <Parser/FunctionParser.h>
#include <Parser/TypeParser.h>
#include <Common/BlockTypeUtils.h>
#include <Common/CHUtil.h>
#include <Common/Exception.h>

Expand All @@ -42,8 +43,7 @@ class SparkFunctionRepeatParser : public FunctionParser
const auto & args = substrait_func.arguments();
parsed_args.emplace_back(parseExpression(actions_dag, args[0].value()));
const auto * repeat_times_node = parseExpression(actions_dag, args[1].value());
DB::DataTypeNullable target_type(std::make_shared<DB::DataTypeUInt32>());
repeat_times_node = ActionsDAGUtil::convertNodeType(actions_dag, repeat_times_node, target_type.getName());
repeat_times_node = ActionsDAGUtil::convertNodeType(actions_dag, repeat_times_node, makeNullable(UINT()));
parsed_args.emplace_back(repeat_times_node);
const auto * func_node = toFunctionNode(actions_dag, ch_function_name, parsed_args);
return convertNodeTypeIfNeeded(substrait_func, func_node, actions_dag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class FunctionParserArraySlice : public FunctionParser
DataTypePtr wrap_arr_nullable_type = wrapNullableType(true, slice_node->result_type);

const auto * wrap_slice_node = ActionsDAGUtil::convertNodeType(
actions_dag, slice_node, wrap_arr_nullable_type->getName(), slice_node->result_name);
actions_dag, slice_node, wrap_arr_nullable_type, slice_node->result_name);
const auto * null_const_node = addColumnToActionsDAG(actions_dag, wrap_arr_nullable_type, Field{});

const auto * arr_is_null_node = toFunctionNode(actions_dag, "isNull", {arr_arg});
Expand Down

0 comments on commit 16465e3

Please sign in to comment.