提交 a1f04865 编写于 作者: Y yy0 提交者: LINGuanRen

fix:40048757,40048854

上级 293e2ec4
......@@ -650,7 +650,7 @@ int ObJsonBin::serialize_json_value(ObJsonNode *json_tree, ObJsonBuffer &result)
case ObJsonNodeType::J_DOUBLE: {
const ObJsonDouble *d = static_cast<const ObJsonDouble*>(json_tree);
double value = d->value();
if (std::isnan(value) || std::isinf(value)) {
if (isnan(value) || isinf(value)) {
ret = OB_INVALID_NUMERIC;
LOG_WARN("invalid double value", K(ret), K(value));
} else if (OB_FAIL(result.append(reinterpret_cast<const char*>(&value), sizeof(double)))) {
......@@ -1783,7 +1783,7 @@ int ObJsonBin::move_parent_iter()
}
// inlined will reuse value entry offset which length is type_size
int ObJsonBin::set_curr_by_type(int64_t new_pos, uint64_t val_offset, uint8_t type)
int ObJsonBin::set_curr_by_type(int64_t new_pos, uint64_t val_offset, uint8_t type, uint8_t entry_size)
{
INIT_SUCC(ret);
char *ptr = curr_.ptr();
......@@ -1820,7 +1820,7 @@ int ObJsonBin::set_curr_by_type(int64_t new_pos, uint64_t val_offset, uint8_t ty
}
case ObJsonNodeType::J_INT: {
if (is_inlined) {
int_val_ = ObJsonVar::var_uint2int(val_offset);
int_val_ = ObJsonVar::var_uint2int(val_offset, entry_size);
bytes_ = 0;
} else {
int64_t val = 0;
......@@ -2141,7 +2141,7 @@ int ObJsonBin::get_element_in_array_v0(size_t index, char **get_addr_only)
} else {
pos_ = pos_ + val_offset;
}
if (OB_FAIL(set_curr_by_type(pos_, val_offset, val_type))) {
if (OB_FAIL(set_curr_by_type(pos_, val_offset, val_type, type))) {
LOG_WARN("failed to move iter to sub obj.", K(ret), K(index));
}
}
......@@ -2212,7 +2212,7 @@ int ObJsonBin::get_element_in_object_v0(size_t i, char **get_addr_only)
} else {
pos_ = pos_ + value_offset;
}
if (OB_FAIL(set_curr_by_type(pos_, value_offset, val_type))) {
if (OB_FAIL(set_curr_by_type(pos_, value_offset, val_type, type))) {
LOG_WARN("failed to move iter to sub obj.", K(ret), K(i));
}
}
......@@ -3685,12 +3685,21 @@ int ObJsonBin::rebuild_json_value(const char *data,
break;
}
case ObJsonNodeType::J_DECIMAL: {
ObPrecision prec = -1;
ObScale scale = -1;
number::ObNumber num;
int64_t pos = 0;
number::ObNumber temp_number;
if (OB_FAIL(temp_number.deserialize(data, length, pos))) {
LOG_WARN("failed to deserialize decimal data", K(ret));
if (OB_FAIL(serialization::decode_i16(data, length, pos, &prec))) {
LOG_WARN("fail to deserialize decimal precision.", K(ret), K(length));
} else if (OB_FAIL(serialization::decode_i16(data, length, pos, &scale))) {
LOG_WARN("fail to deserialize decimal scale.", K(ret), K(length), K(prec));
} else if (OB_FAIL(num.deserialize(data, length, pos))) {
LOG_WARN("fail to deserialize number.", K(ret), K(length));
} else {
ret = result.append(data, pos);
ObJsonDecimal decimal(num, prec, scale);
if (OB_FAIL(serialize_json_decimal(&decimal, result))) {
LOG_WARN("failed to seialize json decimal", K(ret));
}
}
break;
}
......@@ -4342,9 +4351,9 @@ uint64_t ObJsonVar::var_int2uint(int64_t var)
return val;
}
int64_t ObJsonVar::var_uint2int(uint64_t var)
int64_t ObJsonVar::var_uint2int(uint64_t var, uint8_t entry_size)
{
ObJsonBinLenSize size = static_cast<ObJsonBinLenSize>(ObJsonVar::get_var_type(var));
ObJsonBinLenSize size = static_cast<ObJsonBinLenSize>(max(ObJsonVar::get_var_type(var), entry_size));
int64_t val = 0;
switch (size) {
case JBLS_UINT8: {
......
......@@ -412,7 +412,7 @@ private:
int deserialize_json_array_v0(const char *data, uint64_t length, ObJsonArray *array);
inline int deserialize_json_array(const char *data, uint64_t length, ObJsonArray *array, ObJBVerType vertype);
int set_curr_by_type(int64_t new_pos, uint64_t val_offset, uint8_t type);
int set_curr_by_type(int64_t new_pos, uint64_t val_offset, uint8_t type, uint8_t entry_size = 0);
void parse_obj_header(const char *data, uint64_t &offset, uint8_t &node_type,
uint8_t &type, uint8_t& obj_size_type, uint64_t &count, uint64_t &obj_size) const;
......@@ -513,7 +513,7 @@ public:
static uint8_t get_var_type(uint64_t var);
static int read_var(const char *data, uint8_t type, int64_t *var);
static uint64_t var_int2uint(int64_t var);
static int64_t var_uint2int(uint64_t var);
static int64_t var_uint2int(uint64_t var, uint8_t entry_size = 0);
static uint8_t get_var_type(int64_t var);
};
......
此差异已折叠。
......@@ -101,7 +101,9 @@ CHECK_IS_TRUE_FUNC_NAME(other_type)
{
if (ob_is_json(expr.args_[0]->datum_meta_.type_)) {
int cmp_result = 0;
if (OB_FAIL(ObJsonExprHelper::is_json_zero(child_datum->get_string(), cmp_result))) {
if (child_datum->is_null()) {
res_datum.set_int32(1);;
} else if (OB_FAIL(ObJsonExprHelper::is_json_zero(child_datum->get_string(), cmp_result))) {
LOG_WARN("failed: compare json", K(ret));
} else {
res_datum.set_int32(cmp_result);
......
......@@ -97,6 +97,9 @@ int ObExprCase::calc_result_typeN(
types_stack[i].set_calc_meta(types_stack[i].get_obj_meta());
} else {
types_stack[i].set_calc_meta(type.get_obj_meta());
if (ob_is_json(types_stack[i].get_type())) {
types_stack[i].set_calc_collation_type(CS_TYPE_UTF8MB4_BIN);
}
}
}
}
......
......@@ -49,17 +49,21 @@ int ObExprOr::calc_result2(
bool obj1_is_true = false;
EXPR_SET_CAST_CTX_MODE(expr_ctx);
if (ob_is_json(obj1.get_type())) {
bool is_obj1_json = ob_is_json(obj1.get_type());
if (is_obj1_json) {
// cause for json type, in some case can't transform to number type
// add special process for json type
// use the some logical as mysql
int cmp_result = 0;
if (OB_FAIL(ObJsonExprHelper::is_json_zero(obj1.get_string(), cmp_result))) {
if (obj1.is_null()) {
} else if (OB_FAIL(ObJsonExprHelper::is_json_zero(obj1.get_string(), cmp_result))) {
LOG_WARN("failed: compare json", K(ret));
} else {
result.set_int32(cmp_result);
obj1_is_true = cmp_result != 0;
}
} else if (OB_FAIL(ObLogicalExprOperator::is_true(obj1, expr_ctx.cast_mode_ | CM_NO_RANGE_CHECK, obj1_is_true))) {
}
if (!is_obj1_json && OB_FAIL(ObLogicalExprOperator::is_true(obj1, expr_ctx.cast_mode_ | CM_NO_RANGE_CHECK, obj1_is_true))) {
LOG_WARN("fail to evaluate obj1", K(obj1), K(ret));
} else if (obj1_is_true) {
result.set_int32(static_cast<int32_t>(true));
......@@ -73,6 +77,18 @@ int ObExprOr::calc_result2(
} else {
// obj1 must be false here.
bool bool_v2 = false;
bool is_obj2_json = ob_is_json(obj2.get_type());
if (is_obj2_json) {
int cmp_result = 0;
if (obj1.is_null()) {
} else if (OB_FAIL(ObJsonExprHelper::is_json_zero(obj1.get_string(), cmp_result))) {
LOG_WARN("failed: compare json", K(ret));
} else {
bool_v2 = cmp_result != 0;
}
}
if (OB_FAIL(ObLogicalExprOperator::is_true(obj2, expr_ctx.cast_mode_ | CM_NO_RANGE_CHECK, bool_v2))) {
LOG_WARN("fail to evaluate obj2", K(obj2), K(ret));
} else {
......
......@@ -302,9 +302,11 @@ int ObRawExprDeduceType::calc_result_type(
if (ObLobType == type->get_type()) {
type->set_type(ObLongTextType);
}
// ToDo: test and fix, not all sql functions need calc json as long text
if (ObJsonType == type->get_type() && need_calc_json_as_text(expr.get_expr_type())) {
type->set_calc_type(ObLongTextType);
if (ObJsonType == type->get_type()) {
if (need_calc_json_as_text(expr.get_expr_type())) {
// ToDo: test and fix, not all sql functions need calc json as long text
type->set_calc_type(ObLongTextType);
}
}
}
op->set_row_dimension(row_dimension);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册