2022-06-08 17:14:03 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
|
|
|
#include <Parsers/ASTSelectWithUnionQuery.h>
|
2023-01-17 21:08:33 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
|
|
|
#include <Parsers/IParserBase.h>
|
|
|
|
#include <Parsers/Kusto/KustoFunctions/KQLFunctionFactory.h>
|
2022-06-08 17:14:03 +00:00
|
|
|
#include <Parsers/Kusto/ParserKQLQuery.h>
|
|
|
|
#include <Parsers/Kusto/ParserKQLStatement.h>
|
2023-01-17 21:08:33 +00:00
|
|
|
#include <Parsers/ParserSetQuery.h>
|
2022-06-29 05:03:36 +00:00
|
|
|
|
2022-06-08 17:14:03 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
bool ParserKQLStatement::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
|
|
|
ParserKQLWithOutput query_with_output_p(end, allow_settings_after_format_in_insert);
|
|
|
|
ParserSetQuery set_p;
|
|
|
|
|
2023-01-17 21:08:33 +00:00
|
|
|
bool res = query_with_output_p.parse(pos, node, expected) || set_p.parse(pos, node, expected);
|
2022-06-08 17:14:03 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParserKQLWithOutput::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
2022-06-11 17:33:38 +00:00
|
|
|
ParserKQLWithUnionQuery kql_p;
|
2022-06-08 17:14:03 +00:00
|
|
|
|
|
|
|
ASTPtr query;
|
2022-06-11 17:33:38 +00:00
|
|
|
bool parsed = kql_p.parse(pos, query, expected);
|
2022-06-08 17:14:03 +00:00
|
|
|
|
|
|
|
if (!parsed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
node = std::move(query);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ParserKQLWithUnionQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|
|
|
{
|
2022-06-08 17:14:03 +00:00
|
|
|
// will support union next phase
|
2022-06-11 17:33:38 +00:00
|
|
|
ASTPtr kql_query;
|
2022-06-08 17:14:03 +00:00
|
|
|
|
2022-06-11 17:33:38 +00:00
|
|
|
if (!ParserKQLQuery().parse(pos, kql_query, expected))
|
2022-06-08 17:14:03 +00:00
|
|
|
return false;
|
|
|
|
|
2022-06-11 17:33:38 +00:00
|
|
|
if (kql_query->as<ASTSelectWithUnionQuery>())
|
2022-06-08 17:14:03 +00:00
|
|
|
{
|
2022-06-11 17:33:38 +00:00
|
|
|
node = std::move(kql_query);
|
2022-06-08 17:14:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto list_node = std::make_shared<ASTExpressionList>();
|
2022-06-11 17:33:38 +00:00
|
|
|
list_node->children.push_back(kql_query);
|
2022-06-08 17:14:03 +00:00
|
|
|
|
|
|
|
auto select_with_union_query = std::make_shared<ASTSelectWithUnionQuery>();
|
|
|
|
node = select_with_union_query;
|
|
|
|
select_with_union_query->list_of_selects = list_node;
|
|
|
|
select_with_union_query->children.push_back(select_with_union_query->list_of_selects);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-04-03 01:14:09 +00:00
|
|
|
bool ParserKQLTableFunction::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
2022-06-29 05:03:36 +00:00
|
|
|
{
|
|
|
|
ParserKQLWithUnionQuery kql_p;
|
|
|
|
ASTPtr select;
|
|
|
|
ParserToken s_lparen(TokenType::OpeningRoundBracket);
|
|
|
|
|
|
|
|
auto begin = pos;
|
2023-01-17 21:08:33 +00:00
|
|
|
auto paren_count = 0;
|
2022-06-29 05:03:36 +00:00
|
|
|
String kql_statement;
|
|
|
|
|
|
|
|
if (s_lparen.ignore(pos, expected))
|
2023-01-17 21:08:33 +00:00
|
|
|
{
|
2022-06-29 05:03:36 +00:00
|
|
|
++paren_count;
|
2022-09-14 06:12:14 +00:00
|
|
|
auto pos_start = pos;
|
2022-06-29 05:03:36 +00:00
|
|
|
while (!pos->isEnd())
|
|
|
|
{
|
|
|
|
if (pos->type == TokenType::ClosingRoundBracket)
|
|
|
|
--paren_count;
|
|
|
|
if (pos->type == TokenType::OpeningRoundBracket)
|
|
|
|
++paren_count;
|
|
|
|
|
|
|
|
if (paren_count == 0)
|
|
|
|
break;
|
|
|
|
++pos;
|
|
|
|
}
|
2022-09-14 06:12:14 +00:00
|
|
|
kql_statement = String(pos_start->begin, (--pos)->end);
|
|
|
|
++pos;
|
2022-06-29 05:03:36 +00:00
|
|
|
|
|
|
|
Tokens token_kql(kql_statement.c_str(), kql_statement.c_str() + kql_statement.size());
|
|
|
|
IParser::Pos pos_kql(token_kql, pos.max_depth);
|
|
|
|
|
|
|
|
if (kql_p.parse(pos_kql, select, expected))
|
|
|
|
{
|
|
|
|
node = select;
|
|
|
|
++pos;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2023-01-17 21:08:33 +00:00
|
|
|
pos = begin;
|
2022-06-29 05:03:36 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2022-06-08 17:14:03 +00:00
|
|
|
}
|