LemonLiTree commented on code in PR #19646:
URL: https://github.com/apache/doris/pull/19646#discussion_r1208909097
##########
be/src/util/jsonb_document.h:
##########
@@ -1200,52 +1225,125 @@ inline JsonbValue* JsonbValue::findPath(const char*
key_path, unsigned int kp_le
stream.clear_legPtr();
stream.clear_legLen();
- if (!JsonbPath::parsePath(&stream, pval)) {
+ if (!JsonbPath::parsePath(&stream)) {
+ is_invalid_json_path = stream.get_is_invalid_json_path();
return nullptr;
}
if (stream.get_legLen() == 0) {
return nullptr;
}
- if (LIKELY(pval->type_ == JsonbType::T_Object)) {
- if (stream.get_legLen() == 1 && *stream.get_legPtr() == WILDCARD) {
- return pval;
- } else if (stream.get_hasEscapes()) {
- stream.remove_escapes();
- }
+ if (stream.get_type() == MEMBER_CODE) {
+ if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ return nullptr;
+ } else if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ if (stream.get_legLen() == 1 && *stream.get_legPtr() ==
WILDCARD) {
+ continue;
+ } else if (stream.get_hasEscapes()) {
+ stream.remove_escapes();
+ }
- pval = ((ObjectVal*)pval)->find(stream.get_legPtr(),
stream.get_legLen(), handler);
+ pval = ((ObjectVal*)pval)->find(stream.get_legPtr(),
stream.get_legLen(), handler);
- if (!pval) return nullptr;
- } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ if (!pval) return nullptr;
+ } else {
+ return nullptr;
+ }
+ } else if (stream.get_type() == ARRAY_CODE) {
int index = 0;
- std::string idx_string(stream.get_legPtr(), stream.get_legLen());
+ std::string_view idx_string(stream.get_legPtr(),
stream.get_legLen());
if (stream.get_legLen() == 1 && *stream.get_legPtr() == WILDCARD) {
- return pval;
- } else if (std::string(stream.get_legPtr(), 4) == LAST) {
+ if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ return nullptr;
+ } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ continue;
+ } else {
+ return nullptr;
+ }
+ } else if (*stream.get_legPtr() == MINUS && stream.get_legLen() >
1) {
+ auto result = std::from_chars(idx_string.data(),
+ idx_string.data() +
idx_string.size(), index);
+ if (result.ec != std::errc()) {
+ is_invalid_json_path = true;
+ return nullptr;
+ }
+
+ if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ if (index == 0 || index == -1) {
+ continue;
+ } else {
+ return nullptr;
+ }
+ } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ size_t num = ((ArrayVal*)pval)->numElem();
+ if (-index > num) return nullptr;
+ index = num + index;
+ } else {
+ return nullptr;
+ }
+ } else if (std::equal(LAST, LAST + 4, stream.get_legPtr(),
+ [](char c1, char c2) {
+ return std::tolower(c1) ==
std::tolower(c2);
+ }) &&
+ stream.get_legLen() >= 4) {
auto pos = idx_string.find(MINUS);
if (pos != std::string::npos) {
idx_string = idx_string.substr(pos + 1);
- size_t num = ((ArrayVal*)pval)->numElem();
- if (std::stoi(idx_string) > num) {
- return nullptr; //invalid json path
+
+ auto result = std::from_chars(idx_string.data(),
+ idx_string.data() +
idx_string.size(), index);
+ if (result.ec != std::errc()) {
+ is_invalid_json_path = true;
+ return nullptr;
+ }
+
+ if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ if (index == 0) {
+ continue;
+ } else {
+ return nullptr;
+ }
+ } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ size_t num = ((ArrayVal*)pval)->numElem();
+ if (index > num) return nullptr;
+ index = num - 1 - index;
+ } else {
+ return nullptr;
}
- index = num - 1 - std::stoi(idx_string);
} else if (stream.get_legLen() == 4) {
- index = ((ArrayVal*)pval)->numElem() - 1;
+ if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ continue;
+ } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ index = ((ArrayVal*)pval)->numElem() - 1;
+ } else {
+ return nullptr;
+ }
+
} else {
- return nullptr; //invalid json path
+ is_invalid_json_path = true;
+ return nullptr;
}
} else {
- std::string::size_type pos;
- index = std::stoi(idx_string, &pos, 10);
- if (pos != idx_string.size()) {
- return nullptr; //invalid json path
- } else if (index >= ((ArrayVal*)pval)->numElem()) {
- return nullptr; //invalid json path
+ auto result = std::from_chars(idx_string.data(),
+ idx_string.data() +
idx_string.size(), index);
+ if (result.ec != std::errc()) {
+ is_invalid_json_path = true;
+ return nullptr;
+ }
+
+ if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ if (index == 0) {
+ continue;
Review Comment:
yeah, mysql supports such
##########
be/src/util/jsonb_document.h:
##########
@@ -1200,52 +1225,125 @@ inline JsonbValue* JsonbValue::findPath(const char*
key_path, unsigned int kp_le
stream.clear_legPtr();
stream.clear_legLen();
- if (!JsonbPath::parsePath(&stream, pval)) {
+ if (!JsonbPath::parsePath(&stream)) {
+ is_invalid_json_path = stream.get_is_invalid_json_path();
return nullptr;
}
if (stream.get_legLen() == 0) {
return nullptr;
}
- if (LIKELY(pval->type_ == JsonbType::T_Object)) {
- if (stream.get_legLen() == 1 && *stream.get_legPtr() == WILDCARD) {
- return pval;
- } else if (stream.get_hasEscapes()) {
- stream.remove_escapes();
- }
+ if (stream.get_type() == MEMBER_CODE) {
+ if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ return nullptr;
+ } else if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ if (stream.get_legLen() == 1 && *stream.get_legPtr() ==
WILDCARD) {
+ continue;
+ } else if (stream.get_hasEscapes()) {
+ stream.remove_escapes();
+ }
- pval = ((ObjectVal*)pval)->find(stream.get_legPtr(),
stream.get_legLen(), handler);
+ pval = ((ObjectVal*)pval)->find(stream.get_legPtr(),
stream.get_legLen(), handler);
- if (!pval) return nullptr;
- } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ if (!pval) return nullptr;
+ } else {
+ return nullptr;
+ }
+ } else if (stream.get_type() == ARRAY_CODE) {
int index = 0;
- std::string idx_string(stream.get_legPtr(), stream.get_legLen());
+ std::string_view idx_string(stream.get_legPtr(),
stream.get_legLen());
if (stream.get_legLen() == 1 && *stream.get_legPtr() == WILDCARD) {
- return pval;
- } else if (std::string(stream.get_legPtr(), 4) == LAST) {
+ if (LIKELY(pval->type_ == JsonbType::T_Object)) {
+ return nullptr;
+ } else if (LIKELY(pval->type_ == JsonbType::T_Array)) {
+ continue;
+ } else {
+ return nullptr;
+ }
+ } else if (*stream.get_legPtr() == MINUS && stream.get_legLen() >
1) {
Review Comment:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]