Skip to content

Commit 8bdd2af

Browse files
committed
Kusto-phase3: rebase v23.10.5.20-stable
1 parent 16996aa commit 8bdd2af

28 files changed

+191
-205
lines changed

src/Client/ClientBase.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ ASTPtr ClientBase::parseQuery(const char *& pos, const char * end, bool allow_mu
352352
if (is_interactive || ignore_error)
353353
{
354354
String message;
355-
res = tryParseQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings.max_parser_depth);
355+
if (dialect == Dialect::kusto)
356+
res = tryParseKQLQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings.max_parser_depth);
357+
else
358+
res = tryParseQuery(*parser, pos, end, message, true, "", allow_multi_statements, max_length, settings.max_parser_depth);
356359

357360
if (!res)
358361
{
@@ -362,7 +365,10 @@ ASTPtr ClientBase::parseQuery(const char *& pos, const char * end, bool allow_mu
362365
}
363366
else
364367
{
365-
res = parseQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings.max_parser_depth);
368+
if (dialect == Dialect::kusto)
369+
res = parseKQLQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings.max_parser_depth);
370+
else
371+
res = parseQueryAndMovePosition(*parser, pos, end, "", allow_multi_statements, max_length, settings.max_parser_depth);
366372
}
367373

368374
if (is_interactive)

src/DataTypes/IDataType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ struct WhichDataType
388388
constexpr bool isDateOrDate32() const { return isDate() || isDate32(); }
389389
constexpr bool isDateTime() const { return idx == TypeIndex::DateTime; }
390390
constexpr bool isDateTime64() const { return idx == TypeIndex::DateTime64; }
391-
constexpr bool isDateOrDate32() const { return isDate() || isDate32(); }
391+
constexpr bool isDateTimeOrDateTime64() const { return isDateTime() || isDateTime64(); }
392392
constexpr bool isDateOrDate32OrDateTimeOrDateTime64() const { return isDate() || isDate32() || isDateTime() || isDateTime64(); }
393393

394394
constexpr bool isString() const { return idx == TypeIndex::String; }

src/Functions/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ list (APPEND OBJECT_LIBS $<TARGET_OBJECTS:clickhouse_functions_url>)
116116
add_subdirectory(array)
117117
list (APPEND OBJECT_LIBS $<TARGET_OBJECTS:clickhouse_functions_array>)
118118

119-
add_subdirectory(Kusto)
120-
list (APPEND OBJECT_LIBS $<TARGET_OBJECTS:clickhouse_functions_kusto>)
121-
122119
if (TARGET ch_contrib::datasketches)
123120
add_subdirectory(UniqTheta)
124121
list (APPEND OBJECT_LIBS $<TARGET_OBJECTS:clickhouse_functions_uniqtheta>)

src/Functions/Kusto/kqlIndexOfRegex.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
#include <Functions/FunctionHelpers.h>
88
#include <Functions/IFunction.h>
99

10+
#ifdef __clang__
11+
# pragma clang diagnostic push
12+
# pragma clang diagnostic ignored "-Wzero-as-null-pointer-constant"
13+
#endif
1014
#include <re2/re2.h>
15+
#ifdef __clang__
16+
# pragma clang diagnostic pop
17+
#endif
1118

1219
namespace DB::ErrorCodes
1320
{

src/Functions/byteSwap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ template <typename T>
3636
struct ByteSwapImpl
3737
{
3838
using ResultType = T;
39-
static constexpr const bool allow_string_or_fixed_string = false;
39+
static const constexpr bool allow_interval = true;
40+
static const constexpr bool allow_string_or_fixed_string = false;
4041
static T apply(T x) { return byteSwap<T>(x); }
4142

4243
#if USE_EMBEDDED_COMPILER

src/Functions/extract.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct KqlExtractImpl
8383
res_data.reserve(data.size() / 5);
8484
res_offsets.resize(offsets.size());
8585

86-
const Regexps::Regexp regexp = Regexps::createRegexp<false, false, false>(pattern);
86+
const OptimizedRegularExpression regexp = Regexps::createRegexp<false, false, false>(pattern);
8787

8888
OptimizedRegularExpression::MatchVec matches;
8989
matches.reserve(capture + 1);

src/Functions/toStartOfInterval.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,12 @@ class FunctionToStartOfInterval : public IFunction
453453
return return_type;
454454
}
455455

456-
bool useDefaultImplementationForConstants() const override { return true; }
457-
ColumnNumbers getArgumentsThatAreAlwaysConstant() const override { return {1, 2}; }
458-
459456
ColumnPtr executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, const size_t) const override
460457
{
461458
const auto & time_column = arguments[0];
462459
const auto & interval_column = arguments[1];
463460
const auto & time_zone = extractTimeZoneFromFunctionArguments(arguments, 2, 0);
464-
return dispatchForColumns(time_column, interval_column, result_type, time_zone);
461+
return dispatchForTimeColumn(time_column, interval_column, result_type, time_zone);
465462
}
466463

467464
private:

src/Interpreters/executeQuery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ static std::tuple<ASTPtr, BlockIO> executeQueryImpl(
711711
{
712712
ParserKQLStatement parser;
713713
/// TODO: parser should fail early when max_query_size limit is reached.
714-
ast = parseQuery(parser, begin, end, "", max_query_size, settings.max_parser_depth);
714+
ast = parseKQLQuery(parser, begin, end, "", max_query_size, settings.max_parser_depth);
715715
}
716716
else if (settings.dialect == Dialect::prql && !internal)
717717
{

src/Parsers/ExpressionElementParsers.cpp

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -105,70 +105,62 @@ bool ParserSubquery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
105105
{
106106
ParserSelectWithUnionQuery select;
107107
ParserExplainQuery explain;
108+
109+
if (pos->type != TokenType::OpeningRoundBracket)
110+
return false;
111+
++pos;
112+
108113
ASTPtr result_node = nullptr;
109-
ParserKeyword s_kql("KQL");
110114

111-
if (s_kql.ignore(pos, expected))
115+
if (ASTPtr select_node; select.parse(pos, select_node, expected))
112116
{
113-
if (KQLContext kql_context; !ParserKQLTableFunction(kql_context).parse(pos, result_node, expected))
114-
return false;
117+
result_node = std::move(select_node);
115118
}
116-
else
119+
else if (ASTPtr explain_node; explain.parse(pos, explain_node, expected))
117120
{
118-
if (pos->type != TokenType::OpeningRoundBracket)
119-
return false;
120-
++pos;
121-
122-
if (ASTPtr select_node; select.parse(pos, select_node, expected))
123-
{
124-
result_node = std::move(select_node);
125-
}
126-
else if (ASTPtr explain_node; explain.parse(pos, explain_node, expected))
127-
{
128-
const auto & explain_query = explain_node->as<const ASTExplainQuery &>();
121+
const auto & explain_query = explain_node->as<const ASTExplainQuery &>();
129122

130-
if (explain_query.getTableFunction() || explain_query.getTableOverride())
131-
throw Exception(ErrorCodes::BAD_ARGUMENTS, "EXPLAIN in a subquery cannot have a table function or table override");
123+
if (explain_query.getTableFunction() || explain_query.getTableOverride())
124+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "EXPLAIN in a subquery cannot have a table function or table override");
132125

133-
/// Replace subquery `(EXPLAIN <kind> <explain_settings> SELECT ...)`
134-
/// with `(SELECT * FROM viewExplain("<kind>", "<explain_settings>", SELECT ...))`
126+
/// Replace subquery `(EXPLAIN <kind> <explain_settings> SELECT ...)`
127+
/// with `(SELECT * FROM viewExplain("<kind>", "<explain_settings>", SELECT ...))`
135128

136-
String kind_str = ASTExplainQuery::toString(explain_query.getKind());
129+
String kind_str = ASTExplainQuery::toString(explain_query.getKind());
137130

138-
String settings_str;
139-
if (ASTPtr settings_ast = explain_query.getSettings())
140-
{
141-
if (!settings_ast->as<ASTSetQuery>())
142-
throw Exception(ErrorCodes::BAD_ARGUMENTS, "EXPLAIN settings must be a SET query");
143-
settings_str = queryToString(settings_ast);
144-
}
131+
String settings_str;
132+
if (ASTPtr settings_ast = explain_query.getSettings())
133+
{
134+
if (!settings_ast->as<ASTSetQuery>())
135+
throw Exception(ErrorCodes::BAD_ARGUMENTS, "EXPLAIN settings must be a SET query");
136+
settings_str = queryToString(settings_ast);
137+
}
145138

146-
const ASTPtr & explained_ast = explain_query.getExplainedQuery();
147-
if (explained_ast)
148-
{
149-
auto view_explain = makeASTFunction("viewExplain",
150-
std::make_shared<ASTLiteral>(kind_str),
151-
std::make_shared<ASTLiteral>(settings_str),
152-
explained_ast);
153-
result_node = buildSelectFromTableFunction(view_explain);
154-
}
155-
else
156-
{
157-
auto view_explain = makeASTFunction("viewExplain",
158-
std::make_shared<ASTLiteral>(kind_str),
159-
std::make_shared<ASTLiteral>(settings_str));
160-
result_node = buildSelectFromTableFunction(view_explain);
161-
}
139+
const ASTPtr & explained_ast = explain_query.getExplainedQuery();
140+
if (explained_ast)
141+
{
142+
auto view_explain = makeASTFunction("viewExplain",
143+
std::make_shared<ASTLiteral>(kind_str),
144+
std::make_shared<ASTLiteral>(settings_str),
145+
explained_ast);
146+
result_node = buildSelectFromTableFunction(view_explain);
162147
}
163148
else
164149
{
165-
return false;
150+
auto view_explain = makeASTFunction("viewExplain",
151+
std::make_shared<ASTLiteral>(kind_str),
152+
std::make_shared<ASTLiteral>(settings_str));
153+
result_node = buildSelectFromTableFunction(view_explain);
166154
}
167-
168-
if (pos->type != TokenType::ClosingRoundBracket)
169-
return false;
170-
++pos;
171155
}
156+
else
157+
{
158+
return false;
159+
}
160+
161+
if (pos->type != TokenType::ClosingRoundBracket)
162+
return false;
163+
++pos;
172164

173165
node = std::make_shared<ASTSubquery>();
174166
node->children.push_back(result_node);
@@ -178,16 +170,6 @@ bool ParserSubquery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
178170

179171
bool ParserIdentifier::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
180172
{
181-
/// 'kql(' is used for subuquery in Kusto, should not be treated as an identifier if kql followed by (
182-
ParserKeyword s_kql("KQL");
183-
if (s_kql.ignore(pos, expected))
184-
{
185-
if (pos->type == TokenType::OpeningRoundBracket)
186-
{ --pos;
187-
return false;
188-
}
189-
--pos;
190-
}
191173
/// Identifier in backquotes or in double quotes
192174
if (pos->type == TokenType::QuotedIdentifier)
193175
{

src/Parsers/ExpressionListParsers.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ class KustoLayer : public Layer
21702170
{
21712171
ASTPtr query;
21722172
--pos;
2173-
if (!ParserKQLTableFunction().parse(pos, query, expected))
2173+
if (KQLContext kql_context; !ParserKQLTableFunction(kql_context).parse(pos, query, expected))
21742174
return false;
21752175
--pos;
21762176
pushResult(query);
@@ -2234,9 +2234,13 @@ std::unique_ptr<Layer> getFunctionLayer(ASTPtr identifier, bool is_table_functio
22342234
const auto function_name = getIdentifierName(identifier);
22352235
const auto function_name_lowercase = Poco::toLower(function_name);
22362236

2237-
if (is_table_function
2238-
&& (function_name_lowercase == "getschema" || function_name_lowercase == "view" || function_name_lowercase == "viewifpermitted"))
2239-
return std::make_unique<ViewLayer>(function_name_lowercase);
2237+
if (is_table_function)
2238+
{
2239+
if (function_name_lowercase == "getschema" || function_name_lowercase == "view" || function_name_lowercase == "viewifpermitted")
2240+
return std::make_unique<ViewLayer>(function_name_lowercase);
2241+
if (function_name_lowercase == "kql")
2242+
return std::make_unique<KustoLayer>();
2243+
}
22402244

22412245
if (function_name == "tuple")
22422246
return std::make_unique<TupleLayer>();
@@ -2644,7 +2648,7 @@ Action ParserExpressionImpl::tryParseOperand(Layers & layers, IParser::Pos & pos
26442648
{
26452649
layers.back()->pushOperand(std::move(tmp));
26462650
}
2647-
else if (pos->type == TokenType::OpeningRoundBracket)
2651+
else if (pos->type == TokenType::OpeningRoundBracket || String(pos->begin , pos->end) == "kql")
26482652
{
26492653

26502654
if (subquery_parser.parse(pos, tmp, expected))

0 commit comments

Comments
 (0)