bugfix: json_set order & JsonBaseCmp bugfix

This commit is contained in:
wu-xingying
2023-09-14 04:17:52 +00:00
committed by ob-robot
parent b919db8746
commit 1f0c63c0d7
2 changed files with 11 additions and 7 deletions

View File

@ -29,15 +29,15 @@ namespace common {
struct ObJsonBaseCmp { struct ObJsonBaseCmp {
bool operator()(const ObIJsonBase *a, const ObIJsonBase *b) { bool operator()(const ObIJsonBase *a, const ObIJsonBase *b) {
bool is_eq = false; bool is_less = false;
if (a->is_tree() && b->is_tree()) { if (a->is_tree() && b->is_tree()) {
is_eq = (a == b); is_less = (a < b);
} else if (a->is_bin() && b->is_bin()) { } else if (a->is_bin() && b->is_bin()) {
is_eq = (a->get_data() == b->get_data()); is_less = (a->get_data() < b->get_data());
} else { } else {
LOG_WARN_RET(OB_ERR_UNEXPECTED, "unexpected type", K(OB_ERR_UNEXPECTED), K(*a), K(*b)); LOG_WARN_RET(OB_ERR_UNEXPECTED, "unexpected type", K(OB_ERR_UNEXPECTED), K(*a), K(*b));
} }
return is_eq; return is_less;
} }
}; };
@ -620,7 +620,7 @@ int ObIJsonBase::find_array_child(ObIAllocator* allocator, ObSeekParentInfo &par
if (is_lax) { if (is_lax) {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("should be mysql mode!", K(ret), K(only_need_one)); LOG_WARN("should be mysql mode!", K(ret), K(only_need_one));
}else if (cur_json_type == ObJsonNodeType::J_ARRAY) { } else if (cur_json_type == ObJsonNodeType::J_ARRAY) {
if (OB_FAIL(find_array_range(allocator, parent_info, cur_node, last_node, path_node, if (OB_FAIL(find_array_range(allocator, parent_info, cur_node, last_node, path_node,
is_auto_wrap, only_need_one, is_lax, dup, res, sql_var))) { is_auto_wrap, only_need_one, is_lax, dup, res, sql_var))) {
LOG_WARN("fail in find array range.", K(ret)); LOG_WARN("fail in find array range.", K(ret));

View File

@ -95,8 +95,12 @@ int ObExprJsonSet::set_value(ObJsonBaseVector &hit, ObIJsonBase *&json_doc, ObIJ
} else { } else {
ObJsonArray* json_array = (ObJsonArray*)new(array_buf)ObJsonArray(allocator); ObJsonArray* json_array = (ObJsonArray*)new(array_buf)ObJsonArray(allocator);
ObJsonNode *j_parent = static_cast<ObJsonNode *>(pos_node)->get_parent(); ObJsonNode *j_parent = static_cast<ObJsonNode *>(pos_node)->get_parent();
if (OB_FAIL(json_array->array_append(pos_node)) bool is_idx_from_end = path_last->node_content_.array_cell_.is_index_from_end_;
|| OB_FAIL(json_array->array_append(json_val))) { if (!is_idx_from_end && (OB_FAIL(json_array->array_append(pos_node))
|| OB_FAIL(json_array->array_append(json_val)))) {
LOG_WARN("error, array append node failed", K(ret));
} else if (is_idx_from_end && (OB_FAIL(json_array->array_append(json_val))
|| OB_FAIL(json_array->array_append(pos_node)))) {
LOG_WARN("error, array append node failed", K(ret)); LOG_WARN("error, array append node failed", K(ret));
} else if (OB_ISNULL(j_parent)){ } else if (OB_ISNULL(j_parent)){
json_doc = json_array; json_doc = json_array;