Merge pull request #62840 from CurtizJ/fix-format-row

Fix crash in function `formatRow` with `JSON` format and HTTP  interface
This commit is contained in:
Alexey Milovidov 2024-04-23 02:07:09 +00:00 committed by GitHub
commit 27aa03983a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View File

@ -38,8 +38,14 @@ public:
: format_name(std::move(format_name_))
, arguments_column_names(std::move(arguments_column_names_))
, context(std::move(context_))
, format_settings(getFormatSettings(context))
{
FormatFactory::instance().checkFormatName(format_name);
/// We don't need handling exceptions while formatting as a row.
/// But it can be enabled in query sent via http interface.
format_settings.json.valid_output_on_exception = false;
format_settings.xml.valid_output_on_exception = false;
}
String getName() const override { return name; }
@ -68,7 +74,6 @@ public:
}
materializeBlockInplace(arg_columns);
auto format_settings = getFormatSettings(context);
auto out = FormatFactory::instance().getOutputFormat(format_name, buffer, arg_columns, context, format_settings);
/// This function make sense only for row output formats.
@ -104,6 +109,7 @@ private:
String format_name;
Names arguments_column_names;
ContextPtr context;
FormatSettings format_settings;
};
template <bool no_newline>

View File

@ -0,0 +1,15 @@
{"number":"0"}\n
{"number":"1"}\n
{"number":"2"}\n
{"number":"3"}\n
{"number":"4"}\n
{"number":"5"}\n
{"number":"6"}\n
{"number":"7"}\n
{"number":"8"}\n
{"number":"9"}\n
{"number":"10"}\n
{"number":"11"}\n
{"number":"12"}\n
{"number":"13"}\n
{"number":"14"}\n

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
$CLICKHOUSE_CURL -sS "$CLICKHOUSE_URL" --data-binary "SELECT formatRow('JSONEachRow', number) as test FROM (SELECT number FROM numbers(15))"