forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from ClibMouse/Kusto-p3-range-op
Kusto-phase3: Add kql range operator
- Loading branch information
Showing
7 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#include <format> | ||
#include <Parsers/ExpressionListParsers.h> | ||
#include <Parsers/Kusto/ParserKQLQuery.h> | ||
#include <Parsers/Kusto/ParserKQLRange.h> | ||
#include <Parsers/ParserSelectQuery.h> | ||
namespace DB | ||
{ | ||
|
||
namespace ErrorCodes | ||
{ | ||
extern const int SYNTAX_ERROR; | ||
} | ||
|
||
bool ParserKQLRange::parseImpl(Pos & pos, ASTPtr & node, Expected & /*expected*/) | ||
{ | ||
ASTPtr select_node; | ||
String columnName, start, stop, step; | ||
auto start_pos = pos; | ||
auto end_pos = pos; | ||
while (!pos->isEnd() && pos->type != TokenType::PipeMark && pos->type != TokenType::Semicolon) | ||
{ | ||
if (String(pos->begin, pos->end) == "from") | ||
{ | ||
end_pos = pos; | ||
--end_pos; | ||
if (end_pos < start_pos) | ||
throw Exception("Missing columnName for range operator", ErrorCodes::SYNTAX_ERROR); | ||
|
||
columnName = String(start_pos->begin, end_pos->end); | ||
start_pos = pos; | ||
++start_pos; | ||
} | ||
if (String(pos->begin, pos->end) == "to") | ||
{ | ||
if (columnName.empty()) | ||
throw Exception("Missing `from` for range operator", ErrorCodes::SYNTAX_ERROR); | ||
end_pos = pos; | ||
--end_pos; | ||
if (end_pos < start_pos) | ||
throw Exception("Missing start expression for range operator", ErrorCodes::SYNTAX_ERROR); | ||
start = String(start_pos->begin, end_pos->end); | ||
start_pos = pos; | ||
++start_pos; | ||
} | ||
if (String(pos->begin, pos->end) == "step") | ||
{ | ||
if (columnName.empty()) | ||
throw Exception("Missing `from` for range operator", ErrorCodes::SYNTAX_ERROR); | ||
if (start.empty()) | ||
throw Exception("Missing 'to' for range operator", ErrorCodes::SYNTAX_ERROR); | ||
|
||
end_pos = pos; | ||
--end_pos; | ||
if (end_pos < start_pos) | ||
throw Exception("Missing stop expression for range operator", ErrorCodes::SYNTAX_ERROR); | ||
|
||
stop = String(start_pos->begin, end_pos->end); | ||
start_pos = pos; | ||
++start_pos; | ||
} | ||
++pos; | ||
} | ||
|
||
if (columnName.empty() || start.empty() || stop.empty()) | ||
throw Exception("Missing required expression for range operator", ErrorCodes::SYNTAX_ERROR); | ||
|
||
end_pos = pos; | ||
--end_pos; | ||
if (end_pos < start_pos) | ||
throw Exception("Missing step expression for range operator", ErrorCodes::SYNTAX_ERROR); | ||
|
||
step = String(start_pos->begin, end_pos->end); | ||
|
||
columnName = getExprFromToken(columnName, pos.max_depth); | ||
start = getExprFromToken(start, pos.max_depth); | ||
stop = getExprFromToken(stop, pos.max_depth); | ||
step = getExprFromToken(step, pos.max_depth); | ||
String query = std::format("SELECT * FROM (SELECT kql_range({0}, {1},{2}) AS {3}) ARRAY JOIN {3}", start, stop, step, columnName); | ||
|
||
if (!parseSQLQueryByString(std::make_unique<ParserSelectQuery>(), query, select_node, pos.max_depth)) | ||
return false; | ||
node = std::move(select_node); | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <Parsers/IParserBase.h> | ||
#include <Parsers/Kusto/ParserKQLQuery.h> | ||
|
||
namespace DB | ||
{ | ||
|
||
class ParserKQLRange : public ParserKQLBase | ||
{ | ||
protected: | ||
const char * getName() const override { return "KQL range"; } | ||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters