From 52ead47d8f8dabb366cab56ae40dd856b3c9ac4d Mon Sep 17 00:00:00 2001 From: KevinyhZou Date: Wed, 5 Apr 2023 15:35:04 +0800 Subject: [PATCH 1/2] adapt get json object --- utils/local-engine/Common/QueryContext.h | 2 +- utils/local-engine/Parser/SerializedPlanParser.cpp | 8 +++++++- utils/local-engine/Parser/SerializedPlanParser.h | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/utils/local-engine/Common/QueryContext.h b/utils/local-engine/Common/QueryContext.h index 50b52c5563e4..d6525f4a5f86 100644 --- a/utils/local-engine/Common/QueryContext.h +++ b/utils/local-engine/Common/QueryContext.h @@ -17,7 +17,7 @@ struct NativeAllocatorContext { std::shared_ptr query_scope; std::shared_ptr thread_status; - DB::ContextPtr query_context; + DB::ContextMutablePtr query_context; ReservationListenerWrapperPtr listener; }; diff --git a/utils/local-engine/Parser/SerializedPlanParser.cpp b/utils/local-engine/Parser/SerializedPlanParser.cpp index 9dcd3d732e4d..d7e03ef589ec 100644 --- a/utils/local-engine/Parser/SerializedPlanParser.cpp +++ b/utils/local-engine/Parser/SerializedPlanParser.cpp @@ -1470,6 +1470,12 @@ const ActionsDAG::Node * SerializedPlanParser::parseFunctionWithDAG( SerializedPlanParser::parseType(rel.scalar_function().output_type())->getName(), function_node->result_name); } + if (function_name == "JSON_VALUE") + { + context->setSetting("function_json_value_return_type_allow_complex", true); + context->setSetting("function_json_value_return_type_allow_nullable", true); + result_node->function->setResolver(function_builder); + } if (keep_result) actions_dag->addOrReplaceInOutputs(*result_node); } @@ -2095,7 +2101,7 @@ void SerializedPlanParser::initFunctionEnv() registerFunctions(); registerAggregateFunctions(); } -SerializedPlanParser::SerializedPlanParser(const ContextPtr & context_) : context(context_) +SerializedPlanParser::SerializedPlanParser(const ContextMutablePtr & context_) : context(context_) { } ContextMutablePtr SerializedPlanParser::global_context = nullptr; diff --git a/utils/local-engine/Parser/SerializedPlanParser.h b/utils/local-engine/Parser/SerializedPlanParser.h index 9f86c7c96236..0fc10436003e 100644 --- a/utils/local-engine/Parser/SerializedPlanParser.h +++ b/utils/local-engine/Parser/SerializedPlanParser.h @@ -207,7 +207,7 @@ class SerializedPlanParser friend class RelParser; friend class ASTParser; public: - explicit SerializedPlanParser(const ContextPtr & context); + explicit SerializedPlanParser(const ContextMutablePtr & context); static void initFunctionEnv(); DB::QueryPlanPtr parse(const std::string & plan); DB::QueryPlanPtr parseJson(const std::string & json_plan); @@ -352,7 +352,7 @@ class SerializedPlanParser std::unordered_map function_mapping; std::vector input_iters; const substrait::ProjectRel * last_project = nullptr; - ContextPtr context; + ContextMutablePtr context; }; From 03b43bbfa37ac94e61393ac2fe15cc4c283a5408 Mon Sep 17 00:00:00 2001 From: KevinyhZou Date: Thu, 6 Apr 2023 20:41:00 +0800 Subject: [PATCH 2/2] review fix --- utils/local-engine/Common/CHUtil.cpp | 2 ++ utils/local-engine/Common/QueryContext.h | 2 +- utils/local-engine/Parser/SerializedPlanParser.cpp | 4 +--- utils/local-engine/Parser/SerializedPlanParser.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/local-engine/Common/CHUtil.cpp b/utils/local-engine/Common/CHUtil.cpp index de1d38fe1ec2..d07badf2ad07 100644 --- a/utils/local-engine/Common/CHUtil.cpp +++ b/utils/local-engine/Common/CHUtil.cpp @@ -528,6 +528,8 @@ void BackendInitializerUtil::initSettings() settings.set("input_format_orc_case_insensitive_column_matching", true); settings.set("input_format_parquet_allow_missing_columns", true); settings.set("input_format_parquet_case_insensitive_column_matching", true); + settings.set("function_json_value_return_type_allow_complex", true); + settings.set("function_json_value_return_type_allow_nullable", true); } void BackendInitializerUtil::initContexts() diff --git a/utils/local-engine/Common/QueryContext.h b/utils/local-engine/Common/QueryContext.h index d6525f4a5f86..50b52c5563e4 100644 --- a/utils/local-engine/Common/QueryContext.h +++ b/utils/local-engine/Common/QueryContext.h @@ -17,7 +17,7 @@ struct NativeAllocatorContext { std::shared_ptr query_scope; std::shared_ptr thread_status; - DB::ContextMutablePtr query_context; + DB::ContextPtr query_context; ReservationListenerWrapperPtr listener; }; diff --git a/utils/local-engine/Parser/SerializedPlanParser.cpp b/utils/local-engine/Parser/SerializedPlanParser.cpp index d7e03ef589ec..4882e97e0794 100644 --- a/utils/local-engine/Parser/SerializedPlanParser.cpp +++ b/utils/local-engine/Parser/SerializedPlanParser.cpp @@ -1472,8 +1472,6 @@ const ActionsDAG::Node * SerializedPlanParser::parseFunctionWithDAG( } if (function_name == "JSON_VALUE") { - context->setSetting("function_json_value_return_type_allow_complex", true); - context->setSetting("function_json_value_return_type_allow_nullable", true); result_node->function->setResolver(function_builder); } if (keep_result) @@ -2101,7 +2099,7 @@ void SerializedPlanParser::initFunctionEnv() registerFunctions(); registerAggregateFunctions(); } -SerializedPlanParser::SerializedPlanParser(const ContextMutablePtr & context_) : context(context_) +SerializedPlanParser::SerializedPlanParser(const ContextPtr & context_) : context(context_) { } ContextMutablePtr SerializedPlanParser::global_context = nullptr; diff --git a/utils/local-engine/Parser/SerializedPlanParser.h b/utils/local-engine/Parser/SerializedPlanParser.h index 0fc10436003e..9f86c7c96236 100644 --- a/utils/local-engine/Parser/SerializedPlanParser.h +++ b/utils/local-engine/Parser/SerializedPlanParser.h @@ -207,7 +207,7 @@ class SerializedPlanParser friend class RelParser; friend class ASTParser; public: - explicit SerializedPlanParser(const ContextMutablePtr & context); + explicit SerializedPlanParser(const ContextPtr & context); static void initFunctionEnv(); DB::QueryPlanPtr parse(const std::string & plan); DB::QueryPlanPtr parseJson(const std::string & json_plan); @@ -352,7 +352,7 @@ class SerializedPlanParser std::unordered_map function_mapping; std::vector input_iters; const substrait::ProjectRel * last_project = nullptr; - ContextMutablePtr context; + ContextPtr context; };