[CP] fix bug about timestampdiff and timestampadd
This commit is contained in:
@ -46,17 +46,14 @@ inline int ObExprTimeStampAdd::calc_result_type3(ObExprResType &type,
|
||||
ObExprResType ×tamp,
|
||||
common::ObExprTypeCtx &type_ctx) const
|
||||
{
|
||||
UNUSED(type_ctx);
|
||||
UNUSED(unit);
|
||||
UNUSED(interval);
|
||||
UNUSED(timestamp);
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
ObCompatibilityMode compat_mode = get_compatibility_mode();
|
||||
//not timestamp. compatible with mysql.
|
||||
type.set_varchar();
|
||||
type.set_length(common::ObAccuracy::MAX_ACCURACY2[compat_mode][common::ObTimestampType].precision_
|
||||
+ common::ObAccuracy::MAX_ACCURACY2[compat_mode][common::ObTimestampType].scale_ + 1);
|
||||
//timestamp.set_calc_type(common::ObDateTimeType);
|
||||
type.set_length(common::ObAccuracy::MAX_ACCURACY2[compat_mode][common::ObDateTimeType].precision_
|
||||
+ common::ObAccuracy::MAX_ACCURACY2[compat_mode][common::ObDateTimeType].scale_ + 1);
|
||||
type.set_collation_level(common::CS_LEVEL_IMPLICIT);
|
||||
//not connection collation. compatible with mysql.
|
||||
type.set_collation_type(common::ObCharset::get_default_collation(common::ObCharset::get_default_charset()));
|
||||
@ -216,7 +213,7 @@ int calc_timestampadd_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datu
|
||||
int64_t interval_int = interval_datum->get_int();
|
||||
int64_t res = 0;
|
||||
ObTime ot;
|
||||
ObTimeConvertCtx cvrt_ctx(get_timezone_info(ctx.exec_ctx_.get_my_session()), true);
|
||||
ObTimeConvertCtx cvrt_ctx(get_timezone_info(ctx.exec_ctx_.get_my_session()), false);
|
||||
char *buf = NULL;
|
||||
int64_t buf_len = OB_CAST_TO_VARCHAR_MAX_LENGTH;
|
||||
int64_t out_len = 0;
|
||||
@ -233,7 +230,7 @@ int calc_timestampadd_expr(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &res_datu
|
||||
} else if (OB_ISNULL(buf = expr.get_str_res_mem(ctx, buf_len))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("allocate memory failed", K(ret), K(buf_len));
|
||||
} else if (OB_FAIL(common_datetime_string(ObTimestampType, ObVarcharType,
|
||||
} else if (OB_FAIL(common_datetime_string(ObDateTimeType, ObVarcharType,
|
||||
expr.args_[2]->datum_meta_.scale_, false,
|
||||
res, ctx, buf, buf_len, out_len))) {
|
||||
LOG_WARN("common_datetime_string failed", K(ret), K(res), K(expr));
|
||||
|
||||
@ -200,8 +200,8 @@ int ObExprTimeStampDiff::eval_timestamp_diff(const ObExpr &expr, ObEvalCtx &ctx,
|
||||
} else {
|
||||
int64_t res_int = 0;
|
||||
bool is_null = false;
|
||||
if (OB_FAIL(calc(res_int, is_null, u->get_int(), l->get_timestamp(),
|
||||
r->get_timestamp(), session->get_timezone_info()))) {
|
||||
if (OB_FAIL(calc(res_int, is_null, u->get_int(), l->get_datetime(),
|
||||
r->get_datetime(), session->get_timezone_info()))) {
|
||||
LOG_WARN("calc failed", K(ret));
|
||||
} else if (is_null) {
|
||||
res.set_null();
|
||||
@ -220,8 +220,8 @@ int ObExprTimeStampDiff::cg_expr(ObExprCGCtx &ctx, const ObRawExpr &raw_expr,
|
||||
UNUSED(raw_expr);
|
||||
CK(3 == rt_expr.arg_cnt_);
|
||||
CK(ObIntType == rt_expr.args_[0]->datum_meta_.type_ &&
|
||||
ObTimestampType == rt_expr.args_[1]->datum_meta_.type_ &&
|
||||
ObTimestampType == rt_expr.args_[2]->datum_meta_.type_);
|
||||
ObDateTimeType == rt_expr.args_[1]->datum_meta_.type_ &&
|
||||
ObDateTimeType == rt_expr.args_[2]->datum_meta_.type_);
|
||||
OX(rt_expr.eval_func_ = eval_timestamp_diff);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -58,8 +58,8 @@ inline int ObExprTimeStampDiff::calc_result_type3(ObExprResType &type,
|
||||
type.set_scale(common::DEFAULT_SCALE_FOR_INTEGER);
|
||||
type.set_precision(common::ObAccuracy::DDL_DEFAULT_ACCURACY[common::ObIntType].precision_);
|
||||
//set calc type
|
||||
left.set_calc_type(common::ObTimestampType);
|
||||
right.set_calc_type(common::ObTimestampType);
|
||||
left.set_calc_type(common::ObDateTimeType);
|
||||
right.set_calc_type(common::ObDateTimeType);
|
||||
return common::OB_SUCCESS;
|
||||
}
|
||||
} //sql
|
||||
|
||||
Reference in New Issue
Block a user