Modify varaible name and log info

This commit is contained in:
hexiaoting 2020-10-22 12:40:50 +08:00
parent 91b1dab75b
commit ad2d2cf10d
3 changed files with 27 additions and 46 deletions

View File

@ -46,9 +46,7 @@ void ASTColumnsApplyTransformer::transform(ASTs & nodes) const
void ASTColumnsExceptTransformer::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
settings.ostr << (settings.hilite ? hilite_keyword : "");
settings.ostr << (is_strict ? "EXCEPTSTRICT" : "EXCEPT");
settings.ostr << (settings.hilite ? hilite_none : "") << "(";
settings.ostr << (settings.hilite ? hilite_keyword : "") << "EXCEPT" << (is_strict ? " STRICT " : "") << (settings.hilite ? hilite_none : "") << "(";
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
{
@ -64,7 +62,8 @@ void ASTColumnsExceptTransformer::formatImpl(const FormatSettings & settings, Fo
void ASTColumnsExceptTransformer::transform(ASTs & nodes) const
{
ASTs unexcepted_columns(children);
ASTs expected_columns(children);
nodes.erase(
std::remove_if(
nodes.begin(),
@ -73,11 +72,11 @@ void ASTColumnsExceptTransformer::transform(ASTs & nodes) const
{
if (const auto * id = node_child->as<ASTIdentifier>())
{
for (size_t i = 0; i < children.size(); i++)
for (int i = children.size() - 1; i >= 0; --i)
{
if (children[i]->as<const ASTIdentifier &>().name == id->shortName())
{
unexcepted_columns.erase(unexcepted_columns.begin() + i);
expected_columns.erase(expected_columns.begin() + i);
return true;
}
}
@ -86,18 +85,18 @@ void ASTColumnsExceptTransformer::transform(ASTs & nodes) const
}),
nodes.end());
if (is_strict && !unexcepted_columns.empty())
if (is_strict && !expected_columns.empty())
{
String unexisted_columns;
for (size_t i = 0; i < unexcepted_columns.size(); ++i)
String expected_columns_str;
for (size_t i = 0; i < expected_columns.size(); ++i)
{
if (i > 0)
unexisted_columns += ", ";
unexisted_columns += unexcepted_columns[i]->as<const ASTIdentifier &>().name;
expected_columns_str += ", ";
expected_columns_str += expected_columns[i]->as<const ASTIdentifier &>().name;
}
throw Exception(
"Columns transformer EXPCEPTSTRICT process unexist column : " + unexisted_columns,
"Columns transformer EXCEPT expects following column(s) : " + expected_columns_str,
ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
}
}
@ -111,9 +110,7 @@ void ASTColumnsReplaceTransformer::Replacement::formatImpl(
void ASTColumnsReplaceTransformer::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
settings.ostr << (settings.hilite ? hilite_keyword : "");
settings.ostr << (is_strict ? "REPLACESTRICT" : "REPLACE");
settings.ostr << (settings.hilite ? hilite_none : "") << "(";
settings.ostr << (settings.hilite ? hilite_keyword : "") << "REPLACE" << (is_strict ? " STRICT " : "") << (settings.hilite ? hilite_none : "") << "(";
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
{
@ -183,15 +180,15 @@ void ASTColumnsReplaceTransformer::transform(ASTs & nodes) const
if (is_strict && !replace_map.empty())
{
String unexisted_columns = "";
String expected_columns = "";
for (auto it = replace_map.begin(); it != replace_map.end(); ++it)
{
if (unexisted_columns != "")
unexisted_columns += ", ";
unexisted_columns += it->first;
if (expected_columns != "")
expected_columns += ", ";
expected_columns += it->first;
}
throw Exception(
"Columns transformer REPLACESTRICT process unexist column : " + unexisted_columns,
"Columns transformer REPLACE expects following column(s) : " + expected_columns,
ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
}

View File

@ -1236,10 +1236,7 @@ bool ParserColumnsTransformers::parseImpl(Pos & pos, ASTPtr & node, Expected & e
ParserKeyword except("EXCEPT");
ParserKeyword replace("REPLACE");
ParserKeyword as("AS");
ParserKeyword except_strict("EXCEPTSTRICT");
ParserKeyword replace_strict("REPLACESTRICT");
bool is_except = false;
bool is_replace = false;
ParserKeyword strict("STRICT");
if (apply.ignore(pos, expected))
{
@ -1260,27 +1257,12 @@ bool ParserColumnsTransformers::parseImpl(Pos & pos, ASTPtr & node, Expected & e
node = std::move(res);
return true;
}
else if (except_strict.ignore(pos, expected))
{
is_except = true;
is_strict = true;
}
else if (except.ignore(pos, expected))
{
is_except = true;
}
else if (replace_strict.ignore(pos, expected))
{
is_replace = true;
is_strict = true;
}
else if (replace.ignore(pos, expected))
{
is_replace = true;
}
if (is_except)
{
if (strict.ignore(pos, expected))
is_strict = true;
if (pos->type != TokenType::OpeningRoundBracket)
return false;
++pos;
@ -1309,8 +1291,10 @@ bool ParserColumnsTransformers::parseImpl(Pos & pos, ASTPtr & node, Expected & e
node = std::move(res);
return true;
}
else if (is_replace)
else if (replace.ignore(pos, expected))
{
if (strict.ignore(pos, expected))
is_strict = true;
if (pos->type != TokenType::OpeningRoundBracket)
return false;

View File

@ -13,14 +13,14 @@ SELECT columns_transformers.* EXCEPT(j) APPLY(avg) from columns_transformers;
-- EXCEPT after APPLY will not match anything
SELECT a.* APPLY(toDate) EXCEPT(i, j) APPLY(any) from columns_transformers a;
SELECT * EXCEPTSTRICT(i, j1) from columns_transformers; -- { serverError 16 }
SELECT * REPLACESTRICT(i + 1 AS col) from columns_transformers; -- { serverError 16 }
SELECT * EXCEPT STRICT(i, j1) from columns_transformers; -- { serverError 16 }
SELECT * REPLACE STRICT(i + 1 AS col) from columns_transformers; -- { serverError 16 }
SELECT * REPLACE(i + 1 AS i) APPLY(sum) from columns_transformers;
SELECT columns_transformers.* REPLACE(j + 2 AS j, i + 1 AS i) APPLY(avg) from columns_transformers;
SELECT columns_transformers.* REPLACE(j + 1 AS j, j + 2 AS j) APPLY(avg) from columns_transformers; -- { serverError 43 }
-- REPLACE after APPLY will not match anything
SELECT a.* APPLY(toDate) REPLACE(i + 1 AS i) APPLY(any) from columns_transformers a;
SELECT a.* APPLY(toDate) REPLACESTRICT(i + 1 AS i) APPLY(any) from columns_transformers a; -- { serverError 16 }
SELECT a.* APPLY(toDate) REPLACE STRICT(i + 1 AS i) APPLY(any) from columns_transformers a; -- { serverError 16 }
EXPLAIN SYNTAX SELECT * APPLY(sum) from columns_transformers;
EXPLAIN SYNTAX SELECT columns_transformers.* APPLY(avg) from columns_transformers;