fix:json-remove, json is true/false, json-length bug

This commit is contained in:
obdev
2024-02-09 21:34:20 +00:00
committed by ob-robot
parent 9b9d246b5a
commit 094f71022c
16 changed files with 149 additions and 18 deletions

View File

@ -54,14 +54,19 @@ int ObExprJsonRemove::calc_result_typeN(ObExprResType& type,
return ret;
}
static int remove_from_json(ObJsonPath *path_node, ObIJsonBase *parent)
static int remove_from_json(ObJsonPath *path_node, ObIJsonBase *child)
{
INIT_SUCC(ret);
// remove item in hits
ObJsonPathBasicNode* last_node = path_node->last_path_node();
// get node to be removed
ObJsonNodeType type = parent->json_type();
if (type == ObJsonNodeType::J_OBJECT && last_node->get_node_type() == JPN_MEMBER) {
ObJsonNodeType type;
ObIJsonBase* parent = nullptr;
if (OB_FAIL(child->get_parent(parent)) || OB_ISNULL(parent)) {
// may be null parent
ret = OB_SUCCESS;
} else if (FALSE_IT(type = parent->json_type())) {
} else if (type == ObJsonNodeType::J_OBJECT && last_node->get_node_type() == JPN_MEMBER) {
ObPathMember member = last_node->get_object();
ObString key(member.len_, member.object_name_);
if (OB_FAIL(parent->object_remove(key))) {
@ -120,7 +125,7 @@ int ObExprJsonRemove::eval_json_remove(const ObExpr &expr, ObEvalCtx &ctx, ObDat
} else if (json_path->path_node_cnt() == 0) {
ret = OB_ERR_JSON_VACUOUS_PATH;
LOG_USER_ERROR(OB_ERR_JSON_VACUOUS_PATH);
} else if (OB_FAIL(json_doc->seek(*json_path, json_path->path_node_cnt() - 1, true, false, hits))) {
} else if (OB_FAIL(json_doc->seek(*json_path, json_path->path_node_cnt(), true, false, hits))) {
LOG_WARN("json seek failed", K(path_data->get_string()), K(ret));
} else if (hits.size() == 0){
continue;