From 2b39f6c019294d9bce1443a7dd0592d8ed0472c0 Mon Sep 17 00:00:00 2001 From: zhanglistar Date: Wed, 20 Nov 2024 16:40:09 +0800 Subject: [PATCH] fix style --- src/Common/ErrorCodes.cpp | 1 + src/Common/JSONParsers/SimdJSONParser.h | 7 +------ src/Formats/JSONExtractTree.cpp | 2 +- src/Functions/FunctionSQLJSON.h | 5 ----- src/Functions/FunctionsJSON.cpp | 2 +- src/Functions/JSONPath/Generator/IGenerator.h | 2 +- src/Functions/JSONPath/Generator/IVisitor.h | 13 +++++++++---- .../Generator/VisitorJSONPathMemberAccess.h | 2 +- .../JSONPath/Generator/VisitorJSONPathRange.h | 2 +- .../JSONPath/Generator/VisitorJSONPathRoot.h | 2 +- .../JSONPath/Generator/VisitorJSONPathStar.h | 2 +- 11 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/Common/ErrorCodes.cpp b/src/Common/ErrorCodes.cpp index 4471484a4af..f057dc2995f 100644 --- a/src/Common/ErrorCodes.cpp +++ b/src/Common/ErrorCodes.cpp @@ -614,6 +614,7 @@ M(734, CANNOT_WRITE_AFTER_BUFFER_CANCELED) \ M(735, QUERY_WAS_CANCELLED_BY_CLIENT) \ M(736, JSON_PARSE_ERROR) \ +\ M(900, DISTRIBUTED_CACHE_ERROR) \ M(901, CANNOT_USE_DISTRIBUTED_CACHE) \ M(902, PROTOCOL_VERSION_MISMATCH) \ diff --git a/src/Common/JSONParsers/SimdJSONParser.h b/src/Common/JSONParsers/SimdJSONParser.h index 70306cbe57e..d54fd11c10e 100644 --- a/src/Common/JSONParsers/SimdJSONParser.h +++ b/src/Common/JSONParsers/SimdJSONParser.h @@ -1,10 +1,8 @@ #pragma once -#include "Common/StackTrace.h" #include "config.h" #if USE_SIMDJSON -# include # include # include # include @@ -294,7 +292,7 @@ public: simdjson::ondemand::number_type nt{}; auto res = value.get_number_type().get(nt); chassert(res == simdjson::SUCCESS); - switch(nt) + switch (nt) { case simdjson::ondemand::number_type::signed_integer: format.number(value.get_int64().value_unsafe()); @@ -663,7 +661,6 @@ struct OnDemandSimdJSONParser ALWAYS_INLINE KeyValuePair operator*() const { - //SIMDJSON_ASSIGN_OR_THROW(auto field_wrapper, *it); auto field_wrapper = *it; if (field_wrapper.error()) { @@ -716,8 +713,6 @@ struct OnDemandSimdJSONParser /// Optional: Provides access to an object's element by index. KeyValuePair operator[](size_t index) const { - ///SIMDJSON_ASSIGN_OR_THROW(auto b, object.reset()); - ///(void)b; SIMDJSON_ASSIGN_OR_THROW(auto it, object.begin()); while (index--) { diff --git a/src/Formats/JSONExtractTree.cpp b/src/Formats/JSONExtractTree.cpp index 17b59e80d6f..b8b70ce3d07 100644 --- a/src/Formats/JSONExtractTree.cpp +++ b/src/Formats/JSONExtractTree.cpp @@ -1324,7 +1324,7 @@ public: size_t old_size = tuple_col.size(); auto object = element.getObject(); auto it = object.begin(); - size_t object_size{}; + size_t object_size = 0; for (; it != object.end(); ++it) { ++object_size; diff --git a/src/Functions/FunctionSQLJSON.h b/src/Functions/FunctionSQLJSON.h index 300c6152b4d..58e18df23b0 100644 --- a/src/Functions/FunctionSQLJSON.h +++ b/src/Functions/FunctionSQLJSON.h @@ -368,7 +368,6 @@ public: /// Here it is possible to handle errors with ON ERROR (as described in ISO/IEC TR 19075-6), /// however this functionality is not implemented yet } - //current_element = root; } if (status == VisitorStatus::Exhausted) @@ -420,10 +419,8 @@ public: bool success = false; const char * array_begin = "["; const char * array_end = "]"; - //const char * comma = ", "; JSONStringSerializer json_serializer(col_str); json_serializer.addRawData(array_begin, 1); - //std::vector result{}; std::function result_func= [&json_serializer](const Element & element) { json_serializer.addElement(element); }; while ((status = generator_json_path.getNextItemBatch(current_element, result_func)) != VisitorStatus::Exhausted) { @@ -437,8 +434,6 @@ public: /// Here it is possible to handle errors with ON ERROR (as described in ISO/IEC TR 19075-6), /// however this functionality is not implemented yet } - //current_element = root; - //result.clear(); } if (!success) { diff --git a/src/Functions/FunctionsJSON.cpp b/src/Functions/FunctionsJSON.cpp index d2457784d00..e1815515ff9 100644 --- a/src/Functions/FunctionsJSON.cpp +++ b/src/Functions/FunctionsJSON.cpp @@ -623,7 +623,7 @@ public: static bool insertResultToColumn(IColumn & dest, const Element & element, std::string_view, const FormatSettings &, String &) { - size_t size{}; + size_t size; if (element.isArray()) size = element.getArray().size(); else if (element.isObject()) diff --git a/src/Functions/JSONPath/Generator/IGenerator.h b/src/Functions/JSONPath/Generator/IGenerator.h index a91c940316d..ffb44d8ad42 100644 --- a/src/Functions/JSONPath/Generator/IGenerator.h +++ b/src/Functions/JSONPath/Generator/IGenerator.h @@ -24,7 +24,7 @@ public: */ virtual VisitorStatus getNextItem(TElement & element) = 0; - virtual VisitorStatus getNextItemBatch(TElement & element, std::function & ) = 0; + virtual VisitorStatus getNextItemBatch(TElement & element, std::function & res_func) = 0; virtual ~IGenerator() = default; }; diff --git a/src/Functions/JSONPath/Generator/IVisitor.h b/src/Functions/JSONPath/Generator/IVisitor.h index 1a39a09bad6..72c3196efd5 100644 --- a/src/Functions/JSONPath/Generator/IVisitor.h +++ b/src/Functions/JSONPath/Generator/IVisitor.h @@ -15,14 +15,19 @@ public: * Applies this visitor to document and mutates its state * @param element simdjson element */ - virtual VisitorStatus visit(typename JSONParser::Element & element) = 0; - virtual VisitorStatus visitBatch(TElement & element, std::function & , bool ) = 0; + virtual VisitorStatus visit(TElement & element) = 0; - /** + /** + * Applies this visitor to document and mutates its state, returning a batch of results + * @param element simdjson element + */ + virtual VisitorStatus visitBatch(TElement &element, std::function & res_func, bool can_reduce) = 0; + + /** * Applies this visitor to document, but does not mutate state * @param element simdjson element */ - virtual VisitorStatus apply(typename JSONParser::Element & element) = 0; + virtual VisitorStatus apply(typename JSONParser::Element & element) const = 0; /** * Restores visitor's initial state for later use diff --git a/src/Functions/JSONPath/Generator/VisitorJSONPathMemberAccess.h b/src/Functions/JSONPath/Generator/VisitorJSONPathMemberAccess.h index efbd3d9fba6..ec36a67aba1 100644 --- a/src/Functions/JSONPath/Generator/VisitorJSONPathMemberAccess.h +++ b/src/Functions/JSONPath/Generator/VisitorJSONPathMemberAccess.h @@ -17,7 +17,7 @@ public: const char * getName() const override { return "VisitorJSONPathMemberAccess"; } - VisitorStatus apply(typename JSONParser::Element & element) override + VisitorStatus apply(typename JSONParser::Element & element) const override { typename JSONParser::Element result; auto obj = element.getObject(); diff --git a/src/Functions/JSONPath/Generator/VisitorJSONPathRange.h b/src/Functions/JSONPath/Generator/VisitorJSONPathRange.h index 7cb429d59bb..09763fe0b5b 100644 --- a/src/Functions/JSONPath/Generator/VisitorJSONPathRange.h +++ b/src/Functions/JSONPath/Generator/VisitorJSONPathRange.h @@ -19,7 +19,7 @@ public: const char * getName() const override { return "VisitorJSONPathRange"; } - VisitorStatus apply(typename JSONParser::Element & element) override + VisitorStatus apply(typename JSONParser::Element & element) const override { element = (*array)[current_index]; return VisitorStatus::Ok; diff --git a/src/Functions/JSONPath/Generator/VisitorJSONPathRoot.h b/src/Functions/JSONPath/Generator/VisitorJSONPathRoot.h index 6f980073030..cc9001110db 100644 --- a/src/Functions/JSONPath/Generator/VisitorJSONPathRoot.h +++ b/src/Functions/JSONPath/Generator/VisitorJSONPathRoot.h @@ -15,7 +15,7 @@ public: const char * getName() const override { return "VisitorJSONPathRoot"; } - VisitorStatus apply(typename JSONParser::Element & /*element*/) override + VisitorStatus apply(typename JSONParser::Element & /*element*/) const override { /// No-op on document, since we are already passed document's root return VisitorStatus::Ok; diff --git a/src/Functions/JSONPath/Generator/VisitorJSONPathStar.h b/src/Functions/JSONPath/Generator/VisitorJSONPathStar.h index d36a323abe7..51b499bd892 100644 --- a/src/Functions/JSONPath/Generator/VisitorJSONPathStar.h +++ b/src/Functions/JSONPath/Generator/VisitorJSONPathStar.h @@ -18,7 +18,7 @@ public: const char * getName() const override { return "VisitorJSONPathStar"; } - VisitorStatus apply(typename JSONParser::Element & element) override + VisitorStatus apply(typename JSONParser::Element & element) const override { element = array.value()[current_index]; return VisitorStatus::Ok;