From 16323788f7ffd5ad3ac44de7a573f7406755592a Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Tue, 4 Jun 2024 14:02:40 +0800 Subject: [PATCH] Fix json --- velox/functions/sparksql/SIMDJsonFunctions.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/velox/functions/sparksql/SIMDJsonFunctions.h b/velox/functions/sparksql/SIMDJsonFunctions.h index 02cc97582599..f3fc2693d45b 100644 --- a/velox/functions/sparksql/SIMDJsonFunctions.h +++ b/velox/functions/sparksql/SIMDJsonFunctions.h @@ -15,6 +15,7 @@ */ #include "velox/functions/prestosql/SIMDJsonFunctions.h" +#include "velox/functions/prestosql/json/SIMDJsonUtil.h" using namespace simdjson; @@ -155,13 +156,17 @@ struct SIMDGetJsonObjectFunction { out_type& result, const arg_type& json, const arg_type& jsonPath) { - ParserContext ctx(json.data(), json.size()); + simdjson::ondemand::document jsonDoc; + simdjson::padded_string paddedJson(json.data(), json.size()); + if (simdjsonParse(paddedJson).get(jsonDoc)) { + return false; + } + try { - ctx.parseDocument(); simdjson_result rawResult = formattedJsonPath_.has_value() - ? ctx.jsonDoc.at_pointer(formattedJsonPath_.value().data()) - : ctx.jsonDoc.at_pointer(getFormattedJsonPath(jsonPath).data()); + ? jsonDoc.at_pointer(formattedJsonPath_.value().data()) + : jsonDoc.at_pointer(getFormattedJsonPath(jsonPath).data()); // Field not found. if (rawResult.error() == NO_SUCH_FIELD) { return false; @@ -175,7 +180,7 @@ struct SIMDGetJsonObjectFunction { } const char* currentPos; - ctx.jsonDoc.current_location().get(currentPos); + jsonDoc.current_location().get(currentPos); return isValidEndingCharacter(currentPos); } };