fix: json type json-object support empty string key

This commit is contained in:
obdev
2022-11-03 01:11:04 +00:00
committed by wangzelin.wzl
parent add9d0d15b
commit 13774e3016
5 changed files with 21 additions and 19 deletions

View File

@ -1322,11 +1322,16 @@ int ObJsonBin::deserialize_json_object_v0(const char *data, uint64_t length, ObJ
} else { } else {
// TODO if with key dict, read key from dict // TODO if with key dict, read key from dict
// to consider, add option to controll need alloc or not // to consider, add option to controll need alloc or not
void *key_buf = allocator_->alloc(key_len); void *key_buf = nullptr;
if (key_buf == NULL) { if (key_len > 0) {
ret = OB_ALLOCATE_MEMORY_FAILED; key_buf = allocator_->alloc(key_len);
LOG_WARN("fail to alloc memory for data buf", K(ret)); if (key_buf == NULL) {
} else { ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to alloc memory for data buf", K(ret));
}
}
if (OB_SUCC(ret)) {
MEMCPY(key_buf, data + key_offset, key_len); MEMCPY(key_buf, data + key_offset, key_len);
ObString key(key_len, reinterpret_cast<const char*>(key_buf)); ObString key(key_len, reinterpret_cast<const char*>(key_buf));
const char *val = data + value_offset; const char *val = data + value_offset;

View File

@ -1049,7 +1049,7 @@ int ObJsonPath::parse_name_with_rapidjson(char*& str, uint64_t& len)
ObJsonString *val = static_cast<ObJsonString *>(dom); ObJsonString *val = static_cast<ObJsonString *>(dom);
len = val->value().length(); len = val->value().length();
str = static_cast<char*> (allocator_->alloc(len)); str = static_cast<char*> (allocator_->alloc(len));
if (OB_ISNULL(str)) { if (len > 0 && OB_ISNULL(str)) {
ret = OB_ALLOCATE_MEMORY_FAILED; ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("fail to allocate memory for member_name.", LOG_WARN("fail to allocate memory for member_name.",
K(ret), K(len), K(val->value())); K(ret), K(len), K(val->value()));

View File

@ -628,9 +628,6 @@ int ObJsonObject::add(const common::ObString &key, ObJsonNode *value)
if (OB_ISNULL(value)) { // check param if (OB_ISNULL(value)) { // check param
ret = OB_INVALID_ARGUMENT; ret = OB_INVALID_ARGUMENT;
LOG_WARN("param value is NULL", K(ret)); LOG_WARN("param value is NULL", K(ret));
} else if (key.empty()) {
ret = OB_ERR_JSON_DOCUMENT_NULL_KEY;
LOG_WARN("key is NULL", K(ret));
} else { } else {
value->set_parent(this); value->set_parent(this);
ObJsonObjectPair pair(key, value); ObJsonObjectPair pair(key, value);

View File

@ -262,7 +262,7 @@ int ObExprJsonSearch::eval_json_search(const ObExpr &expr, ObEvalCtx &ctx, ObDat
} }
// check one_or_all flag // check one_or_all flag
bool one_flag; bool one_flag = false;
if (OB_SUCC(ret) && !is_null) { if (OB_SUCC(ret) && !is_null) {
json_arg = expr.args_[1]; json_arg = expr.args_[1];
val_type = json_arg->datum_meta_.type_; val_type = json_arg->datum_meta_.type_;

View File

@ -1151,7 +1151,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
case ObMediumIntType: case ObMediumIntType:
case ObInt32Type: case ObInt32Type:
case ObIntType: { case ObIntType: {
int64_t val; int64_t val = 0;
ret = cast_to_int(j_base, dst_type, val); ret = cast_to_int(j_base, dst_type, val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "SIGNED")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "SIGNED")) {
res.set_int(val); res.set_int(val);
@ -1163,7 +1163,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
case ObUMediumIntType: case ObUMediumIntType:
case ObUInt32Type: case ObUInt32Type:
case ObUInt64Type: { case ObUInt64Type: {
uint64_t val; uint64_t val = 0;
ret = cast_to_uint(j_base, dst_type, val); ret = cast_to_uint(j_base, dst_type, val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "UNSIGNED")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "UNSIGNED")) {
res.set_uint(val); res.set_uint(val);
@ -1171,7 +1171,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
break; break;
} }
case ObDateTimeType: { case ObDateTimeType: {
int64_t val; int64_t val = 0;
ret = cast_to_datetime(j_base, accuracy, val); ret = cast_to_datetime(j_base, accuracy, val);
if (ret == OB_ERR_NULL_VALUE) { if (ret == OB_ERR_NULL_VALUE) {
res.set_null(); res.set_null();
@ -1192,7 +1192,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
break; break;
} }
case ObDateType: { case ObDateType: {
int32_t val; int32_t val = 0;
ret = cast_to_date(j_base, val); ret = cast_to_date(j_base, val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "DATE")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "DATE")) {
res.set_date(val); res.set_date(val);
@ -1200,7 +1200,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
break; break;
} }
case ObTimeType: { case ObTimeType: {
int64_t val; int64_t val = 0;
ret = cast_to_time(j_base, accuracy, val); ret = cast_to_time(j_base, accuracy, val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "TIME")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "TIME")) {
res.set_time(val); res.set_time(val);
@ -1208,7 +1208,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
break; break;
} }
case ObYearType: { case ObYearType: {
uint8_t val; uint8_t val = 0;
ret = cast_to_year(j_base, val); ret = cast_to_year(j_base, val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "YEAR")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "YEAR")) {
res.set_year(val); res.set_year(val);
@ -1217,7 +1217,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
} }
case ObFloatType: case ObFloatType:
case ObUFloatType: { case ObUFloatType: {
float out_val; float out_val = 0;
ret = cast_to_float(j_base, dst_type, out_val); ret = cast_to_float(j_base, dst_type, out_val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "FLOAT")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "FLOAT")) {
res.set_float(out_val); res.set_float(out_val);
@ -1226,7 +1226,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
} }
case ObDoubleType: case ObDoubleType:
case ObUDoubleType: { case ObUDoubleType: {
double out_val; double out_val = 0;
ret = cast_to_double(j_base, dst_type, out_val); ret = cast_to_double(j_base, dst_type, out_val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "DOUBLE")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "DOUBLE")) {
res.set_double(out_val); res.set_double(out_val);
@ -1268,7 +1268,7 @@ int ObExprJsonValue::cast_to_res(common::ObIAllocator *allocator,
break; break;
} }
case ObBitType: { case ObBitType: {
uint64_t out_val; uint64_t out_val = 0;
ret = cast_to_bit(j_base, out_val); ret = cast_to_bit(j_base, out_val);
if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "BIT")) { if (!try_set_error_val<ObDatum>(res, ret, error_type, error_val, "BIT")) {
res.set_bit(out_val); res.set_bit(out_val);