From 31a443203b21c185519768cdec8d48522475cdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=89=AC?= <654010905@qq.com> Date: Wed, 21 Sep 2022 20:44:15 -0500 Subject: [PATCH] Support functions for clickhouse backend: lower/upper/ltrim/rtrim (#117) * support more functions * commit again * remove function length * fix as requested --- .../Parser/SerializedPlanParser.cpp | 12 ++- .../Parser/SerializedPlanParser.h | 88 ++++++++++--------- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/utils/local-engine/Parser/SerializedPlanParser.cpp b/utils/local-engine/Parser/SerializedPlanParser.cpp index bb2553cc7fea..4396772a895c 100644 --- a/utils/local-engine/Parser/SerializedPlanParser.cpp +++ b/utils/local-engine/Parser/SerializedPlanParser.cpp @@ -40,7 +40,7 @@ #include #include #include - +#include #include "SerializedPlanParser.h" namespace DB @@ -323,7 +323,7 @@ Block SerializedPlanParser::parseNameStruct(const substrait::NamedStruct & struc return Block(*std::move(internal_cols)); } -DataTypePtr inline wrapNullableType(substrait::Type_Nullability nullable, DataTypePtr nested_type) +static DataTypePtr wrapNullableType(substrait::Type_Nullability nullable, DataTypePtr nested_type) { if (nullable == substrait::Type_Nullability_NULLABILITY_NULLABLE) { @@ -392,6 +392,14 @@ DataTypePtr SerializedPlanParser::parseType(const substrait::Type & type) } QueryPlanPtr SerializedPlanParser::parse(std::unique_ptr plan) { + { + namespace pb_util = google::protobuf::util; + pb_util::JsonOptions options; + std::string json; + pb_util::MessageToJsonString(*plan, &json, options); + LOG_DEBUG(&Poco::Logger::get("SerializedPlanParser"), "substrait plan:{}", json); + } + if (plan->extensions_size() > 0) { for (const auto & extension : plan->extensions()) diff --git a/utils/local-engine/Parser/SerializedPlanParser.h b/utils/local-engine/Parser/SerializedPlanParser.h index 123af15157dd..7ea4b0dd8482 100644 --- a/utils/local-engine/Parser/SerializedPlanParser.h +++ b/utils/local-engine/Parser/SerializedPlanParser.h @@ -20,46 +20,54 @@ namespace local_engine { -static const std::map SCALAR_FUNCTIONS - = {{"is_not_null", "isNotNull"}, - {"is_null", "isNull"}, - {"gte", "greaterOrEquals"}, - {"gt", "greater"}, - {"lte", "lessOrEquals"}, - {"lt", "less"}, - {"equal", "equals"}, - - {"and", "and"}, - {"or", "or"}, - {"not", "not"}, - {"xor", "xor"}, - - {"TO_DATE", "toDate"}, - {"extract", ""}, - {"cast", ""}, - {"alias", "alias"}, - - {"subtract", "minus"}, - {"multiply", "multiply"}, - {"add", "plus"}, - {"divide", "divide"}, - {"modulus", "modulo"}, - - {"like", "like"}, - {"not_like", "notLike"}, - {"starts_with", "startsWith"}, - {"ends_with", "endsWith"}, - {"contains", "countSubstrings"}, - {"substring", "substring"}, - - {"in", "in"}, - - // aggregate functions - {"count", "count"}, - {"avg", "avg"}, - {"sum", "sum"}, - {"min", "min"}, - {"max", "max"}}; + +static const std::map SCALAR_FUNCTIONS = { + {"is_not_null","isNotNull"}, + {"is_null","isNull"}, + {"gte","greaterOrEquals"}, + {"gt", "greater"}, + {"lte", "lessOrEquals"}, + {"lt", "less"}, + {"equal", "equals"}, + + {"and", "and"}, + {"or", "or"}, + {"not", "not"}, + {"xor", "xor"}, + + {"TO_DATE", "toDate"}, + {"extract", ""}, + {"cast", ""}, + {"alias", "alias"}, + + {"subtract", "minus"}, + {"multiply", "multiply"}, + {"add", "plus"}, + {"divide", "divide"}, + {"modulus", "modulo"}, + + /// string functions + {"like", "like"}, + {"not_like", "notLike"}, + {"starts_with", "startsWith"}, + {"ends_with", "endsWith"}, + {"contains", "countSubstrings"}, + {"substring", "substring"}, + {"lower", "lower"}, + {"upper", "upper"}, + {"ltrim", "trimLeft"}, + {"rtrim", "trimRight"}, + + // in functions + {"in", "in"}, + + // aggregate functions + {"count", "count"}, + {"avg", "avg"}, + {"sum", "sum"}, + {"min", "min"}, + {"max", "max"} +}; static const std::set FUNCTION_NEED_KEEP_ARGUMENTS = {"alias"};