[to #48896499] fix object construct with null parameter

This commit is contained in:
obdev
2023-04-07 08:11:21 +00:00
committed by ob-robot
parent 303ea8ea6f
commit 534c25f11f
2 changed files with 44 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include "pl/ob_pl.h"
#include "pl/ob_pl_user_type.h"
#include "sql/ob_spi.h"
#include "pl/ob_pl_resolver.h"
namespace oceanbase
{
@ -93,6 +94,42 @@ int ObExprObjectConstruct::cg_expr(ObExprCGCtx &op_cg_ctx,
return ret;
}
int ObExprObjectConstruct::newx(ObEvalCtx &ctx, ObObj &result, uint64_t udt_id)
{
int ret = OB_SUCCESS;
auto session = ctx.exec_ctx_.get_my_session();
auto &exec_ctx = ctx.exec_ctx_;
ObIAllocator &alloc = ctx.exec_ctx_.get_allocator();
pl::ObPLPackageGuard package_guard(session->get_effective_tenant_id());
pl::ObPLResolveCtx resolve_ctx(alloc,
*session,
*(exec_ctx.get_sql_ctx()->schema_guard_),
package_guard,
*(exec_ctx.get_sql_proxy()),
false);
pl::ObPLINS *ns = NULL;
if (NULL == session->get_pl_context()) {
OZ (package_guard.init());
OX (ns = &resolve_ctx);
} else {
ns = session->get_pl_context()->get_current_ctx();
}
if (OB_SUCC(ret)) {
ObObj new_composite;
int64_t ptr = 0;
int64_t init_size = OB_INVALID_SIZE;
ObArenaAllocator tmp_alloc;
const pl::ObUserDefinedType *user_type = NULL;
OZ (ns->get_user_type(udt_id, user_type, &tmp_alloc));
CK (OB_NOT_NULL(user_type));
OZ (user_type->newx(alloc, ns, ptr));
OZ (user_type->get_size(*ns, pl::PL_TYPE_INIT_SIZE, init_size));
OX (new_composite.set_extend(ptr, user_type->get_type(), init_size));
OX (result = new_composite);
}
return ret;
}
int ObExprObjectConstruct::eval_object_construct(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res)
{
int ret = OB_SUCCESS;
@ -128,7 +165,11 @@ int ObExprObjectConstruct::eval_object_construct(const ObExpr &expr, ObEvalCtx &
} else {
new(record)pl::ObPLRecord(info->udt_id_, expr.arg_cnt_);
for (int64_t i = 0; i < expr.arg_cnt_; ++i) {
record->get_element()[i] = objs[i];
if (objs[i].is_null() && info->elem_types_.at(i).is_ext()) {
OZ (newx(ctx, record->get_element()[i], info->elem_types_.at(i).get_udt_id()));
} else {
OX (record->get_element()[i] = objs[i]);
}
if (OB_SUCC(ret) &&
(ObCharType == info->elem_types_.at(i).get_type() || ObNCharType == info->elem_types_.at(i).get_type())) {
OZ (ObSPIService::spi_pad_char_or_varchar(session,

View File

@ -68,6 +68,8 @@ public:
int64_t param_num);
static int fill_obj_stack(const ObExpr &expr, ObEvalCtx &ctx, ObObj *objs);
static int newx(ObEvalCtx &ctx, ObObj &result, uint64_t udt_id);
virtual void reset() {
rowsize_ = 0;
udt_id_ = OB_INVALID_ID;