Backport #70218 to 24.8: Respect setting allow_simdjson in JSON type parser

This commit is contained in:
robot-clickhouse 2024-10-02 13:13:12 +00:00
parent f8bcad44be
commit 8bd8d333c6
3 changed files with 30 additions and 10 deletions

View File

@ -21,12 +21,13 @@
#include <IO/Operators.h> #include <IO/Operators.h>
#if USE_SIMDJSON #if USE_SIMDJSON
#include <Common/JSONParsers/SimdJSONParser.h> # include <Common/JSONParsers/SimdJSONParser.h>
#endif #endif
#if USE_RAPIDJSON #if USE_RAPIDJSON
#include <Common/JSONParsers/RapidJSONParser.h> # include <Common/JSONParsers/RapidJSONParser.h>
#else
# include <Common/JSONParsers/DummyJSONParser.h>
#endif #endif
#include <Common/JSONParsers/DummyJSONParser.h>
namespace DB namespace DB
{ {
@ -119,13 +120,19 @@ SerializationPtr DataTypeObject::doGetDefaultSerialization() const
switch (schema_format) switch (schema_format)
{ {
case SchemaFormat::JSON: case SchemaFormat::JSON:
#ifdef USE_SIMDJSON #if USE_SIMDJSON
return std::make_shared<SerializationJSON<SimdJSONParser>>( auto context = CurrentThread::getQueryContext();
std::move(typed_path_serializations), if (!context)
paths_to_skip, context = Context::getGlobalContextInstance();
path_regexps_to_skip, if (context->getSettingsRef().allow_simdjson)
buildJSONExtractTree<SimdJSONParser>(getPtr(), "JSON serialization")); return std::make_shared<SerializationJSON<SimdJSONParser>>(
#elif USE_RAPIDJSON std::move(typed_path_serializations),
paths_to_skip,
path_regexps_to_skip,
buildJSONExtractTree<SimdJSONParser>(getPtr(), "JSON serialization"));
#endif
#if USE_RAPIDJSON
return std::make_shared<SerializationJSON<RapidJSONParser>>( return std::make_shared<SerializationJSON<RapidJSONParser>>(
std::move(typed_path_serializations), std::move(typed_path_serializations),
paths_to_skip, paths_to_skip,

View File

@ -0,0 +1,2 @@
2
2

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# Tags: no-fasttest
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh
$CLICKHOUSE_LOCAL --allow_experimental_json_type=1 --stacktrace -q "select '{\"a\" : 4ab2}'::JSON" 2>&1 | grep -c -F "SimdJSON"
$CLICKHOUSE_LOCAL --allow_experimental_json_type=1 --allow_simdjson=0 --stacktrace -q "select '{\"a\" : 4ab2}'::JSON" 2>&1 | grep -c -F "RapidJSON"