Skip to content

Commit

Permalink
Support functions for clickhouse backend: lower/upper/ltrim/rtrim (#117)
Browse files Browse the repository at this point in the history
* support more functions

* commit again

* remove function length

* fix as requested
  • Loading branch information
taiyang-li authored Sep 22, 2022
1 parent c5ba2bf commit 31a4432
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 42 deletions.
12 changes: 10 additions & 2 deletions utils/local-engine/Parser/SerializedPlanParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <Common/JoinHelper.h>
#include <Common/MergeTreeTool.h>
#include <Common/StringUtils.h>

#include <google/protobuf/util/json_util.h>
#include "SerializedPlanParser.h"

namespace DB
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -392,6 +392,14 @@ DataTypePtr SerializedPlanParser::parseType(const substrait::Type & type)
}
QueryPlanPtr SerializedPlanParser::parse(std::unique_ptr<substrait::Plan> 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())
Expand Down
88 changes: 48 additions & 40 deletions utils/local-engine/Parser/SerializedPlanParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,54 @@

namespace local_engine
{
static const std::map<std::string, std::string> 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<std::string, std::string> 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<std::string> FUNCTION_NEED_KEEP_ARGUMENTS = {"alias"};

Expand Down

0 comments on commit 31a4432

Please sign in to comment.