From 7b235fe643e744b643be6e4d0788de63cae4a07c Mon Sep 17 00:00:00 2001 From: Blargian Date: Mon, 22 Jan 2024 22:59:59 +0200 Subject: [PATCH] #31363 - remove schema delimiter setting and add test 00937_format_schema_rows_template.sh and reference --- src/Formats/FormatFactory.cpp | 1 - .../Impl/TemplateBlockOutputFormat.cpp | 15 +++------ ...0937_format_schema_rows_template.reference | 4 +++ .../00937_format_schema_rows_template.sh | 32 +++++++++++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 tests/queries/0_stateless/00937_format_schema_rows_template.reference create mode 100755 tests/queries/0_stateless/00937_format_schema_rows_template.sh diff --git a/src/Formats/FormatFactory.cpp b/src/Formats/FormatFactory.cpp index 6f7f758621c..184778a9fa9 100644 --- a/src/Formats/FormatFactory.cpp +++ b/src/Formats/FormatFactory.cpp @@ -167,7 +167,6 @@ FormatSettings getFormatSettings(ContextPtr context, const Settings & settings) format_settings.template_settings.row_between_delimiter = settings.format_template_rows_between_delimiter; format_settings.template_settings.row_format = settings.format_template_row; format_settings.template_settings.row_format_schema = settings.format_schema_rows_template; - format_settings.template_settings.row_between_delimiter_schema = settings.format_schema_rows_between_delimiter; format_settings.tsv.crlf_end_of_line = settings.output_format_tsv_crlf_end_of_line; format_settings.tsv.empty_as_default = settings.input_format_tsv_empty_as_default; format_settings.tsv.enum_as_number = settings.input_format_tsv_enum_as_number; diff --git a/src/Processors/Formats/Impl/TemplateBlockOutputFormat.cpp b/src/Processors/Formats/Impl/TemplateBlockOutputFormat.cpp index 495cc0e541e..99a7f59c09e 100644 --- a/src/Processors/Formats/Impl/TemplateBlockOutputFormat.cpp +++ b/src/Processors/Formats/Impl/TemplateBlockOutputFormat.cpp @@ -221,21 +221,14 @@ void registerOutputFormatTemplate(FormatFactory & factory) }; if (settings.template_settings.row_format.empty()) { - if (settings.template_settings.row_format_schema.empty()) - { - throw Exception(DB::ErrorCodes::INVALID_TEMPLATE_FORMAT, "Expected either format_template_row or format_schema_rows_template"); - } - else - { - row_format = ParsedTemplateFormatString(); - row_format.parse(settings.template_settings.row_format_schema,idx_by_name); - } + row_format = ParsedTemplateFormatString(); + row_format.parse(settings.template_settings.row_format_schema,idx_by_name); } else { - if (settings.template_settings.row_format_schema.empty()) + if (!settings.template_settings.row_format_schema.empty()) { - throw Exception(DB::ErrorCodes::INVALID_TEMPLATE_FORMAT, "Expected either format_template_row or format_schema_rows_template"); + throw Exception(DB::ErrorCodes::INVALID_TEMPLATE_FORMAT, "Expected either format_template_row or format_schema_rows_template, but not both"); } row_format = ParsedTemplateFormatString( FormatSchemaInfo(settings.template_settings.row_format, "Template", false, diff --git a/tests/queries/0_stateless/00937_format_schema_rows_template.reference b/tests/queries/0_stateless/00937_format_schema_rows_template.reference new file mode 100644 index 00000000000..167f16ec55f --- /dev/null +++ b/tests/queries/0_stateless/00937_format_schema_rows_template.reference @@ -0,0 +1,4 @@ +Question: 'How awesome is clickhouse?', Answer: 'unbelievably awesome!', Number of Likes: 456, Date: 2016-01-02; +Question: 'How fast is clickhouse?', Answer: 'Lightning fast!', Number of Likes: 9876543210, Date: 2016-01-03; +Question: 'Is it opensource', Answer: 'of course it is!', Number of Likes: 789, Date: 2016-01-04 + diff --git a/tests/queries/0_stateless/00937_format_schema_rows_template.sh b/tests/queries/0_stateless/00937_format_schema_rows_template.sh new file mode 100755 index 00000000000..651e3618f83 --- /dev/null +++ b/tests/queries/0_stateless/00937_format_schema_rows_template.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2016 + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +# shellcheck source=../shell_config.sh +. "$CURDIR"/../shell_config.sh + +# Test format_schema_rows_template setting + +$CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS template"; +$CLICKHOUSE_CLIENT --query="CREATE TABLE template (question String, answer String, likes UInt64, date Date) ENGINE = Memory"; +$CLICKHOUSE_CLIENT --query="INSERT INTO template VALUES +('How awesome is clickhouse?', 'unbelievably awesome!', 456, '2016-01-02'),\ +('How fast is clickhouse?', 'Lightning fast!', 9876543210, '2016-01-03'),\ +('Is it opensource', 'of course it is!', 789, '2016-01-04')"; + +$CLICKHOUSE_CLIENT --query="SELECT * FROM template GROUP BY question, answer, likes, date WITH TOTALS ORDER BY date LIMIT 3 FORMAT Template SETTINGS \ +format_schema_rows_template = 'Question: \${question:Quoted}, Answer: \${answer:Quoted}, Number of Likes: \${likes:Raw}, Date: \${date:Raw}', \ +format_template_rows_between_delimiter = ';\n'"; + +echo -e "\n" + +# Test that if both format_schema_rows_template setting and format_template_row are provided, error is thrown + +echo -ne 'Question: ${question:Quoted}, Answer: ${answer:Quoted}, Number of Likes: ${likes:Raw}, Date: ${date:Raw}' > "$CURDIR"/00937_template_output_format_row.tmp +$CLICKHOUSE_CLIENT --query="SELECT * FROM template GROUP BY question, answer, likes, date WITH TOTALS ORDER BY date LIMIT 3 FORMAT Template SETTINGS \ +format_template_row = '$CURDIR/00937_template_output_format_row.tmp', \ +format_schema_rows_template = 'Question: \${question:Quoted}, Answer: \${answer:Quoted}, Number of Likes: \${likes:Raw}, Date: \${date:Raw}', \ +format_template_rows_between_delimiter = ';\n'"; -- { serverError 474 } + +$CLICKHOUSE_CLIENT --query="DROP TABLE template"; +rm "$CURDIR"/00937_template_output_format_row.tmp \ No newline at end of file