#31363 - remove schema delimiter setting and add test 00937_format_schema_rows_template.sh and reference

This commit is contained in:
Blargian 2024-01-22 22:59:59 +02:00
parent eae39ff545
commit 7b235fe643
4 changed files with 40 additions and 12 deletions

View File

@ -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;

View File

@ -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,

View File

@ -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

View File

@ -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