mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Better
This commit is contained in:
parent
d4fe0fae8f
commit
fc6ec8474e
@ -111,7 +111,7 @@ bool ParserSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
|
||||
/// FROM database.table or FROM table or FROM (subquery) or FROM tableFunction(...)
|
||||
if (s_from.ignore(pos, expected))
|
||||
{
|
||||
if (!ParserTablesInSelectQuery().parse(pos, tables, expected))
|
||||
if (!ParserTablesInSelectQuery(false).parse(pos, tables, expected))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ bool ParserTableExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expec
|
||||
{
|
||||
auto res = std::make_shared<ASTTableExpression>();
|
||||
|
||||
if (!ParserWithOptionalAlias(std::make_unique<ParserSubquery>(), true).parse(pos, res->subquery, expected)
|
||||
&& !ParserWithOptionalAlias(std::make_unique<ParserFunction>(true, true), true).parse(pos, res->table_function, expected)
|
||||
&& !ParserWithOptionalAlias(std::make_unique<ParserCompoundIdentifier>(true, true), true)
|
||||
if (!ParserWithOptionalAlias(std::make_unique<ParserSubquery>(), allow_alias_without_as_keyword).parse(pos, res->subquery, expected)
|
||||
&& !ParserWithOptionalAlias(std::make_unique<ParserFunction>(true, true), allow_alias_without_as_keyword).parse(pos, res->table_function, expected)
|
||||
&& !ParserWithOptionalAlias(std::make_unique<ParserCompoundIdentifier>(true, true), allow_alias_without_as_keyword)
|
||||
.parse(pos, res->database_and_table_name, expected))
|
||||
return false;
|
||||
|
||||
@ -126,7 +126,7 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec
|
||||
|
||||
if (is_first)
|
||||
{
|
||||
if (!ParserTableExpression().parse(pos, res->table_expression, expected))
|
||||
if (!ParserTableExpression(allow_alias_without_as_keyword).parse(pos, res->table_expression, expected))
|
||||
return false;
|
||||
}
|
||||
else if (ParserArrayJoin().parse(pos, res->array_join, expected))
|
||||
@ -200,7 +200,7 @@ bool ParserTablesInSelectQueryElement::parseImpl(Pos & pos, ASTPtr & node, Expec
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ParserTableExpression().parse(pos, res->table_expression, expected))
|
||||
if (!ParserTableExpression(allow_alias_without_as_keyword).parse(pos, res->table_expression, expected))
|
||||
return false;
|
||||
|
||||
if (table_join->kind != JoinKind::Comma
|
||||
@ -261,12 +261,12 @@ bool ParserTablesInSelectQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & e
|
||||
|
||||
ASTPtr child;
|
||||
|
||||
if (ParserTablesInSelectQueryElement(true).parse(pos, child, expected))
|
||||
if (ParserTablesInSelectQueryElement(true, allow_alias_without_as_keyword).parse(pos, child, expected))
|
||||
res->children.emplace_back(child);
|
||||
else
|
||||
return false;
|
||||
|
||||
while (ParserTablesInSelectQueryElement(false).parse(pos, child, expected))
|
||||
while (ParserTablesInSelectQueryElement(false, allow_alias_without_as_keyword).parse(pos, child, expected))
|
||||
res->children.emplace_back(child);
|
||||
|
||||
node = res;
|
||||
|
@ -12,16 +12,24 @@ struct ASTTableJoin;
|
||||
*/
|
||||
class ParserTablesInSelectQuery : public IParserBase
|
||||
{
|
||||
public:
|
||||
ParserTablesInSelectQuery(bool allow_alias_without_as_keyword_ = true)
|
||||
: allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
|
||||
|
||||
protected:
|
||||
const char * getName() const override { return "table, table function, subquery or list of joined tables"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
||||
|
||||
private:
|
||||
bool allow_alias_without_as_keyword;
|
||||
};
|
||||
|
||||
|
||||
class ParserTablesInSelectQueryElement : public IParserBase
|
||||
{
|
||||
public:
|
||||
explicit ParserTablesInSelectQueryElement(bool is_first_) : is_first(is_first_) {}
|
||||
explicit ParserTablesInSelectQueryElement(bool is_first_, bool allow_alias_without_as_keyword_ = true)
|
||||
: is_first(is_first_), allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
|
||||
|
||||
protected:
|
||||
const char * getName() const override { return "table, table function, subquery or list of joined tables"; }
|
||||
@ -29,6 +37,7 @@ protected:
|
||||
|
||||
private:
|
||||
bool is_first;
|
||||
bool allow_alias_without_as_keyword;
|
||||
|
||||
static void parseJoinStrictness(Pos & pos, ASTTableJoin & table_join);
|
||||
};
|
||||
@ -36,9 +45,16 @@ private:
|
||||
|
||||
class ParserTableExpression : public IParserBase
|
||||
{
|
||||
public:
|
||||
explicit ParserTableExpression(bool allow_alias_without_as_keyword_ = true)
|
||||
: allow_alias_without_as_keyword(allow_alias_without_as_keyword_) {}
|
||||
|
||||
protected:
|
||||
const char * getName() const override { return "table or subquery or table function"; }
|
||||
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
|
||||
|
||||
private:
|
||||
bool allow_alias_without_as_keyword;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1,2 +1,4 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
|
@ -1,2 +1,4 @@
|
||||
FROM numbers(1) SELECT number;
|
||||
WITH 1 as n FROM numbers(1) SELECT number * n;
|
||||
FROM (FROM numbers(1) SELECT *) SELECT number;
|
||||
FROM (FROM numbers(1) SELECT *) AS select SELECT number;
|
||||
|
Loading…
Reference in New Issue
Block a user