bugfix : json objectagg returning type affect by var in pl

This commit is contained in:
obdev
2023-02-16 04:17:46 +00:00
committed by ob-robot
parent d820b79c29
commit 61a17a9abc
4 changed files with 13 additions and 6 deletions

View File

@ -1237,9 +1237,11 @@ int ObRawExprDeduceType::set_json_agg_result_type(ObAggFunRawExpr &expr, ObExprR
} else {
ParseNode parse_node;
parse_node.value_ = static_cast<ObConstRawExpr *>(return_type_expr)->get_value().get_int();
ObScale scale = static_cast<ObConstRawExpr *>(return_type_expr)->get_accuracy().get_scale();
bool is_json_type = (scale == 1) && (col_type.get_type_class() == ObJsonTC);
ObObjType obj_type = static_cast<ObObjType>(parse_node.int16_values_[OB_NODE_CAST_TYPE_IDX]);
result_type.set_collation_type(static_cast<ObCollationType>(parse_node.int16_values_[OB_NODE_CAST_COLL_IDX]));
if (ob_is_string_type(obj_type)) {
if (ob_is_string_type(obj_type) && !is_json_type) {
result_type.set_type(obj_type);
result_type.set_length(OB_MAX_SQL_LENGTH);
result_type.set_length_semantics(my_session_->get_actual_nls_length_semantics());
@ -1258,7 +1260,7 @@ int ObRawExprDeduceType::set_json_agg_result_type(ObAggFunRawExpr &expr, ObExprR
result_type.set_calc_collation_type(my_session_->get_nls_collation());
result_type.set_collation_level(CS_LEVEL_IMPLICIT);
expr.set_result_type(result_type);
} else if (ob_is_json(obj_type)) {
} else if (ob_is_json(obj_type) || is_json_type) {
result_type.set_json();
result_type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
} else if (ob_is_raw(obj_type)) {

View File

@ -1506,10 +1506,11 @@ int ObRawExprPrinter::print_json_return_type(ObRawExpr *expr)
{
INIT_SUCC(ret);
const int32_t DEFAULT_VARCHAR_LEN = 4000;
ObScale scale = static_cast<ObConstRawExpr *>(expr)->get_accuracy().get_scale();
if (OB_ISNULL(buf_) || OB_ISNULL(pos_) || OB_ISNULL(expr)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("stmt_ is NULL of buf_ is NULL or pos_ is NULL or expr is NULL", K(ret));
} else if (scale == 1) { // scale == 1 is default returning
} else if (ObRawExpr::EXPR_CONST != expr->get_expr_class()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("expr class should be EXPR_CONST ", K(ret), K(expr->get_expr_class()));

View File

@ -4022,11 +4022,15 @@ int ObRawExprResolverImpl::process_agg_node(const ParseNode *node, ObRawExpr *&e
} else if (T_FUN_ORA_JSON_OBJECTAGG == node->type_) {
for (int64_t i = 0; OB_SUCC(ret) && i < node->num_child_; ++i) {
sub_expr = NULL;
ObString def_val(7, "default");
if (OB_ISNULL(node->children_[i])) {
// do nothing
} else if (OB_FAIL(SMART_CALL(recursive_resolve(node->children_[i], sub_expr)))) {
LOG_WARN("fail to recursive resolve expr list item", K(ret));
} else if (OB_FAIL(agg_expr->add_real_param_expr(sub_expr))) {
} else if ((i == 4) && (0 == def_val.case_compare(node->children_[i]->raw_text_))) {
(static_cast<ObConstRawExpr *>(sub_expr))->set_scale(1);
}
if (OB_SUCC(ret) && OB_FAIL(agg_expr->add_real_param_expr(sub_expr))) {
LOG_WARN("fail to add param expr to agg expr", K(ret));
}
} // end for