From 9a76efb8500e779f4925c4830e4f15d527084b7c Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Sun, 3 Apr 2022 23:39:59 +0300 Subject: [PATCH 1/2] Fix formatting of INSERT INFILE queries (missing quotes) Signed-off-by: Azat Khuzhin --- src/Parsers/ASTInsertQuery.cpp | 12 ++++++++++-- .../0_stateless/02165_insert_from_infile.reference | 4 ++-- .../0_stateless/02264_format_insert_infile.reference | 3 +++ .../0_stateless/02264_format_insert_infile.sql | 2 ++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 tests/queries/0_stateless/02264_format_insert_infile.reference create mode 100644 tests/queries/0_stateless/02264_format_insert_infile.sql diff --git a/src/Parsers/ASTInsertQuery.cpp b/src/Parsers/ASTInsertQuery.cpp index 7e1d48d7f55..1d30c8f1bbd 100644 --- a/src/Parsers/ASTInsertQuery.cpp +++ b/src/Parsers/ASTInsertQuery.cpp @@ -81,9 +81,17 @@ void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & s if (infile) { - settings.ostr << (settings.hilite ? hilite_keyword : "") << " FROM INFILE " << (settings.hilite ? hilite_none : "") << infile->as().value.safeGet(); + settings.ostr + << (settings.hilite ? hilite_keyword : "") + << " FROM INFILE " + << (settings.hilite ? hilite_none : "") + << quoteString(infile->as().value.safeGet()); if (compression) - settings.ostr << (settings.hilite ? hilite_keyword : "") << " COMPRESSION " << (settings.hilite ? hilite_none : "") << compression->as().value.safeGet(); + settings.ostr + << (settings.hilite ? hilite_keyword : "") + << " COMPRESSION " + << (settings.hilite ? hilite_none : "") + << compression->as().value.safeGet(); } if (select) diff --git a/tests/queries/0_stateless/02165_insert_from_infile.reference b/tests/queries/0_stateless/02165_insert_from_infile.reference index 2a00a8faa31..f8c205ecc0f 100644 --- a/tests/queries/0_stateless/02165_insert_from_infile.reference +++ b/tests/queries/0_stateless/02165_insert_from_infile.reference @@ -1,5 +1,5 @@ -INSERT INTO test FROM INFILE data.file SELECT x +INSERT INTO test FROM INFILE \'data.file\' SELECT x FROM input(\'x UInt32\') -INSERT INTO test FROM INFILE data.file WITH number AS x +INSERT INTO test FROM INFILE \'data.file\' WITH number AS x SELECT number FROM input(\'number UInt32\') diff --git a/tests/queries/0_stateless/02264_format_insert_infile.reference b/tests/queries/0_stateless/02264_format_insert_infile.reference new file mode 100644 index 00000000000..338ea6fbfc6 --- /dev/null +++ b/tests/queries/0_stateless/02264_format_insert_infile.reference @@ -0,0 +1,3 @@ +-- { echo } +EXPLAIN SYNTAX INSERT INTO foo FROM INFILE '/dev/null'; +INSERT INTO foo FROM INFILE \'/dev/null\' diff --git a/tests/queries/0_stateless/02264_format_insert_infile.sql b/tests/queries/0_stateless/02264_format_insert_infile.sql new file mode 100644 index 00000000000..38ee39d932d --- /dev/null +++ b/tests/queries/0_stateless/02264_format_insert_infile.sql @@ -0,0 +1,2 @@ +-- { echo } +EXPLAIN SYNTAX INSERT INTO foo FROM INFILE '/dev/null'; From 93bbe9641aa162c65ea182279cfa10ab71e6d8cf Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 4 Apr 2022 10:30:31 +0300 Subject: [PATCH 2/2] Fix formatting of INSERT ... COMPRESSION Signed-off-by: Azat Khuzhin --- src/Parsers/ASTInsertQuery.cpp | 2 +- .../0_stateless/02264_format_insert_compression.reference | 3 +++ tests/queries/0_stateless/02264_format_insert_compression.sql | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02264_format_insert_compression.reference create mode 100644 tests/queries/0_stateless/02264_format_insert_compression.sql diff --git a/src/Parsers/ASTInsertQuery.cpp b/src/Parsers/ASTInsertQuery.cpp index 1d30c8f1bbd..40e14c918ff 100644 --- a/src/Parsers/ASTInsertQuery.cpp +++ b/src/Parsers/ASTInsertQuery.cpp @@ -91,7 +91,7 @@ void ASTInsertQuery::formatImpl(const FormatSettings & settings, FormatState & s << (settings.hilite ? hilite_keyword : "") << " COMPRESSION " << (settings.hilite ? hilite_none : "") - << compression->as().value.safeGet(); + << quoteString(compression->as().value.safeGet()); } if (select) diff --git a/tests/queries/0_stateless/02264_format_insert_compression.reference b/tests/queries/0_stateless/02264_format_insert_compression.reference new file mode 100644 index 00000000000..107b7fcb3e9 --- /dev/null +++ b/tests/queries/0_stateless/02264_format_insert_compression.reference @@ -0,0 +1,3 @@ +-- { echo } +EXPLAIN SYNTAX INSERT INTO foo FROM INFILE '/dev/null' COMPRESSION 'gz'; +INSERT INTO foo FROM INFILE \'/dev/null\' COMPRESSION \'gz\' diff --git a/tests/queries/0_stateless/02264_format_insert_compression.sql b/tests/queries/0_stateless/02264_format_insert_compression.sql new file mode 100644 index 00000000000..c095a8fbbb7 --- /dev/null +++ b/tests/queries/0_stateless/02264_format_insert_compression.sql @@ -0,0 +1,2 @@ +-- { echo } +EXPLAIN SYNTAX INSERT INTO foo FROM INFILE '/dev/null' COMPRESSION 'gz';