Merge pull request #33521 from Avogar/fix-from-infile-syntax

Fix parsing queries with FROM INFILE statement
This commit is contained in:
tavplubix 2022-01-11 20:16:24 +03:00 committed by GitHub
commit 6eee1fda56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

View File

@ -113,10 +113,13 @@ bool ParserInsertQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
return false;
}
/// Check if file is a source of data.
Pos before_values = pos;
String format_str;
/// VALUES or FROM INFILE or FORMAT or SELECT
if (s_from_infile.ignore(pos, expected))
{
/// Read its name to process it later
/// Read file name to process it later
if (!infile_name_p.parse(pos, infile, expected))
return false;
@ -128,13 +131,14 @@ bool ParserInsertQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (!compression_p.parse(pos, compression, expected))
return false;
}
/// Read format name
if (!s_format.ignore(pos, expected) || !name_p.parse(pos, format, expected))
return false;
tryGetIdentifierNameInto(format, format_str);
}
Pos before_values = pos;
String format_str;
/// VALUES or FROM INFILE or FORMAT or SELECT
if (!infile && s_values.ignore(pos, expected))
else if (s_values.ignore(pos, expected))
{
/// If VALUES is defined in query, everything except setting will be parsed as data
data = pos->begin;

View File

@ -0,0 +1,4 @@
EXPLAIN SYNTAX INSERT INTO test FROM INFILE 'data.file' SELECT 1; -- { clientError SYNTAX_ERROR }
EXPLAIN SYNTAX INSERT INTO test FROM INFILE 'data.file' WATCH view; -- { clientError SYNTAX_ERROR }
EXPLAIN SYNTAX INSERT INTO test FROM INFILE 'data.file' VALUES (1) -- { clientError SYNTAX_ERROR }
EXPLAIN SYNTAX INSERT INTO test FROM INFILE 'data.file' WITH number AS x SELECT number FROM numbers(10); -- { clientError SYNTAX_ERROR }