From 8bd8d333c68d84eff668e9d40ac5ae73b17b6871 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Wed, 2 Oct 2024 13:13:12 +0000 Subject: [PATCH] Backport #70218 to 24.8: Respect setting allow_simdjson in JSON type parser --- src/DataTypes/DataTypeObject.cpp | 27 ++++++++++++------- .../03246_json_simd_rapid_parsers.reference | 2 ++ .../03246_json_simd_rapid_parsers.sh | 11 ++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 tests/queries/0_stateless/03246_json_simd_rapid_parsers.reference create mode 100755 tests/queries/0_stateless/03246_json_simd_rapid_parsers.sh diff --git a/src/DataTypes/DataTypeObject.cpp b/src/DataTypes/DataTypeObject.cpp index 88e2a90cbeb..e5c3f795495 100644 --- a/src/DataTypes/DataTypeObject.cpp +++ b/src/DataTypes/DataTypeObject.cpp @@ -21,12 +21,13 @@ #include #if USE_SIMDJSON -#include +# include #endif #if USE_RAPIDJSON -#include +# include +#else +# include #endif -#include namespace DB { @@ -119,13 +120,19 @@ SerializationPtr DataTypeObject::doGetDefaultSerialization() const switch (schema_format) { case SchemaFormat::JSON: -#ifdef USE_SIMDJSON - return std::make_shared>( - std::move(typed_path_serializations), - paths_to_skip, - path_regexps_to_skip, - buildJSONExtractTree(getPtr(), "JSON serialization")); -#elif USE_RAPIDJSON +#if USE_SIMDJSON + auto context = CurrentThread::getQueryContext(); + if (!context) + context = Context::getGlobalContextInstance(); + if (context->getSettingsRef().allow_simdjson) + return std::make_shared>( + std::move(typed_path_serializations), + paths_to_skip, + path_regexps_to_skip, + buildJSONExtractTree(getPtr(), "JSON serialization")); +#endif + +#if USE_RAPIDJSON return std::make_shared>( std::move(typed_path_serializations), paths_to_skip, diff --git a/tests/queries/0_stateless/03246_json_simd_rapid_parsers.reference b/tests/queries/0_stateless/03246_json_simd_rapid_parsers.reference new file mode 100644 index 00000000000..51993f072d5 --- /dev/null +++ b/tests/queries/0_stateless/03246_json_simd_rapid_parsers.reference @@ -0,0 +1,2 @@ +2 +2 diff --git a/tests/queries/0_stateless/03246_json_simd_rapid_parsers.sh b/tests/queries/0_stateless/03246_json_simd_rapid_parsers.sh new file mode 100755 index 00000000000..58299fa66bb --- /dev/null +++ b/tests/queries/0_stateless/03246_json_simd_rapid_parsers.sh @@ -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" + +