patch 4.0
This commit is contained in:
@ -18,18 +18,24 @@
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
#include "lib/timezone/ob_time_convert.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
namespace sql {
|
||||
namespace sql
|
||||
{
|
||||
|
||||
ObExprUsecToTime::ObExprUsecToTime(ObIAllocator& alloc)
|
||||
ObExprUsecToTime::ObExprUsecToTime(ObIAllocator &alloc)
|
||||
: ObFuncExprOperator(alloc, T_FUN_SYS_USEC_TO_TIME, N_USEC_TO_TIME, 1, NOT_ROW_DIMENSION)
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
ObExprUsecToTime::~ObExprUsecToTime()
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
int ObExprUsecToTime::calc_result_type1(ObExprResType& type, ObExprResType& usec, common::ObExprTypeCtx& type_ctx) const
|
||||
int ObExprUsecToTime::calc_result_type1(ObExprResType &type,
|
||||
ObExprResType &usec,
|
||||
common::ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
int ret = common::OB_SUCCESS;
|
||||
@ -38,48 +44,17 @@ int ObExprUsecToTime::calc_result_type1(ObExprResType& type, ObExprResType& usec
|
||||
|
||||
} else {
|
||||
type.set_timestamp();
|
||||
type.set_scale(common::MAX_SCALE_FOR_TEMPORAL);
|
||||
// set calc type
|
||||
type.set_scale(common::MAX_SCALE_FOR_TEMPORAL); //和时间值有关,取最大值
|
||||
//set calc type
|
||||
usec.set_calc_type(ObIntType);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprUsecToTime::calc_result1(ObObj& result, const ObObj& usec, ObExprCtx& expr_ctx) const
|
||||
int calc_usec_to_time_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_UNLIKELY(usec.is_null())) {
|
||||
result.set_null();
|
||||
} else {
|
||||
TYPE_CHECK(usec, ObIntType);
|
||||
int64_t value = usec.get_int();
|
||||
int32_t offset = 0;
|
||||
const ObTimeZoneInfo* tz_info = get_timezone_info(expr_ctx.my_session_);
|
||||
if (NULL != tz_info && ObTimeConverter::ZERO_DATETIME != value) {
|
||||
if (OB_FAIL(tz_info->get_timezone_offset(USEC_TO_SEC(value), offset))) {
|
||||
LOG_WARN("failed to get offset between utc and local", K(ret));
|
||||
} else {
|
||||
value += SEC_TO_USEC(offset);
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (!ObTimeConverter::is_valid_datetime(value)) {
|
||||
ret = OB_DATETIME_FUNCTION_OVERFLOW;
|
||||
value -= SEC_TO_USEC(offset);
|
||||
LOG_WARN("datetime overflow", K(ret), K(value));
|
||||
} else {
|
||||
value -= SEC_TO_USEC(offset);
|
||||
result.set_timestamp(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int calc_usec_to_time_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datum)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObDatum* usec_datum = NULL;
|
||||
ObDatum *usec_datum = NULL;
|
||||
if (OB_FAIL(expr.args_[0]->eval(ctx, usec_datum))) {
|
||||
LOG_WARN("eval arg failed", K(ret));
|
||||
} else if (usec_datum->is_null()) {
|
||||
@ -109,7 +84,8 @@ int calc_usec_to_time_expr(const ObExpr& expr, ObEvalCtx& ctx, ObDatum& res_datu
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExprUsecToTime::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_expr, ObExpr& rt_expr) const
|
||||
int ObExprUsecToTime::cg_expr(ObExprCGCtx &expr_cg_ctx, const ObRawExpr &raw_expr,
|
||||
ObExpr &rt_expr) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
UNUSED(expr_cg_ctx);
|
||||
@ -117,5 +93,5 @@ int ObExprUsecToTime::cg_expr(ObExprCGCtx& expr_cg_ctx, const ObRawExpr& raw_exp
|
||||
rt_expr.eval_func_ = calc_usec_to_time_expr;
|
||||
return ret;
|
||||
}
|
||||
} // namespace sql
|
||||
} // namespace oceanbase
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user