Merge pull request #13940 from hczhcz/patch-0821

Fix parser to reject create table as table function with engine
This commit is contained in:
alexey-milovidov 2020-08-24 22:01:40 +03:00 committed by GitHub
commit 14400b5b41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 7 deletions

View File

@ -265,11 +265,6 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat
formatOnCluster(settings);
}
if (as_table_function)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS " << (settings.hilite ? hilite_none : "");
as_table_function->formatImpl(settings, state, frame);
}
if (to_table_id)
{
settings.ostr
@ -285,6 +280,12 @@ void ASTCreateQuery::formatQueryImpl(const FormatSettings & settings, FormatStat
<< (!as_database.empty() ? backQuoteIfNeed(as_database) + "." : "") << backQuoteIfNeed(as_table);
}
if (as_table_function)
{
settings.ostr << (settings.hilite ? hilite_keyword : "") << " AS " << (settings.hilite ? hilite_none : "");
as_table_function->formatImpl(settings, state, frame);
}
frame.expression_list_always_start_on_new_line = true;
if (columns_list)

View File

@ -427,7 +427,8 @@ bool ParserCreateTableQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expe
if (!select_p.parse(pos, select, expected)) /// AS SELECT ...
{
if (!table_function_p.parse(pos, as_table_function, expected))
/// ENGINE can not be specified for table functions.
if (storage || !table_function_p.parse(pos, as_table_function, expected))
{
/// AS [db.]table
if (!name_p.parse(pos, as_table, expected))

View File

@ -4,9 +4,15 @@ DROP TABLE IF EXISTS t3;
DROP TABLE IF EXISTS v;
DROP TABLE IF EXISTS lv;
CREATE TABLE t1 (key Int) Engine=Memory();
CREATE TABLE t1 (key Int) Engine=Memory;
CREATE TABLE t2 AS t1;
DROP TABLE t2;
CREATE TABLE t2 Engine=Memory AS t1;
DROP TABLE t2;
CREATE TABLE t2 AS t1 Engine=Memory;
DROP TABLE t2;
CREATE TABLE t3 AS numbers(10);
DROP TABLE t3;
-- live view
SET allow_experimental_live_view=1;

View File

@ -0,0 +1,3 @@
OK
OK
OK

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. "$CUR_DIR"/../shell_config.sh
${CLICKHOUSE_CLIENT} --query "CREATE TABLE system.columns AS numbers(10);" 2>&1 | grep -F "Code: 57" > /dev/null && echo 'OK' || echo 'FAIL'
${CLICKHOUSE_CLIENT} --query "CREATE TABLE system.columns engine=Memory AS numbers(10);" 2>&1 | grep -F "Code: 62" > /dev/null && echo 'OK' || echo 'FAIL'
${CLICKHOUSE_CLIENT} --query "CREATE TABLE system.columns AS numbers(10) engine=Memory;" 2>&1 | grep -F "Code: 62" > /dev/null && echo 'OK' || echo 'FAIL'