提交 97badd00 编写于 作者: O obdev 提交者: wangyunlai.wyl

[CP] Json bugfix: json column length and create view with json

上级 811b5387
......@@ -542,6 +542,10 @@ int ObTableColumns::deduce_column_attributes(
if (OB_FAIL(set_null_and_default_according_binary_expr(select_stmt, expr, nullable, has_default))) {
LOG_WARN("fail to get null and default for binary expr", K(ret));
}
} else if (expr->is_json_expr() ||
(T_FUN_SYS_CAST == expr->get_expr_type() && ob_is_json(expr->get_result_type().get_type()))) {
nullable = true;
has_default = false;
} else {
// ObOpRawExpr, ObCaseOpRawExpr, ObAggFunRawExpr
for (int64_t i = 0; OB_SUCC(ret) && i < expr->get_param_count(); ++i) {
......
......@@ -51,6 +51,7 @@ int ObExprJsonArray::calc_result_typeN(ObExprResType& type,
} else {
// param_num >= 0
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
for (int64_t i = 0; i < param_num; i++) {
if (ob_is_string_type(types_stack[i].get_type())) {
if (types_stack[i].get_charset_type() != CHARSET_UTF8MB4) {
......
......@@ -50,6 +50,7 @@ int ObExprJsonArrayAppend::calc_result_typeN(ObExprResType& type,
LOG_USER_ERROR(OB_ERR_PARAM_SIZE, name.length(), name.ptr());
} else {
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
if (OB_FAIL(ObJsonExprHelper::is_valid_for_json(types_stack, 0, N_JSON_ARRAY_APPEND))) {
LOG_WARN("wrong type for json doc.", K(ret), K(types_stack[0].get_type()));
......
......@@ -48,6 +48,7 @@ int ObExprJsonArrayInsert::calc_result_typeN(ObExprResType& type, ObExprResType*
LOG_USER_ERROR(OB_ERR_PARAM_SIZE, name.length(), name.ptr());
} else {
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
if (OB_FAIL(ObJsonExprHelper::is_valid_for_json(types_stack, 0, N_JSON_ARRAY_INSERT))) {
LOG_WARN("wrong type for json doc.", K(ret), K(types_stack[0].get_type()));
......
......@@ -74,11 +74,8 @@ int ObExprJsonExtract::calc_result_typeN(ObExprResType& type,
}
if (OB_SUCC(ret)) {
if (is_null_result) {
type.set_null();
} else {
type.set_json();
}
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
}
}
return ret;
......
......@@ -51,6 +51,7 @@ int ObExprJsonInsert::calc_result_typeN(ObExprResType& type,
LOG_USER_ERROR(OB_ERR_PARAM_SIZE, name.length(), name.ptr());
} else {
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
if (OB_FAIL(ObJsonExprHelper::is_valid_for_json(types_stack, 0, N_JSON_INSERT))) {
LOG_WARN("wrong type for json doc.", K(ret), K(types_stack[0].get_type()));
......
......@@ -44,6 +44,7 @@ int ObExprJsonKeys::calc_result_typeN(ObExprResType& type,
} else {
// set result to json
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
// set type of json_doc
if (OB_FAIL(ObJsonExprHelper::is_valid_for_json(types_stack, 0, N_JSON_KEYS))) {
......
......@@ -44,6 +44,7 @@ int ObExprJsonMergePatch::calc_result_typeN(ObExprResType& type,
INIT_SUCC(ret);
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
for (int64_t i = 0; OB_SUCC(ret) && i < param_num; i++) {
if (OB_FAIL(ObJsonExprHelper::is_valid_for_json(types_stack, i, N_JSON_MERGE_PRESERVE))) {
LOG_WARN("wrong type for json doc.", K(ret), K(types_stack[i].get_type()));
......
......@@ -53,6 +53,7 @@ int ObExprJsonMergePreserve::calc_result_typeN(ObExprResType& type,
UNUSED(type_ctx);
INIT_SUCC(ret);
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
bool is_result_null = false;
for (int64_t i = 0; OB_SUCC(ret) && !is_result_null && i < param_num; i++) {
if (types_stack[0].get_type() == ObNullType) {
......
......@@ -45,6 +45,7 @@ int ObExprJsonObject::calc_result_typeN(ObExprResType& type,
LOG_USER_ERROR(OB_ERR_PARAM_SIZE, name.length(), name.ptr());
} else {
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
for (int64_t i = 0; OB_SUCC(ret) && i < param_num; i += 2) {
if ((types_stack[i].get_type() == ObNullType)) {
ret = OB_ERR_JSON_DOCUMENT_NULL_KEY;
......
......@@ -49,6 +49,7 @@ int ObExprJsonRemove::calc_result_typeN(ObExprResType& type,
}
}
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
return ret;
}
......
......@@ -55,6 +55,7 @@ int ObExprJsonReplace::calc_result_typeN(ObExprResType& type,
}
}
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
}
return ret;
}
......
......@@ -218,6 +218,7 @@ int ObExprJsonSearch::calc_result_typeN(ObExprResType& type,
LOG_WARN("invalid param number", K(ret), K(param_num));
} else {
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
// json doc
if (OB_FAIL(ObJsonExprHelper::is_valid_for_json(types_stack, 0, "json_search"))) {
......
......@@ -55,6 +55,7 @@ int ObExprJsonSet::calc_result_typeN(ObExprResType& type,
}
}
type.set_json();
type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
}
return ret;
}
......
......@@ -466,6 +466,11 @@ int ObRawExpr::postorder_replace(ObRawExprVisitor& visitor)
return ret;
}
bool ObRawExpr::is_json_expr() const
{
return (T_FUN_SYS_JSON_OBJECT <= get_expr_type() && get_expr_type() <= T_FUN_JSON_OBJECTAGG) ? true : false;
}
////////////////////////////////////////////////////////////////
ObRawExpr*& ObTerminalRawExpr::get_param_expr(int64_t index)
{
......
......@@ -1508,6 +1508,7 @@ public:
{
is_deterministic_ = is_deterministic;
}
bool is_json_expr() const;
VIRTUAL_TO_STRING_KV(N_ITEM_TYPE, type_, N_RESULT_TYPE, result_type_, N_EXPR_INFO, info_, N_REL_ID, rel_ids_,
K_(expr_level), K_(expr_levels), K_(enum_set_values), K_(is_explicited_reference), K_(ref_count),
K_(is_for_generated_column), K_(extra), K_(is_calculated));
......
......@@ -1074,6 +1074,7 @@ int ObRawExprDeduceType::visit(ObAggFunRawExpr& expr)
}
case T_FUN_JSON_ARRAYAGG: {
result_type.set_json();
result_type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
expr.set_result_type(result_type);
break;
}
......@@ -1095,6 +1096,7 @@ int ObRawExprDeduceType::visit(ObAggFunRawExpr& expr)
need_add_cast = true;
}
result_type.set_json();
result_type.set_length((ObAccuracy::DDL_DEFAULT_ACCURACY[ObJsonType]).get_length());
expr.set_result_type(result_type);
}
break;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册