[to #51258084] fix serval name resolve issues

This commit is contained in:
obdev 2023-08-07 11:18:15 +00:00 committed by ob-robot
parent 83f6c7e439
commit e6c7d6e585
8 changed files with 91 additions and 50 deletions

View File

@ -4503,7 +4503,7 @@ int ObPLCodeGenerator::generate_get_record_attr(const ObObjAccessIdx &current_ac
OX (record_type = static_cast<const ObRecordType*>(user_type));
OX (element_idx += record_type->get_record_member_count()); //null map
OX (element_idx += record_type->get_record_member_count()); //record meta list
CK (current_access.is_const());
OV (current_access.is_const(), OB_ERR_UNEXPECTED, K(current_access));
OX (element_idx += current_access.var_index_); //访问的域对应的下标
if (OB_SUCC(ret) && user_type->is_object_type() && for_write) {
ObLLVMBasicBlock null_block, not_null_block;
@ -4581,7 +4581,7 @@ int ObPLCodeGenerator::generate_get_attr(ObLLVMValue &param_array,
for_write,
value,
ret_value_ptr,
exit));
exit), K(obj_access), K(i));
} else {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected user type" , K(obj_access.at(i - 1).var_type_), K(ret));

View File

@ -1399,22 +1399,6 @@ int ObPLResolver::resolve_sp_composite_type(const ParseNode *sp_data_type_node,
ObArray<ObRawExpr*> params;
OZ (obj_access_idents.at(obj_access_idents.count() -1 ).extract_params(0, params));
} else {
// // 如果这个record是定义在package中,同时有默认值,那么需要把这个默认值表达式copy过来
// // 放到当前func的表达式列表中,后面进行default赋值的时候,可以使用。
// if (OB_SUCC(ret) && user_type->is_record_type()) {
// const ObRecordType *rec_type = static_cast<const ObRecordType *>(user_type);
// for (int64_t i = 0; OB_SUCC(ret) && i < rec_type->get_member_count(); ++i) {
// ObRecordMember *member = const_cast<ObRecordMember*>(rec_type->get_record_member(i));
// CK (OB_NOT_NULL(member));
// if (OB_SUCC(ret)) {
// if (OB_INVALID_INDEX != member->get_default()
// && OB_NOT_NULL(member->get_default_expr())) {
// OZ (func.add_expr(member->get_default_expr(), false));
// OX (member->set_default(func.get_expr_count() - 1));
// }
// }
// }
// }
OX (data_type = *user_type);
}
}
@ -1736,7 +1720,7 @@ int ObPLResolver::get_view_select_stmt(
}
int ObPLResolver::fill_record_type(
ObIAllocator &allocator, ObSelectStmt *select_stmt, ObRecordType *&record_type)
ObSchemaGetterGuard &schema_guard, ObIAllocator &allocator, ObSelectStmt *select_stmt, ObRecordType *&record_type)
{
int ret = OB_SUCCESS;
const SelectItem *select_item = NULL;
@ -1749,9 +1733,22 @@ int ObPLResolver::fill_record_type(
ObPLDataType pl_type;
CK (OB_NOT_NULL(select_item = &(select_stmt->get_select_item(i))));
CK (OB_NOT_NULL(expr = select_item->expr_));
OX (data_type.set_meta_type(expr->get_result_type()));
OX (data_type.set_accuracy(expr->get_result_type().get_accuracy()));
OX (pl_type.set_data_type(data_type));
if (OB_FAIL(ret)) {
} else if (expr->get_result_type().is_ext() || expr->get_result_type().is_user_defined_sql_type()) {
const ObUDTTypeInfo *udt_info = NULL;
const ObUserDefinedType *user_type = NULL;
ObArenaAllocator allocator;
uint64_t udt_id = expr->get_result_type().get_expr_udt_id();
uint64_t tenant_id = get_tenant_id_by_object_id(udt_id);
OZ (schema_guard.get_udt_info(tenant_id, udt_id, udt_info));
CK (OB_NOT_NULL(udt_info));
OZ (udt_info->transform_to_pl_type(allocator, user_type));
OX (pl_type = *user_type);
} else {
OX (data_type.set_meta_type(expr->get_result_type()));
OX (data_type.set_accuracy(expr->get_result_type().get_accuracy()));
OX (pl_type.set_data_type(data_type));
}
OZ (ob_write_string(allocator, select_item->alias_name_, copy_name));
OZ (record_type->add_record_member(copy_name, pl_type));
}
@ -1806,11 +1803,12 @@ int ObPLResolver::build_record_type_by_view_schema(const ObPLResolveCtx &ctx,
// OZ (get_view_select_stmt(resolve_ctx, view_schema, select_stmt));
CK (OB_NOT_NULL(real_stmt = select_stmt->get_real_stmt()));
CK (OB_NOT_NULL(record_type));
OZ (fill_record_type(ctx.allocator_, real_stmt, record_type));
OZ (fill_record_type(ctx.schema_guard_, ctx.allocator_, real_stmt, record_type));
return ret;
}
int ObPLResolver::build_record_type_by_table_schema(common::ObIAllocator &allocator,
int ObPLResolver::build_record_type_by_table_schema(ObSchemaGetterGuard &schema_guard,
common::ObIAllocator &allocator,
const ObTableSchema* table_schema,
ObRecordType *&record_type,
bool with_rowid)
@ -1824,20 +1822,32 @@ int ObPLResolver::build_record_type_by_table_schema(common::ObIAllocator &alloca
for (; OB_SUCC(ret) && cs_iter != cs_iter_end; cs_iter++) {
const ObColumnSchemaV2 &column_schema = **cs_iter;
if (!column_schema.is_hidden() && !(column_schema.is_invisible_column() && !with_rowid)) {
ObDataType data_type;
ObPLDataType pl_type;
data_type.set_meta_type(column_schema.get_meta_type());
data_type.set_accuracy(column_schema.get_accuracy());
if (data_type.get_meta_type().is_bit()) { // 对于bit类型, scale存储的是长度信息
data_type.meta_.set_scale(data_type.get_precision());
if (column_schema.get_meta_type().is_user_defined_sql_type()) {
const ObUDTTypeInfo *udt_info = NULL;
const ObUserDefinedType *user_type = NULL;
ObArenaAllocator allocator;
uint64_t tenant_id = get_tenant_id_by_object_id(column_schema.get_sub_data_type());
OZ (schema_guard.get_udt_info(tenant_id, column_schema.get_sub_data_type(), udt_info));
CK (OB_NOT_NULL(udt_info));
OZ (udt_info->transform_to_pl_type(allocator, user_type));
CK (OB_NOT_NULL(user_type));
OX (pl_type = *user_type);
} else {
data_type.meta_.set_scale(data_type.get_scale());
}
if (column_schema.is_enum_or_set()) {
OZ (pl_type.set_type_info(column_schema.get_extended_type_info()));
ObDataType data_type;
data_type.set_meta_type(column_schema.get_meta_type());
data_type.set_accuracy(column_schema.get_accuracy());
if (data_type.get_meta_type().is_bit()) { // 对于bit类型, scale存储的是长度信息
data_type.meta_.set_scale(data_type.get_precision());
} else {
data_type.meta_.set_scale(data_type.get_scale());
}
if (column_schema.is_enum_or_set()) {
OZ (pl_type.set_type_info(column_schema.get_extended_type_info()));
}
OX (pl_type.set_data_type(data_type));
}
if (OB_SUCC(ret)) {
pl_type.set_data_type(data_type);
char *name_buf = NULL;
ObString column_name = column_schema.get_column_name_str();
if (OB_ISNULL(name_buf =
@ -1905,7 +1915,7 @@ int ObPLResolver::build_record_type_by_schema(
resolve_ctx, table_schema, record_type));
} else {
OZ (build_record_type_by_table_schema(
resolve_ctx.allocator_, table_schema, record_type, with_rowid));
resolve_ctx.schema_guard_, resolve_ctx.allocator_, table_schema, record_type, with_rowid));
}
}
return ret;
@ -7207,7 +7217,7 @@ int ObPLResolver::resolve_fetch(
if (OB_SUCC(ret) && !is_compatible) {
ret = OB_ERR_TYPE_MISMATCH_IN_FETCH;
LOG_WARN("type not compatible", K(ret));
LOG_WARN("type not compatible", K(ret), KPC(left), KPC(right));
}
}
}
@ -8107,8 +8117,13 @@ int ObPLResolver::build_raw_expr(const ParseNode *node,
ret = OB_NOT_SUPPORTED;
LOG_WARN("agg expr in pl assign stmt not allowed", K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "agg expr in pl assign stmt");
} else if (sub_query_info.count() > 0 && lib::is_mysql_mode()) {
OZ (transform_subquery_expr(node, expr, expected_type, unit_ast));
} else if (sub_query_info.count() > 0) {
if (lib::is_mysql_mode()) {
OZ (transform_subquery_expr(node, expr, expected_type, unit_ast));
} else {
ret = OB_NOT_SUPPORTED;
LOG_USER_ERROR(OB_NOT_SUPPORTED, "use subquery in pl/sql expression");
}
} else {
OZ (resolve_columns(expr, columns, unit_ast));
}
@ -8417,7 +8432,11 @@ int ObPLResolver::resolve_expr(const ParseNode *node,
// 放在step是有问题,因为类似T_SP_CPARAM是没有对应的expr执行实体,需要展开. 没展开deduce就会出问题。
bool pl_sql_format_convert = false;
if (OB_SUCC(ret) && OB_NOT_NULL(expected_type)) {
if (ObNullType == expr->get_result_type().get_obj_meta().get_type()) {
if (T_OP_ROW == expr->get_expr_type()) {
ret = OB_ERR_EXPRESSION_WRONG_TYPE;
LOG_WARN("PLS-00382: expression is of wrong type",
K(ret), K(expected_type->is_obj_type()), KPC(expr));
} else if (ObNullType == expr->get_result_type().get_obj_meta().get_type()) {
// do nothing
} else if (expected_type->is_opaque_type()
&& expected_type->get_user_type_id() == static_cast<uint64_t>(T_OBJ_XML)
@ -11778,7 +11797,7 @@ int ObPLMockSelfArg::mock()
mocked_ = true;
mark_only_ = true;
} else if (access_idxs_.at(access_idxs_.count() - 1).elem_type_.is_composite_type()
&& expr_params_.at(0)->get_result_type().get_expr_udt_id()
&& expr_params_.at(0)->get_result_type().get_expr_udt_id()
== access_idxs_.at(access_idxs_.count() - 1).elem_type_.get_user_type_id()) {
ObConstRawExpr *null_expr = NULL;
OZ (expr_factory_.create_raw_expr(T_NULL, null_expr));

View File

@ -31,6 +31,7 @@
} while(0);
#endif
#ifndef NDEBUG
#ifndef SET_LOG_CHECK_MODE
#define SET_LOG_CHECK_MODE() \
bool set_check_mode = false; \
@ -53,6 +54,10 @@
CANCLE_OB_LOG_TRACE_MODE(); \
}
#endif // CANCLE_LOG_CHECK_MODE
#else
#define SET_LOG_CHECK_MODE()
#define CANCLE_LOG_CHECK_MODE()
#endif
namespace oceanbase {
using sql::ObObjAccessIdent;
@ -383,14 +388,17 @@ public:
const share::schema::ObTableSchema* view_schema,
sql::ObSelectStmt *&select_stmt);
static
int fill_record_type(
common::ObIAllocator &allocator, sql::ObSelectStmt *select_stmt, ObRecordType *&record_type);
int fill_record_type(share::schema::ObSchemaGetterGuard &schema_guard,
common::ObIAllocator &allocator,
sql::ObSelectStmt *select_stmt,
ObRecordType *&record_type);
static
int build_record_type_by_view_schema(const ObPLResolveCtx &resolve_ctx,
const share::schema::ObTableSchema* view_schema,
ObRecordType *&record_type);
static
int build_record_type_by_table_schema(common::ObIAllocator &allocator,
int build_record_type_by_table_schema(share::schema::ObSchemaGetterGuard &schema_guard,
common::ObIAllocator &allocator,
const share::schema::ObTableSchema* table_schema,
ObRecordType *&record_type,
bool with_rowid = false);

View File

@ -1784,8 +1784,7 @@ int ObPLExternalNS::resolve_external_symbol(const common::ObString &name,
OZ (add_dependency_object(obj_version));
}
OX (var_idx = i);
CK (OB_NOT_NULL(member_type->get_data_type()));
OX (data_type.set_data_type(*(member_type->get_data_type())));
OX (data_type = *member_type);
}
}
}

View File

@ -982,6 +982,8 @@ public:
virtual bool is_udt_map() const { return compile_flag_.compile_with_map(); }
virtual bool is_udt_order() const { return compile_flag_.compile_with_order(); }
virtual const ObString& get_routine_name() const { return get_name(); }
bool has_self_param() const;
int64_t get_self_param_pos() const;

View File

@ -1220,6 +1220,7 @@ ObObjAccessIdx::ObObjAccessIdx(const ObPLDataType &elem_type,
if (AccessType::IS_EXPR == access_type
|| AccessType::IS_UDF_NS == access_type) {
get_sysfunc_ = reinterpret_cast<sql::ObRawExpr *>(value);
var_index_ = var_type.get_user_type_id();
} else if (AccessType::IS_INTERNAL_PROC == access_type
|| AccessType::IS_EXTERNAL_PROC == access_type
|| AccessType::IS_NESTED_PROC == access_type) {

View File

@ -167,6 +167,8 @@ public:
virtual void set_has_sequence() = 0;
virtual void set_has_out_param() = 0;
virtual void set_external_state() = 0;
virtual int64_t get_param_start_idx() const { return 0; }
virtual const common::ObString &get_routine_name() const = 0;
TO_STRING_EMPTY();
};

View File

@ -863,7 +863,7 @@ int ObResolverUtils::get_type_and_type_id(
{
int ret = OB_SUCCESS;
CK (OB_NOT_NULL(expr));
OX (type_id = expr->get_result_type().get_udt_id());
OX (type_id = expr->get_result_type().get_expr_udt_id());
if (OB_FAIL(ret)) {
} else if (IS_BOOL_OP(expr->get_expr_type())) {
type = ObTinyIntType;
@ -897,7 +897,7 @@ int ObResolverUtils::check_match(const pl::ObPLResolveCtx &resolve_ctx,
}
int64_t offset = 0;
if(OB_SUCC(ret) && 0 < expr_params.count() && OB_NOT_NULL(expr_params.at(0))) {
if(OB_SUCC(ret) && expr_params.count() > 0 && OB_NOT_NULL(expr_params.at(0))) {
ObRawExpr *first_arg = expr_params.at(0);
if (first_arg->has_flag(IS_UDT_UDF_SELF_PARAM)) {
// do nothing, may be we can check if routine is static or not
@ -912,8 +912,7 @@ int ObResolverUtils::check_match(const pl::ObPLResolveCtx &resolve_ctx,
OX (offset = 1);
}
} else if (routine_info->is_udt_routine()
&& !routine_info->is_udt_static_routine()
&& expr_params.count() != routine_info->get_param_count()) {
&& !routine_info->is_udt_static_routine()) {
uint64_t src_type_id = OB_INVALID_ID;
ObObjType src_type;
if (T_SP_CPARAM == first_arg->get_expr_type()) {
@ -928,7 +927,18 @@ int ObResolverUtils::check_match(const pl::ObPLResolveCtx &resolve_ctx,
&& (src_type_id != routine_info->get_package_id())) {
// set first param matched
OX (match_info.match_info_.at(0) = (ObRoutineMatchInfo::MatchInfo(false, src_type, src_type)));
OX (offset = 1);
if ((expr_params.count() + 1) > routine_info->get_param_count()) {
ret = OB_ERR_SP_WRONG_ARG_NUM;
LOG_WARN("argument count not match",
K(ret),
K(expr_params.count()),
K(src_type_id),
KPC(first_arg),
K(routine_info->get_param_count()),
K(routine_info->get_routine_name()));
} else {
OX (offset = 1);
}
}
}
}