cherry-pick to opensource branch

This commit is contained in:
st0
2022-03-16 20:16:36 +08:00
committed by LINxiansheng
parent 4255c9054b
commit 8d81ad6ed1
11 changed files with 64 additions and 30 deletions

View File

@ -835,13 +835,14 @@ static OB_INLINE int common_string_year(const ObExpr& expr, const ObString& in_s
if (OB_FAIL(common_string_int(expr, extra, in_str, is_str_int_cast, tmp_res, warning))) {
LOG_WARN("common_string_int failed", K(ret), K(in_str));
} else if (0 == tmp_int) {
// cast '0000' to year, result is 0. cast '0'/'00'/'00000' to year, result is 2000.
if (4 == in_str.length()) {
// cast '0000' to year, result is 0. cast '0'/'00'/'00000' to year, result is 2000.
if (OB_SUCCESS != warning || 4 == in_str.length()) {
SET_RES_YEAR(ObTimeConverter::ZERO_YEAR);
} else {
const uint8_t base_year = 100;
SET_RES_YEAR(base_year);
}
CAST_FAIL(warning);
} else {
if (CAST_FAIL(common_int_year(expr, tmp_int, res_datum, warning))) {
LOG_WARN("common_int_year failed", K(ret), K(tmp_int));
@ -4283,9 +4284,14 @@ CAST_FUNC_NAME(time, date)
int32_t out_val = 0;
ObPhysicalPlanCtx *phy_plan_ctx = ctx.exec_ctx_.get_physical_plan_ctx();
int64_t cur_time = phy_plan_ctx ? phy_plan_ctx->get_cur_time().get_datetime() : 0;
if (OB_FAIL(ObTimeConverter::datetime_to_date(cur_time, session->get_timezone_info(),
out_val))) {
int64_t datetime_value = 0;
int64_t in_val = child_res->get_time();
ObTimeConvertCtx cvrt_ctx(session->get_timezone_info(), false);
if (OB_FAIL(ObTimeConverter::time_to_datetime(in_val, cur_time, session->get_timezone_info(),
datetime_value, ObDateTimeType))) {
LOG_WARN("datetime_to_date failed", K(ret), K(cur_time));
} else if (ObTimeConverter::datetime_to_date(datetime_value, NULL, out_val)) {
LOG_WARN("date to datetime failed", K(ret), K(datetime_value));
} else {
res_datum.set_date(out_val);
}