From 258affd57cb3b51e8cf19cec7115b864c6040a8d Mon Sep 17 00:00:00 2001 From: 2149 <260391947@qq.com> Date: Wed, 2 Aug 2023 05:48:31 +0000 Subject: [PATCH] Fix convert/to_type and get_ddl compatibility bugs --- src/share/schema/ob_schema_printer.cpp | 6 ++++ src/sql/engine/expr/ob_expr_convert.cpp | 29 ++++++++++++++++++- src/sql/engine/expr/ob_expr_to_blob.cpp | 9 +++--- src/sql/engine/expr/ob_expr_to_clob.cpp | 5 ++-- src/sql/engine/expr/ob_expr_to_number.cpp | 22 ++++++++++---- .../engine/expr/ob_expr_to_temporal_base.cpp | 4 +++ 6 files changed, 61 insertions(+), 14 deletions(-) diff --git a/src/share/schema/ob_schema_printer.cpp b/src/share/schema/ob_schema_printer.cpp index fd3a895727..0f04ecf93f 100644 --- a/src/share/schema/ob_schema_printer.cpp +++ b/src/share/schema/ob_schema_printer.cpp @@ -2128,6 +2128,12 @@ int ObSchemaPrinter::print_table_definition_table_options( OB_LOG(WARN, "fail to print global/local", K(ret), K(table_schema)); } } + if (OB_SUCC(ret) && !strict_compat_ + && is_index_tbl && is_oracle_mode && !table_schema.is_index_visible()) { + if (OB_FAIL(databuff_printf(buf, buf_len, pos, "INVISIBLE"))) { + OB_LOG(WARN, "fail to print invisible option", K(ret), K(table_schema)); + } + } if (OB_SUCC(ret) && !strict_compat_ && !is_index_tbl) { if (OB_FAIL(databuff_printf(buf, buf_len, pos, "USE_BLOOM_FILTER = %s ", table_schema.is_use_bloomfilter() ? "TRUE" : "FALSE"))) { diff --git a/src/sql/engine/expr/ob_expr_convert.cpp b/src/sql/engine/expr/ob_expr_convert.cpp index 6b8281d923..6444ba041b 100644 --- a/src/sql/engine/expr/ob_expr_convert.cpp +++ b/src/sql/engine/expr/ob_expr_convert.cpp @@ -84,7 +84,34 @@ int calc_convert_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum) if (OB_FAIL(expr.args_[0]->eval(ctx, child_res))) { LOG_WARN("eval arg 0 failed", K(ret)); } else { - res_datum.set_datum(*child_res); + ObCollationType cs_type = expr.args_[0]->datum_meta_.cs_type_; + int64_t mbmaxlen = 1; + if (OB_FAIL(ObCharset::get_mbmaxlen_by_coll(cs_type, mbmaxlen))) { + LOG_WARN("fail to get mbmaxlen", K(cs_type), K(ret)); + } else if (mbmaxlen > 1 && !child_res->is_null()) { + ObString checked_res; + bool is_null = false; + const ObSQLSessionInfo *session = ctx.exec_ctx_.get_my_session(); + if (OB_ISNULL(session)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("session is null", K(ret)); + } else if (OB_FAIL(ObSQLUtils::check_well_formed_str(child_res->get_string(), + cs_type, + checked_res, + is_null, + is_strict_mode(session->get_sql_mode()), + false))) { + LOG_WARN("check_well_formed_str failed", K(ret), + K(child_res->get_string()), + K(expr.datum_meta_)); + } else if (is_null) { + res_datum.set_null(); + } else { + res_datum.set_string(checked_res); + } + } else { + res_datum.set_datum(*child_res); + } } return ret; } diff --git a/src/sql/engine/expr/ob_expr_to_blob.cpp b/src/sql/engine/expr/ob_expr_to_blob.cpp index 5093de5d5e..6a7258ee93 100644 --- a/src/sql/engine/expr/ob_expr_to_blob.cpp +++ b/src/sql/engine/expr/ob_expr_to_blob.cpp @@ -40,11 +40,10 @@ int ObExprToBlob::calc_result_type1(ObExprResType &type, UNUSED(type_ctx); int ret = OB_SUCCESS; - if (ob_is_null(text.get_type())) { - type.set_null(); - } else if (ob_is_blob(text.get_type(), text.get_collation_type()) - || ob_is_raw(text.get_type()) - || ob_is_string_tc(text.get_type())) { + if (ob_is_null(text.get_type()) + || ob_is_blob(text.get_type(), text.get_collation_type()) + || ob_is_raw(text.get_type()) + || ob_is_string_tc(text.get_type())) { type.set_blob(); type.set_collation_type(CS_TYPE_BINARY); if (ob_is_string_tc(text.get_type())) { diff --git a/src/sql/engine/expr/ob_expr_to_clob.cpp b/src/sql/engine/expr/ob_expr_to_clob.cpp index a619cfd7cd..3bc526f16c 100644 --- a/src/sql/engine/expr/ob_expr_to_clob.cpp +++ b/src/sql/engine/expr/ob_expr_to_clob.cpp @@ -44,9 +44,8 @@ int ObExprToClob::calc_result_type1(ObExprResType &type, if (OB_ISNULL(type_ctx.get_session())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("session is NULL", K(ret)); - } else if (ob_is_null(text.get_type())) { - type.set_null(); - } else if (ob_is_string_tc(text.get_type()) + } else if (ob_is_null(text.get_type()) + || ob_is_string_tc(text.get_type()) || ob_is_clob(text.get_type(), text.get_collation_type()) || ob_is_raw(text.get_type()) || ob_is_numeric_type(text.get_type()) diff --git a/src/sql/engine/expr/ob_expr_to_number.cpp b/src/sql/engine/expr/ob_expr_to_number.cpp index 6f1876aa64..06ad3927e1 100644 --- a/src/sql/engine/expr/ob_expr_to_number.cpp +++ b/src/sql/engine/expr/ob_expr_to_number.cpp @@ -76,9 +76,13 @@ int ObExprToNumberBase::calc_result_typeN(ObExprResType &type, if (param_num == 3) { types[2].set_calc_type_default_varchar(); } - type.set_type(ObNumberType); - type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET); - type.set_precision(PRECISION_UNKNOWN_YET); + if (types[0].is_null()) { + type.set_null(); + } else { + type.set_type(ObNumberType); + type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET); + type.set_precision(PRECISION_UNKNOWN_YET); + } } } return ret; @@ -325,7 +329,11 @@ int ObExprToBinaryFloat::calc_result_typeN(ObExprResType &type, LOG_WARN("input type can not cast to binary_float", K(types[0].get_type()), K(ret)); } else { types[0].set_calc_type(ObFloatType); - type.set_type(ObFloatType); + if (types[0].is_null()) { + type.set_null(); + } else { + type.set_type(ObFloatType); + } } return ret; } @@ -388,7 +396,11 @@ int ObExprToBinaryDouble::calc_result_typeN(ObExprResType &type, LOG_WARN("input type can not cast to binary_double", K(types[0].get_type()), K(ret)); } else { types[0].set_calc_type(ObDoubleType); - type.set_type(ObDoubleType); + if (types[0].is_null()) { + type.set_null(); + } else { + type.set_type(ObDoubleType); + } } return ret; } diff --git a/src/sql/engine/expr/ob_expr_to_temporal_base.cpp b/src/sql/engine/expr/ob_expr_to_temporal_base.cpp index 05b7aa684a..bdac7c1456 100644 --- a/src/sql/engine/expr/ob_expr_to_temporal_base.cpp +++ b/src/sql/engine/expr/ob_expr_to_temporal_base.cpp @@ -244,6 +244,10 @@ int ObExprToTemporalBase::calc_result_typeN(ObExprResType &type, //result type if (OB_SUCC(ret)) { type.set_type(get_my_target_obj_type()); + if (ObDateTimeType == get_my_target_obj_type() && input_char.is_null()) { + //set to_date(null) to null type + type.set_null(); + } } //result scale if (OB_SUCC(ret)) {