xiaokang commented on code in PR #22298: URL: https://github.com/apache/doris/pull/22298#discussion_r1300230755
########## regression-test/data/jsonb_p0/test_jsonb_load_and_function.out: ########## @@ -87,6 +89,55 @@ 26 \N \N 27 {"k1":"v1","k2":200} {"k1":"v1","k2":200} 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} +29 [{"a":[{"b":12,"c":22,"d":33},{"c":"ss"}]},{"a":[{"c":12},{"c":"12"}],"s":11}] \N + +-- !select -- +1 \N \N +2 null \N +3 true \N +4 false \N +5 100 \N +6 10000 \N +7 1000000000 \N +8 1152921504606846976 \N +9 6.18 \N +10 "abcd" \N +11 {} \N +12 {"k1":"v31","k2":300} \N +13 [] [] +14 [123,456] [] +15 ["abc","def"] [] +16 [null,true,false,100,6.18,"abc"] [] +17 [{"k1":"v41","k2":400},1,"a",3.14] [] +18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} \N +26 \N \N +27 {"k1":"v1","k2":200} \N +28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N +29 [{"a":[{"b":12,"c":22,"d":33},{"c":"ss"}]},{"a":[{"c":12},{"c":"12"}],"s":11}] [] + +-- !select -- +1 \N \N +2 null \N +3 true \N +4 false \N +5 100 \N +6 10000 \N +7 1000000000 \N +8 1152921504606846976 \N +9 6.18 \N +10 "abcd" \N +11 {} \N +12 {"k1":"v31","k2":300} \N +13 [] [] +14 [123,456] [] +15 ["abc","def"] [] +16 [null,true,false,100,6.18,"abc"] [] +17 [{"k1":"v41","k2":400},1,"a",3.14] [] +18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} \N +26 \N \N +27 {"k1":"v1","k2":200} \N +28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N +29 [{"a":[{"b":12,"c":22,"d":33},{"c":"ss"}]},{"a":[{"c":12},{"c":"12"}],"s":11}] [] Review Comment: the result should not be empty array ########## be/src/vec/functions/function_jsonb.cpp: ########## @@ -66,16 +66,85 @@ namespace doris::vectorized { -enum class NullalbeMode { +enum class NullableMode { NULLABLE = 0, NOT_NULL, FOLLOW_INPUT, }; enum class JsonbParseErrorMode { FAIL = 0, RETURN_NULL, RETURN_VALUE, RETURN_INVALID }; +inline static JsonbValue* find_value(const std::unique_ptr<JsonbWriter>& writer, + JsonbValue* param_json, JsonbPath& path, int path_idx, + hDictFind handler) { + JsonbValue* pval = param_json; + for (size_t i = path_idx; i < path.get_leg_vector_size(); ++i) { + switch (path.get_leg_from_leg_vector(i)->type) { + case MEMBER_CODE: { + if (LIKELY(pval->type() == JsonbType::T_Object)) { + if (path.get_leg_from_leg_vector(i)->leg_len == 1 && + *path.get_leg_from_leg_vector(i)->leg_ptr == WILDCARD) { + continue; + } + + pval = ((ObjectVal*)pval) + ->find(path.get_leg_from_leg_vector(i)->leg_ptr, + path.get_leg_from_leg_vector(i)->leg_len, handler); + + if (!pval) return nullptr; + continue; + } else { + return nullptr; + } + } + case ARRAY_CODE: { + if (path.get_leg_from_leg_vector(i)->leg_len == 1 && + *path.get_leg_from_leg_vector(i)->leg_ptr == WILDCARD) { + if (LIKELY(pval->type() == JsonbType::T_Array)) { + // make array value + writer->writeStartArray(); + for (int j = 0; j < ((ArrayVal*)pval)->numElem(); ++j) { + JsonbValue* v = + find_value(writer, ((ArrayVal*)pval)->get(j), path, i + 1, handler); + if (v) { + writer->writeValue(v); Review Comment: value may be written by the same writer many times, since writer the the same one in recursive call ########## be/src/vec/functions/function_jsonb.cpp: ########## @@ -66,16 +66,85 @@ namespace doris::vectorized { -enum class NullalbeMode { +enum class NullableMode { NULLABLE = 0, NOT_NULL, FOLLOW_INPUT, }; enum class JsonbParseErrorMode { FAIL = 0, RETURN_NULL, RETURN_VALUE, RETURN_INVALID }; +inline static JsonbValue* find_value(const std::unique_ptr<JsonbWriter>& writer, Review Comment: it should be encapsulated in JsonbValue::findValue ########## regression-test/data/jsonb_p0/test_jsonb_load_and_function.out: ########## @@ -87,6 +89,55 @@ 26 \N \N 27 {"k1":"v1","k2":200} {"k1":"v1","k2":200} 28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} +29 [{"a":[{"b":12,"c":22,"d":33},{"c":"ss"}]},{"a":[{"c":12},{"c":"12"}],"s":11}] \N + +-- !select -- +1 \N \N +2 null \N +3 true \N +4 false \N +5 100 \N +6 10000 \N +7 1000000000 \N +8 1152921504606846976 \N +9 6.18 \N +10 "abcd" \N +11 {} \N +12 {"k1":"v31","k2":300} \N +13 [] [] +14 [123,456] [] +15 ["abc","def"] [] +16 [null,true,false,100,6.18,"abc"] [] +17 [{"k1":"v41","k2":400},1,"a",3.14] [] +18 {"k1":"v31","k2":300,"a1":[{"k1":"v41","k2":400},1,"a",3.14]} \N +26 \N \N +27 {"k1":"v1","k2":200} \N +28 {"a.b.c":{"k1.a1":"v31","k2":300},"a":"niu"} \N +29 [{"a":[{"b":12,"c":22,"d":33},{"c":"ss"}]},{"a":[{"c":12},{"c":"12"}],"s":11}] [] Review Comment: the result should not be empty array -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org