From e2b88f2628320e930333048e1b179624e6b4a012 Mon Sep 17 00:00:00 2001 From: haohao022 Date: Fri, 24 May 2024 05:56:54 +0000 Subject: [PATCH] [CP] [to #56964541] change error code for complex type print Co-authored-by: LiuYoung00 --- src/observer/mysql/obmp_base.cpp | 2 +- src/observer/mysql/obmp_base.h | 2 +- src/observer/mysql/obmp_stmt_fetch.cpp | 26 ++++++++++----------- src/observer/mysql/obmp_stmt_fetch.h | 6 ++--- src/observer/mysql/obmp_stmt_prexecute.cpp | 9 +++++--- src/share/object/ob_obj_cast.cpp | 6 ++--- src/sql/ob_sql.cpp | 27 +++++++++++++++++++++- 7 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/observer/mysql/obmp_base.cpp b/src/observer/mysql/obmp_base.cpp index 07fca0e0b7..3ac0e7a035 100644 --- a/src/observer/mysql/obmp_base.cpp +++ b/src/observer/mysql/obmp_base.cpp @@ -598,7 +598,7 @@ int ObMPBase::response_row(ObSQLSessionInfo &session, if (OB_SUCC(ret)) { const ObDataTypeCastParams dtc_params = ObBasicSessionInfo::create_dtc_params(&session); - ObSMRow sm_row(obmysql::BINARY, tmp_row, dtc_params, fields, schema_guard); + ObSMRow sm_row(obmysql::BINARY, tmp_row, dtc_params, fields, schema_guard, session.get_effective_tenant_id()); sm_row.set_packed(is_packed); obmysql::OMPKRow rp(sm_row); rp.set_is_packed(is_packed); diff --git a/src/observer/mysql/obmp_base.h b/src/observer/mysql/obmp_base.h index 0ae2c970be..1f5de83dfe 100644 --- a/src/observer/mysql/obmp_base.h +++ b/src/observer/mysql/obmp_base.h @@ -128,7 +128,7 @@ protected: const ColumnsFieldIArray *fields, bool is_packed, sql::ObExecContext *exec_ctx = NULL, - bool is_ps_protocol = false, + bool is_ps_protocol = true, ObSchemaGetterGuard *schema_guard = NULL); int process_extra_info(sql::ObSQLSessionInfo &session, const obmysql::ObMySQLRawPacket &pkt, bool &need_response_error); diff --git a/src/observer/mysql/obmp_stmt_fetch.cpp b/src/observer/mysql/obmp_stmt_fetch.cpp index 5586ecdca4..db43765c6e 100644 --- a/src/observer/mysql/obmp_stmt_fetch.cpp +++ b/src/observer/mysql/obmp_stmt_fetch.cpp @@ -323,6 +323,7 @@ int ObMPStmtFetch::response_result(pl::ObPLCursorInfo &cursor, int64_t cur = 0; const ColumnsFieldArray *fields = NULL; ObArenaAllocator allocator(ObModIds::OB_SQL_EXECUTOR); + ObSchemaGetterGuard schema_guard; SMART_VAR(ObExecContext, tmp_exec_ctx, allocator) { if (cursor.is_streaming()) { CK (OB_NOT_NULL(cursor.get_cursor_handler())); @@ -460,12 +461,16 @@ int ObMPStmtFetch::response_result(pl::ObPLCursorInfo &cursor, } } } - if (OB_SUCC(ret) && !need_fetch && NULL != row) { + if (OB_FAIL(ret)) { + // do nothing + } else if (OB_FAIL(gctx_.schema_service_->get_tenant_schema_guard(session.get_effective_tenant_id(), schema_guard))) { + LOG_WARN("get tenant schema guard failed ", K(ret), K(session.get_effective_tenant_id())); + } else if (!need_fetch && NULL != row) { if (has_long_data()) { OZ (response_row(session, *(const_cast(row)), - fields, column_flag_, cursor_id_, true, cursor.is_packed())); + fields, column_flag_, cursor_id_, true, cursor.is_packed(), &schema_guard)); } else { - OZ (response_row(session, *(const_cast(row)), fields, cursor.is_packed())); + OZ (response_row(session, *(const_cast(row)), fields, cursor.is_packed(), NULL, &schema_guard)); } if (OB_FAIL(ret)) { LOG_WARN("response row fail.", K(ret)); @@ -473,12 +478,6 @@ int ObMPStmtFetch::response_result(pl::ObPLCursorInfo &cursor, } ObPLExecCtx pl_ctx(cursor.get_allocator(), exec_ctx, ¶ms, NULL/*result*/, &ret, NULL/*func*/, true); - ObSchemaGetterGuard schema_guard; - if (OB_SUCC(ret) && need_fetch) { - if (OB_FAIL(gctx_.schema_service_->get_tenant_schema_guard(session.get_effective_tenant_id(), schema_guard))) { - LOG_WARN("get tenant schema guard failed ", K(ret), K(session.get_effective_tenant_id())); - } - } while (OB_SUCC(ret) && need_fetch && row_num < fetch_limit && OB_SUCC(sql::ObSPIService::dbms_cursor_fetch(&pl_ctx, static_cast(cursor)))) { @@ -496,9 +495,9 @@ int ObMPStmtFetch::response_result(pl::ObPLCursorInfo &cursor, cursor.set_current_position(cur); if (has_long_data()) { OZ (response_row(session, row, fields, column_flag_, cursor_id_, - 0 == row_num ? true : false, cursor.is_packed())); + 0 == row_num ? true : false, cursor.is_packed(), &schema_guard)); } else { - OZ (response_row(session, row, fields, cursor.is_packed(), exec_ctx, cursor.is_ps_cursor(), &schema_guard)); + OZ (response_row(session, row, fields, cursor.is_packed(), exec_ctx, &schema_guard)); } if (OB_SUCC(ret)) { ++row_num; @@ -782,7 +781,8 @@ int ObMPStmtFetch::response_row(ObSQLSessionInfo &session, char *column_map, int32_t stmt_id, bool first_time, - bool is_packed) + bool is_packed, + ObSchemaGetterGuard *schema_guard) { int ret = OB_SUCCESS; common::ObNewRow row; @@ -880,7 +880,7 @@ int ObMPStmtFetch::response_row(ObSQLSessionInfo &session, if (OB_FAIL(ret)) { // do nothing - } else if (OB_FAIL(response_row(session, row, fields, is_packed))) { + } else if (OB_FAIL(response_row(session, row, fields, is_packed, NULL, schema_guard))) { LOG_WARN("response row fail.", K(ret), K(stmt_id)); } else { LOG_DEBUG("response row success.", K(stmt_id)); diff --git a/src/observer/mysql/obmp_stmt_fetch.h b/src/observer/mysql/obmp_stmt_fetch.h index f7d3283a4e..e761887707 100644 --- a/src/observer/mysql/obmp_stmt_fetch.h +++ b/src/observer/mysql/obmp_stmt_fetch.h @@ -61,15 +61,15 @@ public: char *column_map, int32_t stmt_id, bool first_time, - bool is_packed); + bool is_packed, + ObSchemaGetterGuard *schema_guard); int response_row(sql::ObSQLSessionInfo &session, common::ObNewRow &row, const ColumnsFieldArray *fields, bool is_packed, sql::ObExecContext *exec_ctx = NULL, - bool is_ps_protocol = false, ObSchemaGetterGuard *schema_guard = NULL) { - return ObMPBase::response_row(session, row, fields, is_packed, exec_ctx, is_ps_protocol, schema_guard); + return ObMPBase::response_row(session, row, fields, is_packed, exec_ctx, true, schema_guard); } bool need_close_cursor() { return need_close_cursor_; } void set_close_cursor() { need_close_cursor_ = true; } diff --git a/src/observer/mysql/obmp_stmt_prexecute.cpp b/src/observer/mysql/obmp_stmt_prexecute.cpp index 8364df2aff..1553d771cc 100644 --- a/src/observer/mysql/obmp_stmt_prexecute.cpp +++ b/src/observer/mysql/obmp_stmt_prexecute.cpp @@ -516,6 +516,7 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, bool last_row = false; bool ac = true; int8_t has_result = 0; + ObSchemaGetterGuard schema_guard; if (0 != iteration_count_ && cursor->get_field_columns().count() > 0) { has_result = 1; LOG_DEBUG("has result set.", K(stmt_id_)); @@ -525,6 +526,8 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, } else if (OB_FAIL(response_param_query_header(session, &cursor->get_field_columns(), get_params(), stmt_id_, has_result, 0))) { LOG_WARN("send header packet faild.", K(ret)); + } else if (OB_FAIL(gctx_.schema_service_->get_tenant_schema_guard(session.get_effective_tenant_id(), schema_guard))) { + LOG_WARN("get tenant schema guard failed ", K(ret), K(session.get_effective_tenant_id())); } if (-1 == cursor->get_current_position() && iteration_count_ > 0) { // execute 如果返回数据,需要更新一下cursor的指针位置 @@ -543,7 +546,7 @@ int ObMPStmtPrexecute::execute_response(ObSQLSessionInfo &session, ++cur; cursor->set_current_position(cur); is_fetched = true; - if (OB_FAIL(response_row(session, row, &cursor->get_field_columns(), cursor->is_packed()))) { + if (OB_FAIL(response_row(session, row, &cursor->get_field_columns(), cursor->is_packed(), &result.get_exec_context(), true, &schema_guard))) { LOG_WARN("response row fail at line: ", K(ret), K(row_num)); } else { ++row_num; @@ -1051,7 +1054,7 @@ int ObMPStmtPrexecute::response_returning_rows(ObSQLSessionInfo &session, arraybinding_row_->get_cell(i+2) = value; } arraybinding_row_->get_cell(arraybinding_row_->get_count() - 1).set_null(); - if (OB_SUCCESS != (response_ret = response_row(session, *arraybinding_row_, arraybinding_columns_, is_packed))) { + if (OB_SUCCESS != (response_ret = response_row(session, *arraybinding_row_, arraybinding_columns_, is_packed, &result.get_exec_context()))) { LOG_WARN("fail to response row to client", K(response_ret)); } } @@ -1070,7 +1073,7 @@ int ObMPStmtPrexecute::response_returning_rows(ObSQLSessionInfo &session, } arraybinding_row_->get_cell(arraybinding_row_->get_count() - 1).set_varchar(ob_oracle_strerror(ret)); LOG_DEBUG("error occured before send arraybinding_row_", KPC(arraybinding_row_)); - if (OB_SUCCESS != (response_ret = response_row(session, *arraybinding_row_, arraybinding_columns_, false))) { + if (OB_SUCCESS != (response_ret = response_row(session, *arraybinding_row_, arraybinding_columns_, false, &result.get_exec_context()))) { LOG_WARN("fail to response row to client", K(response_ret)); } if (is_save_exception_) { diff --git a/src/share/object/ob_obj_cast.cpp b/src/share/object/ob_obj_cast.cpp index 8baf4384ba..c6d0473387 100644 --- a/src/share/object/ob_obj_cast.cpp +++ b/src/share/object/ob_obj_cast.cpp @@ -9643,15 +9643,15 @@ static int pl_extend_string(const ObObjType expect_type, ObObjCastParams ¶ms // then call this directly: select replace(xml_data,xml_data2 ,'1') into stringval from dual; out.set_null(); } else { - ret = OB_ERR_UNEXPECTED; + ret = OB_NOT_SUPPORTED; LOG_WARN("not expected obj type convert", K(ret), K(expect_type), K(in), K(out), K(cast_mode)); } } else { - ret = OB_ERR_UNEXPECTED; + ret = OB_NOT_SUPPORTED; LOG_WARN("not expected obj type convert", K(ret), K(expect_type), K(in), K(out), K(cast_mode)); } } else { - ret = OB_ERR_UNEXPECTED; + ret = OB_NOT_SUPPORTED; LOG_WARN("Unexpected type to convert format", K(ret), K(expect_type), K(in)); } #else diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index cc9cab7dda..97f8225b99 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -785,7 +785,7 @@ int ObSql::fill_select_result_set(ObResultSet &result_set, ObSqlCtx *context, co field.type_.set_collation_level(expr->get_collation_level()); } // Setup Scale - if (ObVarcharType == field.type_.get_type() || is_ext_field) { + if (ObVarcharType == field.type_.get_type()) { field.type_.set_varchar(type_name); } else if (ObNumberType == field.type_.get_type()) { field.type_.set_number(number); @@ -829,6 +829,31 @@ int ObSql::fill_select_result_set(ObResultSet &result_set, ObSqlCtx *context, co LOG_WARN("fail to alloc string", K(i), K(field), K(ret)); } } + } else if ((PC_PS_MODE == mode || PC_PL_MODE == mode) && expr->get_result_type().is_ext() + && OB_INVALID_ID != expr->get_result_type().get_udt_id() + && (PL_VARRAY_TYPE == expr->get_result_type().get_extend_type() + || PL_NESTED_TABLE_TYPE == expr->get_result_type().get_extend_type() + || PL_ASSOCIATIVE_ARRAY_TYPE == expr->get_result_type().get_extend_type() + || PL_RECORD_TYPE == expr->get_result_type().get_extend_type())) { + // pl udt type, need set field_name to deserialize + const ObUDTTypeInfo *udt_info = NULL; + const ObSimpleDatabaseSchema *db_schema = NULL; + uint64_t udt_id = expr->get_result_type().get_udt_id(); + const uint64_t tenant_id = get_tenant_id_by_object_id(udt_id); + if (OB_FAIL(context->schema_guard_->get_udt_info(tenant_id, udt_id, udt_info))) { + LOG_WARN("fail to get udt info. ", K(tenant_id), K(udt_id), K(ret)); + } else if (NULL == udt_info) { + LOG_WARN("udt is invalid. ", K(tenant_id), K(udt_id), K(udt_info), K(ret)); + } else if (OB_FAIL(context->schema_guard_->get_database_schema(tenant_id, udt_info->get_database_id(), db_schema))) { + LOG_WARN("get database info fail. ", K(tenant_id), K(udt_info->get_database_id()), K(ret)); + } else if (NULL == db_schema) { + LOG_WARN("database is invalid. ", K(tenant_id), K(udt_id), K(udt_info->get_database_id()), K(ret)); + } else if (OB_FAIL(ob_write_string(alloc, udt_info->get_type_name(), field.type_name_))) { + LOG_WARN("fail to alloc string", K(udt_info->get_type_name()), K(ret)); + } else if (OB_FAIL(ob_write_string(alloc, db_schema->get_database_name_str(), field.type_owner_))) { + LOG_WARN("fail to alloc string", K(db_schema->get_database_name_str()), K(ret)); + } + } else if (!expr->get_result_type().is_ext() && OB_FAIL(expr->get_length_for_meta_in_bytes(field.length_))) { LOG_WARN("get length failed", K(ret), KPC(expr)); }