mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-26 01:22:04 +00:00
Better implementation
This commit is contained in:
parent
72acedfba6
commit
1a090e9901
@ -11,6 +11,7 @@
|
|||||||
#include <Parsers/ASTQualifiedAsterisk.h>
|
#include <Parsers/ASTQualifiedAsterisk.h>
|
||||||
#include <Parsers/ASTColumnsMatcher.h>
|
#include <Parsers/ASTColumnsMatcher.h>
|
||||||
#include <Parsers/ASTExpressionList.h>
|
#include <Parsers/ASTExpressionList.h>
|
||||||
|
#include <Parsers/ASTColumnsTransformers.h>
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
@ -206,11 +207,15 @@ QueryTreeNodePtr MatcherNode::cloneImpl() const
|
|||||||
ASTPtr MatcherNode::toASTImpl() const
|
ASTPtr MatcherNode::toASTImpl() const
|
||||||
{
|
{
|
||||||
ASTPtr result;
|
ASTPtr result;
|
||||||
|
ASTPtr transformers;
|
||||||
|
|
||||||
auto transformers = std::make_shared<ASTExpressionList>();
|
if (!children.empty())
|
||||||
|
{
|
||||||
|
transformers = std::make_shared<ASTColumnsTransformerList>();
|
||||||
|
|
||||||
for (const auto & child : children)
|
for (const auto & child : children)
|
||||||
transformers->children.push_back(child->toAST());
|
transformers->children.push_back(child->toAST());
|
||||||
|
}
|
||||||
|
|
||||||
if (matcher_type == MatcherNodeType::ASTERISK)
|
if (matcher_type == MatcherNodeType::ASTERISK)
|
||||||
{
|
{
|
||||||
@ -218,8 +223,11 @@ ASTPtr MatcherNode::toASTImpl() const
|
|||||||
{
|
{
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
auto asterisk = std::make_shared<ASTAsterisk>();
|
||||||
|
|
||||||
|
if (transformers)
|
||||||
|
{
|
||||||
asterisk->transformers = std::move(transformers);
|
asterisk->transformers = std::move(transformers);
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
asterisk->children.push_back(asterisk->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
result = asterisk;
|
result = asterisk;
|
||||||
}
|
}
|
||||||
@ -229,10 +237,13 @@ ASTPtr MatcherNode::toASTImpl() const
|
|||||||
|
|
||||||
auto identifier_parts = qualified_identifier.getParts();
|
auto identifier_parts = qualified_identifier.getParts();
|
||||||
qualified_asterisk->qualifier = std::make_shared<ASTIdentifier>(std::move(identifier_parts));
|
qualified_asterisk->qualifier = std::make_shared<ASTIdentifier>(std::move(identifier_parts));
|
||||||
qualified_asterisk->transformers = std::move(transformers);
|
|
||||||
|
|
||||||
qualified_asterisk->children.push_back(qualified_asterisk->qualifier);
|
qualified_asterisk->children.push_back(qualified_asterisk->qualifier);
|
||||||
|
|
||||||
|
if (transformers)
|
||||||
|
{
|
||||||
|
qualified_asterisk->transformers = std::move(transformers);
|
||||||
qualified_asterisk->children.push_back(qualified_asterisk->transformers);
|
qualified_asterisk->children.push_back(qualified_asterisk->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
result = qualified_asterisk;
|
result = qualified_asterisk;
|
||||||
}
|
}
|
||||||
@ -244,8 +255,11 @@ ASTPtr MatcherNode::toASTImpl() const
|
|||||||
auto regexp_matcher = std::make_shared<ASTColumnsRegexpMatcher>();
|
auto regexp_matcher = std::make_shared<ASTColumnsRegexpMatcher>();
|
||||||
regexp_matcher->setPattern(columns_matcher->pattern());
|
regexp_matcher->setPattern(columns_matcher->pattern());
|
||||||
|
|
||||||
|
if (transformers)
|
||||||
|
{
|
||||||
regexp_matcher->transformers = std::move(transformers);
|
regexp_matcher->transformers = std::move(transformers);
|
||||||
regexp_matcher->children.push_back(regexp_matcher->transformers);
|
regexp_matcher->children.push_back(regexp_matcher->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
result = regexp_matcher;
|
result = regexp_matcher;
|
||||||
}
|
}
|
||||||
@ -256,10 +270,13 @@ ASTPtr MatcherNode::toASTImpl() const
|
|||||||
|
|
||||||
auto identifier_parts = qualified_identifier.getParts();
|
auto identifier_parts = qualified_identifier.getParts();
|
||||||
regexp_matcher->qualifier = std::make_shared<ASTIdentifier>(std::move(identifier_parts));
|
regexp_matcher->qualifier = std::make_shared<ASTIdentifier>(std::move(identifier_parts));
|
||||||
regexp_matcher->transformers = std::move(transformers);
|
|
||||||
|
|
||||||
regexp_matcher->children.push_back(regexp_matcher->qualifier);
|
regexp_matcher->children.push_back(regexp_matcher->qualifier);
|
||||||
|
|
||||||
|
if (transformers)
|
||||||
|
{
|
||||||
|
regexp_matcher->transformers = std::move(transformers);
|
||||||
regexp_matcher->children.push_back(regexp_matcher->transformers);
|
regexp_matcher->children.push_back(regexp_matcher->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
result = regexp_matcher;
|
result = regexp_matcher;
|
||||||
}
|
}
|
||||||
@ -279,10 +296,13 @@ ASTPtr MatcherNode::toASTImpl() const
|
|||||||
{
|
{
|
||||||
auto columns_list_matcher = std::make_shared<ASTColumnsListMatcher>();
|
auto columns_list_matcher = std::make_shared<ASTColumnsListMatcher>();
|
||||||
columns_list_matcher->column_list = std::move(column_list);
|
columns_list_matcher->column_list = std::move(column_list);
|
||||||
columns_list_matcher->transformers = std::move(transformers);
|
|
||||||
|
|
||||||
columns_list_matcher->children.push_back(columns_list_matcher->column_list);
|
columns_list_matcher->children.push_back(columns_list_matcher->column_list);
|
||||||
|
|
||||||
|
if (transformers)
|
||||||
|
{
|
||||||
|
columns_list_matcher->transformers = std::move(transformers);
|
||||||
columns_list_matcher->children.push_back(columns_list_matcher->transformers);
|
columns_list_matcher->children.push_back(columns_list_matcher->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
result = columns_list_matcher;
|
result = columns_list_matcher;
|
||||||
}
|
}
|
||||||
@ -293,11 +313,14 @@ ASTPtr MatcherNode::toASTImpl() const
|
|||||||
auto identifier_parts = qualified_identifier.getParts();
|
auto identifier_parts = qualified_identifier.getParts();
|
||||||
columns_list_matcher->qualifier = std::make_shared<ASTIdentifier>(std::move(identifier_parts));
|
columns_list_matcher->qualifier = std::make_shared<ASTIdentifier>(std::move(identifier_parts));
|
||||||
columns_list_matcher->column_list = std::move(column_list);
|
columns_list_matcher->column_list = std::move(column_list);
|
||||||
columns_list_matcher->transformers = std::move(transformers);
|
|
||||||
|
|
||||||
columns_list_matcher->children.push_back(columns_list_matcher->qualifier);
|
columns_list_matcher->children.push_back(columns_list_matcher->qualifier);
|
||||||
columns_list_matcher->children.push_back(columns_list_matcher->column_list);
|
columns_list_matcher->children.push_back(columns_list_matcher->column_list);
|
||||||
|
|
||||||
|
if (transformers)
|
||||||
|
{
|
||||||
|
columns_list_matcher->transformers = std::move(transformers);
|
||||||
columns_list_matcher->children.push_back(columns_list_matcher->transformers);
|
columns_list_matcher->children.push_back(columns_list_matcher->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
result = columns_list_matcher;
|
result = columns_list_matcher;
|
||||||
}
|
}
|
||||||
|
@ -809,6 +809,9 @@ ColumnTransformersNodes QueryTreeBuilder::buildColumnTransformers(const ASTPtr &
|
|||||||
{
|
{
|
||||||
ColumnTransformersNodes column_transformers;
|
ColumnTransformersNodes column_transformers;
|
||||||
|
|
||||||
|
if (!matcher_expression)
|
||||||
|
return column_transformers;
|
||||||
|
|
||||||
for (const auto & child : matcher_expression->children)
|
for (const auto & child : matcher_expression->children)
|
||||||
{
|
{
|
||||||
if (auto * apply_transformer = child->as<ASTColumnsApplyTransformer>())
|
if (auto * apply_transformer = child->as<ASTColumnsApplyTransformer>())
|
||||||
|
@ -50,9 +50,7 @@ ASTPtr makeSubqueryQualifiedAsterisk()
|
|||||||
{
|
{
|
||||||
auto asterisk = std::make_shared<ASTQualifiedAsterisk>();
|
auto asterisk = std::make_shared<ASTQualifiedAsterisk>();
|
||||||
asterisk->qualifier = std::make_shared<ASTIdentifier>("--.s");
|
asterisk->qualifier = std::make_shared<ASTIdentifier>("--.s");
|
||||||
asterisk->transformers = std::make_shared<ASTExpressionList>();
|
|
||||||
asterisk->children.push_back(asterisk->qualifier);
|
asterisk->children.push_back(asterisk->qualifier);
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
|
||||||
return asterisk;
|
return asterisk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +140,12 @@ private:
|
|||||||
for (auto & table_name : data.tables_order)
|
for (auto & table_name : data.tables_order)
|
||||||
data.addTableColumns(table_name, columns);
|
data.addTableColumns(table_name, columns);
|
||||||
|
|
||||||
|
if (asterisk->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : asterisk->transformers->children)
|
for (const auto & transformer : asterisk->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (const auto * qualified_asterisk = child->as<ASTQualifiedAsterisk>())
|
else if (const auto * qualified_asterisk = child->as<ASTQualifiedAsterisk>())
|
||||||
{
|
{
|
||||||
has_asterisks = true;
|
has_asterisks = true;
|
||||||
@ -155,9 +156,12 @@ private:
|
|||||||
|
|
||||||
data.addTableColumns(identifier.name(), columns);
|
data.addTableColumns(identifier.name(), columns);
|
||||||
|
|
||||||
|
if (qualified_asterisk->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : qualified_asterisk->transformers->children)
|
for (const auto & transformer : qualified_asterisk->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (const auto * columns_list_matcher = child->as<ASTColumnsListMatcher>())
|
else if (const auto * columns_list_matcher = child->as<ASTColumnsListMatcher>())
|
||||||
{
|
{
|
||||||
has_asterisks = true;
|
has_asterisks = true;
|
||||||
@ -165,9 +169,12 @@ private:
|
|||||||
for (const auto & ident : columns_list_matcher->column_list->children)
|
for (const auto & ident : columns_list_matcher->column_list->children)
|
||||||
columns.emplace_back(ident->clone());
|
columns.emplace_back(ident->clone());
|
||||||
|
|
||||||
|
if (columns_list_matcher->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : columns_list_matcher->transformers->children)
|
for (const auto & transformer : columns_list_matcher->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (const auto * columns_regexp_matcher = child->as<ASTColumnsRegexpMatcher>())
|
else if (const auto * columns_regexp_matcher = child->as<ASTColumnsRegexpMatcher>())
|
||||||
{
|
{
|
||||||
has_asterisks = true;
|
has_asterisks = true;
|
||||||
@ -178,9 +185,12 @@ private:
|
|||||||
columns,
|
columns,
|
||||||
[&](const String & column_name) { return columns_regexp_matcher->isColumnMatching(column_name); });
|
[&](const String & column_name) { return columns_regexp_matcher->isColumnMatching(column_name); });
|
||||||
|
|
||||||
|
if (columns_regexp_matcher->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : columns_regexp_matcher->transformers->children)
|
for (const auto & transformer : columns_regexp_matcher->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
data.new_select_expression_list->children.push_back(child);
|
data.new_select_expression_list->children.push_back(child);
|
||||||
|
|
||||||
@ -409,12 +419,7 @@ private:
|
|||||||
if (!data.done)
|
if (!data.done)
|
||||||
{
|
{
|
||||||
if (data.expression_list->children.empty())
|
if (data.expression_list->children.empty())
|
||||||
{
|
data.expression_list->children.emplace_back(std::make_shared<ASTAsterisk>());
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
|
||||||
asterisk->transformers = std::make_shared<ASTExpressionList>();
|
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
|
||||||
data.expression_list->children.push_back(std::move(asterisk));
|
|
||||||
}
|
|
||||||
|
|
||||||
select.setExpression(ASTSelectQuery::Expression::SELECT, std::move(data.expression_list));
|
select.setExpression(ASTSelectQuery::Expression::SELECT, std::move(data.expression_list));
|
||||||
}
|
}
|
||||||
|
@ -96,12 +96,7 @@ void replaceJoinedTable(const ASTSelectQuery & select_query)
|
|||||||
|
|
||||||
auto new_select = addASTChildren<ASTSelectQuery>(*list_of_selects);
|
auto new_select = addASTChildren<ASTSelectQuery>(*list_of_selects);
|
||||||
new_select->setExpression(ASTSelectQuery::Expression::SELECT, std::make_shared<ASTExpressionList>());
|
new_select->setExpression(ASTSelectQuery::Expression::SELECT, std::make_shared<ASTExpressionList>());
|
||||||
|
addASTChildren<ASTAsterisk>(*new_select->select());
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
|
||||||
asterisk->transformers = std::make_shared<ASTExpressionList>();
|
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
|
||||||
new_select->select()->children.push_back(std::move(asterisk));
|
|
||||||
|
|
||||||
new_select->setExpression(ASTSelectQuery::Expression::TABLES, std::make_shared<ASTTablesInSelectQuery>());
|
new_select->setExpression(ASTSelectQuery::Expression::TABLES, std::make_shared<ASTTablesInSelectQuery>());
|
||||||
|
|
||||||
auto tables_elem = addASTChildren<ASTTablesInSelectQueryElement>(*new_select->tables());
|
auto tables_elem = addASTChildren<ASTTablesInSelectQueryElement>(*new_select->tables());
|
||||||
|
@ -253,17 +253,23 @@ void TranslateQualifiedNamesMatcher::visit(ASTExpressionList & node, const ASTPt
|
|||||||
first_table = false;
|
first_table = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (asterisk->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : asterisk->transformers->children)
|
for (const auto & transformer : asterisk->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (auto * asterisk_column_list = child->as<ASTColumnsListMatcher>())
|
else if (auto * asterisk_column_list = child->as<ASTColumnsListMatcher>())
|
||||||
{
|
{
|
||||||
for (const auto & ident : asterisk_column_list->column_list->children)
|
for (const auto & ident : asterisk_column_list->column_list->children)
|
||||||
columns.emplace_back(ident->clone());
|
columns.emplace_back(ident->clone());
|
||||||
|
|
||||||
|
if (asterisk_column_list->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : asterisk_column_list->transformers->children)
|
for (const auto & transformer : asterisk_column_list->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (const auto * asterisk_regexp_pattern = child->as<ASTColumnsRegexpMatcher>())
|
else if (const auto * asterisk_regexp_pattern = child->as<ASTColumnsRegexpMatcher>())
|
||||||
{
|
{
|
||||||
bool first_table = true;
|
bool first_table = true;
|
||||||
@ -279,9 +285,12 @@ void TranslateQualifiedNamesMatcher::visit(ASTExpressionList & node, const ASTPt
|
|||||||
first_table = false;
|
first_table = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (asterisk_regexp_pattern->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : asterisk_regexp_pattern->transformers->children)
|
for (const auto & transformer : asterisk_regexp_pattern->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (const auto * qualified_asterisk = child->as<ASTQualifiedAsterisk>())
|
else if (const auto * qualified_asterisk = child->as<ASTQualifiedAsterisk>())
|
||||||
{
|
{
|
||||||
DatabaseAndTableWithAlias ident_db_and_name(qualified_asterisk->qualifier);
|
DatabaseAndTableWithAlias ident_db_and_name(qualified_asterisk->qualifier);
|
||||||
@ -296,9 +305,12 @@ void TranslateQualifiedNamesMatcher::visit(ASTExpressionList & node, const ASTPt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (qualified_asterisk->transformers)
|
||||||
|
{
|
||||||
for (const auto & transformer : qualified_asterisk->transformers->children)
|
for (const auto & transformer : qualified_asterisk->transformers->children)
|
||||||
IASTColumnsTransformer::transform(transformer, columns);
|
IASTColumnsTransformer::transform(transformer, columns);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
columns.emplace_back(child);
|
columns.emplace_back(child);
|
||||||
|
|
||||||
|
@ -10,14 +10,21 @@ ASTPtr ASTAsterisk::clone() const
|
|||||||
auto clone = std::make_shared<ASTAsterisk>(*this);
|
auto clone = std::make_shared<ASTAsterisk>(*this);
|
||||||
|
|
||||||
if (expression) { clone->expression = expression->clone(); clone->children.push_back(clone->expression); }
|
if (expression) { clone->expression = expression->clone(); clone->children.push_back(clone->expression); }
|
||||||
|
if (transformers) { clone->transformers = transformers->clone(); clone->children.push_back(clone->transformers); }
|
||||||
clone->transformers = transformers->clone();
|
|
||||||
clone->children.push_back(clone->transformers);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTAsterisk::appendColumnName(WriteBuffer & ostr) const { ostr.write('*'); }
|
void ASTAsterisk::appendColumnName(WriteBuffer & ostr) const
|
||||||
|
{
|
||||||
|
if (expression)
|
||||||
|
{
|
||||||
|
expression->appendColumnName(ostr);
|
||||||
|
writeCString(".", ostr);
|
||||||
|
}
|
||||||
|
|
||||||
|
ostr.write('*');
|
||||||
|
}
|
||||||
|
|
||||||
void ASTAsterisk::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
void ASTAsterisk::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
||||||
{
|
{
|
||||||
@ -29,11 +36,9 @@ void ASTAsterisk::formatImpl(const FormatSettings & settings, FormatState & stat
|
|||||||
|
|
||||||
settings.ostr << "*";
|
settings.ostr << "*";
|
||||||
|
|
||||||
/// Format column transformers
|
if (transformers)
|
||||||
for (const auto & child : transformers->children)
|
|
||||||
{
|
{
|
||||||
settings.ostr << ' ';
|
transformers->formatImpl(settings, state, frame);
|
||||||
child->formatImpl(settings, state, frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,9 +20,7 @@ ASTPtr ASTColumnsRegexpMatcher::clone() const
|
|||||||
auto clone = std::make_shared<ASTColumnsRegexpMatcher>(*this);
|
auto clone = std::make_shared<ASTColumnsRegexpMatcher>(*this);
|
||||||
|
|
||||||
if (expression) { clone->expression = expression->clone(); clone->children.push_back(clone->expression); }
|
if (expression) { clone->expression = expression->clone(); clone->children.push_back(clone->expression); }
|
||||||
|
if (transformers) { clone->transformers = transformers->clone(); clone->children.push_back(clone->transformers); }
|
||||||
clone->transformers = transformers->clone();
|
|
||||||
clone->children.push_back(clone->transformers);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
@ -60,11 +58,9 @@ void ASTColumnsRegexpMatcher::formatImpl(const FormatSettings & settings, Format
|
|||||||
settings.ostr << quoteString(original_pattern);
|
settings.ostr << quoteString(original_pattern);
|
||||||
settings.ostr << ")";
|
settings.ostr << ")";
|
||||||
|
|
||||||
/// Format column transformers
|
if (transformers)
|
||||||
for (const auto & child : transformers->children)
|
|
||||||
{
|
{
|
||||||
settings.ostr << ' ';
|
transformers->formatImpl(settings, state, frame);
|
||||||
child->formatImpl(settings, state, frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,22 +94,14 @@ ASTPtr ASTColumnsListMatcher::clone() const
|
|||||||
auto clone = std::make_shared<ASTColumnsListMatcher>(*this);
|
auto clone = std::make_shared<ASTColumnsListMatcher>(*this);
|
||||||
|
|
||||||
if (expression) { clone->expression = expression->clone(); clone->children.push_back(clone->expression); }
|
if (expression) { clone->expression = expression->clone(); clone->children.push_back(clone->expression); }
|
||||||
|
if (transformers) { clone->transformers = transformers->clone(); clone->children.push_back(clone->transformers); }
|
||||||
|
|
||||||
clone->column_list = column_list->clone();
|
clone->column_list = column_list->clone();
|
||||||
clone->transformers = transformers->clone();
|
|
||||||
|
|
||||||
clone->children.push_back(clone->column_list);
|
clone->children.push_back(clone->column_list);
|
||||||
clone->children.push_back(clone->transformers);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTColumnsListMatcher::updateTreeHashImpl(SipHash & hash_state) const
|
|
||||||
{
|
|
||||||
column_list->updateTreeHash(hash_state);
|
|
||||||
IAST::updateTreeHashImpl(hash_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ASTColumnsListMatcher::appendColumnName(WriteBuffer & ostr) const
|
void ASTColumnsListMatcher::appendColumnName(WriteBuffer & ostr) const
|
||||||
{
|
{
|
||||||
if (expression)
|
if (expression)
|
||||||
@ -154,11 +142,9 @@ void ASTColumnsListMatcher::formatImpl(const FormatSettings & settings, FormatSt
|
|||||||
}
|
}
|
||||||
settings.ostr << ")";
|
settings.ostr << ")";
|
||||||
|
|
||||||
/// Format column transformers
|
if (transformers)
|
||||||
for (const auto & child : transformers->children)
|
|
||||||
{
|
{
|
||||||
settings.ostr << ' ';
|
transformers->formatImpl(settings, state, frame);
|
||||||
child->formatImpl(settings, state, frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,11 +152,10 @@ ASTPtr ASTQualifiedColumnsRegexpMatcher::clone() const
|
|||||||
{
|
{
|
||||||
auto clone = std::make_shared<ASTQualifiedColumnsRegexpMatcher>(*this);
|
auto clone = std::make_shared<ASTQualifiedColumnsRegexpMatcher>(*this);
|
||||||
|
|
||||||
clone->qualifier = qualifier->clone();
|
if (transformers) { clone->transformers = transformers->clone(); clone->children.push_back(clone->transformers); }
|
||||||
clone->transformers = transformers->clone();
|
|
||||||
|
|
||||||
|
clone->qualifier = qualifier->clone();
|
||||||
clone->children.push_back(clone->qualifier);
|
clone->children.push_back(clone->qualifier);
|
||||||
clone->children.push_back(clone->transformers);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
@ -224,11 +209,9 @@ void ASTQualifiedColumnsRegexpMatcher::formatImpl(const FormatSettings & setting
|
|||||||
settings.ostr << quoteString(original_pattern);
|
settings.ostr << quoteString(original_pattern);
|
||||||
settings.ostr << ")";
|
settings.ostr << ")";
|
||||||
|
|
||||||
/// Format column transformers
|
if (transformers)
|
||||||
for (const auto & child : transformers->children)
|
|
||||||
{
|
{
|
||||||
settings.ostr << ' ';
|
transformers->formatImpl(settings, state, frame);
|
||||||
child->formatImpl(settings, state, frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,13 +219,13 @@ ASTPtr ASTQualifiedColumnsListMatcher::clone() const
|
|||||||
{
|
{
|
||||||
auto clone = std::make_shared<ASTQualifiedColumnsListMatcher>(*this);
|
auto clone = std::make_shared<ASTQualifiedColumnsListMatcher>(*this);
|
||||||
|
|
||||||
|
if (transformers) { clone->transformers = transformers->clone(); clone->children.push_back(clone->transformers); }
|
||||||
|
|
||||||
clone->qualifier = qualifier->clone();
|
clone->qualifier = qualifier->clone();
|
||||||
clone->column_list = column_list->clone();
|
clone->column_list = column_list->clone();
|
||||||
clone->transformers = transformers->clone();
|
|
||||||
|
|
||||||
clone->children.push_back(clone->qualifier);
|
clone->children.push_back(clone->qualifier);
|
||||||
clone->children.push_back(clone->column_list);
|
clone->children.push_back(clone->column_list);
|
||||||
clone->children.push_back(clone->transformers);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
@ -262,12 +245,6 @@ void ASTQualifiedColumnsListMatcher::appendColumnName(WriteBuffer & ostr) const
|
|||||||
writeChar(')', ostr);
|
writeChar(')', ostr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASTQualifiedColumnsListMatcher::updateTreeHashImpl(SipHash & hash_state) const
|
|
||||||
{
|
|
||||||
column_list->updateTreeHash(hash_state);
|
|
||||||
IAST::updateTreeHashImpl(hash_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ASTQualifiedColumnsListMatcher::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
void ASTQualifiedColumnsListMatcher::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
||||||
{
|
{
|
||||||
settings.ostr << (settings.hilite ? hilite_keyword : "");
|
settings.ostr << (settings.hilite ? hilite_keyword : "");
|
||||||
@ -283,11 +260,9 @@ void ASTQualifiedColumnsListMatcher::formatImpl(const FormatSettings & settings,
|
|||||||
}
|
}
|
||||||
settings.ostr << ")";
|
settings.ostr << ")";
|
||||||
|
|
||||||
/// Format column transformers
|
if (transformers)
|
||||||
for (const auto & child : transformers->children)
|
|
||||||
{
|
{
|
||||||
settings.ostr << ' ';
|
transformers->formatImpl(settings, state, frame);
|
||||||
child->formatImpl(settings, state, frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ public:
|
|||||||
String getID(char) const override { return "ColumnsListMatcher"; }
|
String getID(char) const override { return "ColumnsListMatcher"; }
|
||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
void updateTreeHashImpl(SipHash & hash_state) const override;
|
|
||||||
|
|
||||||
ASTPtr expression;
|
ASTPtr expression;
|
||||||
ASTPtr column_list;
|
ASTPtr column_list;
|
||||||
@ -85,7 +84,6 @@ public:
|
|||||||
String getID(char) const override { return "QualifiedColumnsListMatcher"; }
|
String getID(char) const override { return "QualifiedColumnsListMatcher"; }
|
||||||
ASTPtr clone() const override;
|
ASTPtr clone() const override;
|
||||||
void appendColumnName(WriteBuffer & ostr) const override;
|
void appendColumnName(WriteBuffer & ostr) const override;
|
||||||
void updateTreeHashImpl(SipHash & hash_state) const override;
|
|
||||||
|
|
||||||
ASTPtr qualifier;
|
ASTPtr qualifier;
|
||||||
ASTPtr column_list;
|
ASTPtr column_list;
|
||||||
|
@ -19,6 +19,15 @@ namespace ErrorCodes
|
|||||||
extern const int CANNOT_COMPILE_REGEXP;
|
extern const int CANNOT_COMPILE_REGEXP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ASTColumnsTransformerList::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
||||||
|
{
|
||||||
|
for (const auto & child : children)
|
||||||
|
{
|
||||||
|
settings.ostr << ' ';
|
||||||
|
child->formatImpl(settings, state, frame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void IASTColumnsTransformer::transform(const ASTPtr & transformer, ASTs & nodes)
|
void IASTColumnsTransformer::transform(const ASTPtr & transformer, ASTs & nodes)
|
||||||
{
|
{
|
||||||
if (const auto * apply = transformer->as<ASTColumnsApplyTransformer>())
|
if (const auto * apply = transformer->as<ASTColumnsApplyTransformer>())
|
||||||
|
@ -9,6 +9,23 @@ namespace re2
|
|||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// A list of column transformers
|
||||||
|
class ASTColumnsTransformerList : public IAST
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
String getID(char) const override { return "ColumnsTransformerList"; }
|
||||||
|
ASTPtr clone() const override
|
||||||
|
{
|
||||||
|
auto clone = std::make_shared<ASTColumnsTransformerList>(*this);
|
||||||
|
clone->cloneChildren();
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
|
||||||
|
};
|
||||||
|
|
||||||
class IASTColumnsTransformer : public IAST
|
class IASTColumnsTransformer : public IAST
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -16,11 +16,9 @@ void ASTQualifiedAsterisk::formatImpl(const FormatSettings & settings, FormatSta
|
|||||||
qualifier->formatImpl(settings, state, frame);
|
qualifier->formatImpl(settings, state, frame);
|
||||||
settings.ostr << ".*";
|
settings.ostr << ".*";
|
||||||
|
|
||||||
/// Format column transformers
|
if (transformers)
|
||||||
for (const auto & child : transformers->children)
|
|
||||||
{
|
{
|
||||||
settings.ostr << ' ';
|
transformers->formatImpl(settings, state, frame);
|
||||||
child->formatImpl(settings, state, frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,11 +18,10 @@ public:
|
|||||||
{
|
{
|
||||||
auto clone = std::make_shared<ASTQualifiedAsterisk>(*this);
|
auto clone = std::make_shared<ASTQualifiedAsterisk>(*this);
|
||||||
|
|
||||||
clone->qualifier = qualifier->clone();
|
if (transformers) { clone->transformers = transformers->clone(); clone->children.push_back(clone->transformers); }
|
||||||
clone->transformers = transformers->clone();
|
|
||||||
|
|
||||||
|
clone->qualifier = qualifier->clone();
|
||||||
clone->children.push_back(clone->qualifier);
|
clone->children.push_back(clone->qualifier);
|
||||||
clone->children.push_back(clone->transformers);
|
|
||||||
|
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
@ -80,12 +80,7 @@ static ASTPtr buildSelectFromTableFunction(const std::shared_ptr<ASTFunction> &
|
|||||||
{
|
{
|
||||||
auto select_ast = std::make_shared<ASTSelectQuery>();
|
auto select_ast = std::make_shared<ASTSelectQuery>();
|
||||||
select_ast->setExpression(ASTSelectQuery::Expression::SELECT, std::make_shared<ASTExpressionList>());
|
select_ast->setExpression(ASTSelectQuery::Expression::SELECT, std::make_shared<ASTExpressionList>());
|
||||||
|
select_ast->select()->children.push_back(std::make_shared<ASTAsterisk>());
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
|
||||||
asterisk->transformers = std::make_shared<ASTExpressionList>();
|
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
|
||||||
|
|
||||||
select_ast->select()->children.push_back(std::move(asterisk));
|
|
||||||
|
|
||||||
auto list_of_selects = std::make_shared<ASTExpressionList>();
|
auto list_of_selects = std::make_shared<ASTExpressionList>();
|
||||||
list_of_selects->children.push_back(select_ast);
|
list_of_selects->children.push_back(select_ast);
|
||||||
@ -1553,7 +1548,7 @@ bool ParserAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|||||||
{
|
{
|
||||||
++pos;
|
++pos;
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
auto asterisk = std::make_shared<ASTAsterisk>();
|
||||||
auto transformers = std::make_shared<ASTExpressionList>();
|
auto transformers = std::make_shared<ASTColumnsTransformerList>();
|
||||||
ParserColumnsTransformers transformers_p(allowed_transformers);
|
ParserColumnsTransformers transformers_p(allowed_transformers);
|
||||||
ASTPtr transformer;
|
ASTPtr transformer;
|
||||||
while (transformers_p.parse(pos, transformer, expected))
|
while (transformers_p.parse(pos, transformer, expected))
|
||||||
@ -1561,8 +1556,11 @@ bool ParserAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
|||||||
transformers->children.push_back(transformer);
|
transformers->children.push_back(transformer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!transformers->children.empty())
|
||||||
|
{
|
||||||
asterisk->transformers = std::move(transformers);
|
asterisk->transformers = std::move(transformers);
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
asterisk->children.push_back(asterisk->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
node = std::move(asterisk);
|
node = std::move(asterisk);
|
||||||
return true;
|
return true;
|
||||||
@ -1585,7 +1583,7 @@ bool ParserQualifiedAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected & exp
|
|||||||
++pos;
|
++pos;
|
||||||
|
|
||||||
auto res = std::make_shared<ASTQualifiedAsterisk>();
|
auto res = std::make_shared<ASTQualifiedAsterisk>();
|
||||||
auto transformers = std::make_shared<ASTExpressionList>();
|
auto transformers = std::make_shared<ASTColumnsTransformerList>();
|
||||||
ParserColumnsTransformers transformers_p;
|
ParserColumnsTransformers transformers_p;
|
||||||
ASTPtr transformer;
|
ASTPtr transformer;
|
||||||
while (transformers_p.parse(pos, transformer, expected))
|
while (transformers_p.parse(pos, transformer, expected))
|
||||||
@ -1594,9 +1592,13 @@ bool ParserQualifiedAsterisk::parseImpl(Pos & pos, ASTPtr & node, Expected & exp
|
|||||||
}
|
}
|
||||||
|
|
||||||
res->qualifier = std::move(node);
|
res->qualifier = std::move(node);
|
||||||
res->transformers = std::move(transformers);
|
|
||||||
res->children.push_back(res->qualifier);
|
res->children.push_back(res->qualifier);
|
||||||
|
|
||||||
|
if (!transformers->children.empty())
|
||||||
|
{
|
||||||
|
res->transformers = std::move(transformers);
|
||||||
res->children.push_back(res->transformers);
|
res->children.push_back(res->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
node = std::move(res);
|
node = std::move(res);
|
||||||
return true;
|
return true;
|
||||||
@ -1621,7 +1623,7 @@ static bool parseColumnsMatcherBody(IParser::Pos & pos, ASTPtr & node, Expected
|
|||||||
return false;
|
return false;
|
||||||
++pos;
|
++pos;
|
||||||
|
|
||||||
auto transformers = std::make_shared<ASTExpressionList>();
|
auto transformers = std::make_shared<ASTColumnsTransformerList>();
|
||||||
ParserColumnsTransformers transformers_p(allowed_transformers);
|
ParserColumnsTransformers transformers_p(allowed_transformers);
|
||||||
ASTPtr transformer;
|
ASTPtr transformer;
|
||||||
while (transformers_p.parse(pos, transformer, expected))
|
while (transformers_p.parse(pos, transformer, expected))
|
||||||
@ -1635,9 +1637,13 @@ static bool parseColumnsMatcherBody(IParser::Pos & pos, ASTPtr & node, Expected
|
|||||||
auto list_matcher = std::make_shared<ASTColumnsListMatcher>();
|
auto list_matcher = std::make_shared<ASTColumnsListMatcher>();
|
||||||
|
|
||||||
list_matcher->column_list = std::move(column_list);
|
list_matcher->column_list = std::move(column_list);
|
||||||
list_matcher->transformers = std::move(transformers);
|
|
||||||
list_matcher->children.push_back(list_matcher->column_list);
|
list_matcher->children.push_back(list_matcher->column_list);
|
||||||
|
|
||||||
|
if (!transformers->children.empty())
|
||||||
|
{
|
||||||
|
list_matcher->transformers = std::move(transformers);
|
||||||
list_matcher->children.push_back(list_matcher->transformers);
|
list_matcher->children.push_back(list_matcher->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
node = std::move(list_matcher);
|
node = std::move(list_matcher);
|
||||||
}
|
}
|
||||||
@ -1646,8 +1652,11 @@ static bool parseColumnsMatcherBody(IParser::Pos & pos, ASTPtr & node, Expected
|
|||||||
auto regexp_matcher = std::make_shared<ASTColumnsRegexpMatcher>();
|
auto regexp_matcher = std::make_shared<ASTColumnsRegexpMatcher>();
|
||||||
regexp_matcher->setPattern(regex_node->as<ASTLiteral &>().value.get<String>());
|
regexp_matcher->setPattern(regex_node->as<ASTLiteral &>().value.get<String>());
|
||||||
|
|
||||||
|
if (!transformers->children.empty())
|
||||||
|
{
|
||||||
regexp_matcher->transformers = std::move(transformers);
|
regexp_matcher->transformers = std::move(transformers);
|
||||||
regexp_matcher->children.push_back(regexp_matcher->transformers);
|
regexp_matcher->children.push_back(regexp_matcher->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
node = std::move(regexp_matcher);
|
node = std::move(regexp_matcher);
|
||||||
}
|
}
|
||||||
@ -1689,11 +1698,15 @@ bool ParserQualifiedColumnsMatcher::parseImpl(Pos & pos, ASTPtr & node, Expected
|
|||||||
auto result = std::make_shared<ASTQualifiedColumnsListMatcher>();
|
auto result = std::make_shared<ASTQualifiedColumnsListMatcher>();
|
||||||
result->qualifier = std::move(identifier_node);
|
result->qualifier = std::move(identifier_node);
|
||||||
result->column_list = std::move(columns_list_matcher->column_list);
|
result->column_list = std::move(columns_list_matcher->column_list);
|
||||||
result->transformers = std::move(columns_list_matcher->transformers);
|
|
||||||
|
|
||||||
result->children.push_back(result->qualifier);
|
result->children.push_back(result->qualifier);
|
||||||
result->children.push_back(result->column_list);
|
result->children.push_back(result->column_list);
|
||||||
|
|
||||||
|
if (columns_list_matcher->transformers)
|
||||||
|
{
|
||||||
|
result->transformers = std::move(columns_list_matcher->transformers);
|
||||||
result->children.push_back(result->transformers);
|
result->children.push_back(result->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
node = std::move(result);
|
node = std::move(result);
|
||||||
}
|
}
|
||||||
@ -1704,10 +1717,13 @@ bool ParserQualifiedColumnsMatcher::parseImpl(Pos & pos, ASTPtr & node, Expected
|
|||||||
result->setMatcher(column_regexp_matcher->getMatcher());
|
result->setMatcher(column_regexp_matcher->getMatcher());
|
||||||
|
|
||||||
result->qualifier = std::move(identifier_node);
|
result->qualifier = std::move(identifier_node);
|
||||||
result->transformers = std::move(column_regexp_matcher->transformers);
|
|
||||||
|
|
||||||
result->children.push_back(result->qualifier);
|
result->children.push_back(result->qualifier);
|
||||||
|
|
||||||
|
if (column_regexp_matcher->transformers)
|
||||||
|
{
|
||||||
|
result->transformers = std::move(column_regexp_matcher->transformers);
|
||||||
result->children.push_back(result->transformers);
|
result->children.push_back(result->transformers);
|
||||||
|
}
|
||||||
|
|
||||||
node = std::move(result);
|
node = std::move(result);
|
||||||
}
|
}
|
||||||
|
@ -194,11 +194,7 @@ static bool modifyAST(ASTPtr ast, SubqueryFunctionType type)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
/// subquery --> (SELECT aggregate_function(*) FROM subquery)
|
/// subquery --> (SELECT aggregate_function(*) FROM subquery)
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
auto aggregate_function = makeASTFunction(aggregate_function_name, std::make_shared<ASTAsterisk>());
|
||||||
asterisk->transformers = std::make_shared<ASTExpressionList>();
|
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
|
||||||
|
|
||||||
auto aggregate_function = makeASTFunction(aggregate_function_name, std::move(asterisk));
|
|
||||||
auto subquery_node = function->children[0]->children[1];
|
auto subquery_node = function->children[0]->children[1];
|
||||||
|
|
||||||
auto table_expression = std::make_shared<ASTTableExpression>();
|
auto table_expression = std::make_shared<ASTTableExpression>();
|
||||||
|
@ -327,10 +327,7 @@ namespace
|
|||||||
{
|
{
|
||||||
auto fetch_query = std::make_shared<ASTSelectQuery>();
|
auto fetch_query = std::make_shared<ASTSelectQuery>();
|
||||||
auto select = std::make_shared<ASTExpressionList>();
|
auto select = std::make_shared<ASTExpressionList>();
|
||||||
auto asterisk = std::make_shared<ASTAsterisk>();
|
select->children.push_back(std::make_shared<ASTAsterisk>());
|
||||||
asterisk->transformers = std::make_shared<ASTExpressionList>();
|
|
||||||
asterisk->children.push_back(asterisk->transformers);
|
|
||||||
select->children.push_back(asterisk);
|
|
||||||
fetch_query->setExpression(ASTSelectQuery::Expression::SELECT, select);
|
fetch_query->setExpression(ASTSelectQuery::Expression::SELECT, select);
|
||||||
fetch_query->setExpression(ASTSelectQuery::Expression::TABLES, std::make_shared<ASTTablesInSelectQuery>());
|
fetch_query->setExpression(ASTSelectQuery::Expression::TABLES, std::make_shared<ASTTablesInSelectQuery>());
|
||||||
auto tables_elem = std::make_shared<ASTTablesInSelectQueryElement>();
|
auto tables_elem = std::make_shared<ASTTablesInSelectQueryElement>();
|
||||||
|
Loading…
Reference in New Issue
Block a user