init push
This commit is contained in:
89
src/sql/engine/expr/ob_expr_effective_tenant.cpp
Normal file
89
src/sql/engine/expr/ob_expr_effective_tenant.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2021 OceanBase
|
||||
* OceanBase CE is licensed under Mulan PubL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PubL v2.
|
||||
* You may obtain a copy of Mulan PubL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPubL-2.0
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PubL v2 for more details.
|
||||
*/
|
||||
|
||||
#define USING_LOG_PREFIX SQL_ENG
|
||||
#include "sql/engine/expr/ob_expr_effective_tenant.h"
|
||||
#include "sql/engine/ob_physical_plan_ctx.h"
|
||||
#include "lib/mysqlclient/ob_mysql_result.h"
|
||||
#include "lib/mysqlclient/ob_mysql_transaction.h"
|
||||
#include "lib/string/ob_sql_string.h"
|
||||
#include "lib/mysqlclient/ob_mysql_proxy.h"
|
||||
#include "lib/oblog/ob_log_module.h"
|
||||
#include "sql/session/ob_sql_session_info.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
using namespace oceanbase::common;
|
||||
using namespace oceanbase::sql;
|
||||
|
||||
namespace oceanbase {
|
||||
namespace sql {
|
||||
|
||||
ObExprEffectiveTenant::ObExprEffectiveTenant(ObIAllocator& alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_EFFECTIVE_TENANT, N_EFFECTIVE_TENANT, 0, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
|
||||
ObExprEffectiveTenant::~ObExprEffectiveTenant()
|
||||
{}
|
||||
|
||||
int ObExprEffectiveTenant::calc_result_type0(ObExprResType& type, ObExprTypeCtx& type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
type.set_varchar();
|
||||
type.set_length(OB_MAX_TENANT_NAME_LENGTH);
|
||||
type.set_default_collation_type();
|
||||
type.set_collation_level(CS_LEVEL_SYSCONST);
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
int ObExprEffectiveTenant::calc_result0(ObObj& result, ObExprCtx& expr_ctx) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObSQLSessionInfo* session_info = NULL;
|
||||
if (OB_ISNULL(session_info = expr_ctx.my_session_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session info is null", K(ret));
|
||||
} else {
|
||||
const ObString effective_tenant_name = session_info->get_effective_tenant_name();
|
||||
if (effective_tenant_name.empty()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("effective tenant name is empty", K(ret));
|
||||
} else {
|
||||
result.set_varchar(effective_tenant_name);
|
||||
result.set_collation(result_type_);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprEffectiveTenant::eval_effective_tenant(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& expr_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(expr);
|
||||
const ObBasicSessionInfo* session_info = NULL;
|
||||
if (OB_ISNULL(session_info = ctx.exec_ctx_.get_my_session())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("session info is null", K(ret));
|
||||
} else {
|
||||
expr_datum.set_string(session_info->get_effective_tenant_name());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprEffectiveTenant::cg_expr(ObExprCGCtx& op_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
{
|
||||
UNUSED(raw_expr);
|
||||
UNUSED(op_cg_ctx);
|
||||
rt_expr.eval_func_ = ObExprEffectiveTenant::eval_effective_tenant;
|
||||
return OB_SUCCESS;
|
||||
}
|
||||
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
Reference in New Issue
Block a user