From 4bdf785213aaca5e8d3a10de9832ecb9bc14291b Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 4 Nov 2022 11:40:48 +0000 Subject: [PATCH] Improve Second and Microsecond function --- src/sql/engine/expr/ob_expr_time.cpp | 3 ++- src/sql/engine/expr/ob_expr_time.h | 40 +++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/sql/engine/expr/ob_expr_time.cpp b/src/sql/engine/expr/ob_expr_time.cpp index 1e01bfca6..c00eea2e6 100644 --- a/src/sql/engine/expr/ob_expr_time.cpp +++ b/src/sql/engine/expr/ob_expr_time.cpp @@ -337,8 +337,9 @@ int ObExprMonthName::calc_result_type1(ObExprResType &type, type.set_collation_level(CS_LEVEL_IMPLICIT); common::ObObjTypeClass tc1 = ob_obj_type_class(type1.get_type()); - if (ob_is_enumset_tc(type1.get_type())) { + if (common::ObEnumSetTC == tc1) { type1.set_calc_type(common::ObVarcharType); + type1.set_calc_collation_type(cs_type); } else if ((common::ObFloatTC == tc1) || (common::ObDoubleTC == tc1)) { type1.set_calc_type(common::ObIntType); } diff --git a/src/sql/engine/expr/ob_expr_time.h b/src/sql/engine/expr/ob_expr_time.h index cf0538a84..38541d59e 100644 --- a/src/sql/engine/expr/ob_expr_time.h +++ b/src/sql/engine/expr/ob_expr_time.h @@ -60,14 +60,12 @@ inline int ObExprTimeBase::calc_result_type1(ObExprResType &type, ObExprResType &type1, common::ObExprTypeCtx &type_ctx) const { - UNUSED(type_ctx); - UNUSED(type1); type.set_int32(); type.set_precision(4); type.set_scale(0); common::ObObjTypeClass tc1 = ob_obj_type_class(type1.get_type()); - if (ob_is_enumset_tc(type1.get_type())) { - type1.set_calc_type(common::ObVarcharType); + if (common::ObEnumSetTC == tc1) { + type1.set_calc_type_default_varchar(); } else if ((common::ObFloatTC == tc1) || (common::ObDoubleTC == tc1)) { type1.set_calc_type(common::ObIntType); } @@ -102,22 +100,56 @@ public: ObExprSecond(); explicit ObExprSecond(common::ObIAllocator &alloc); virtual ~ObExprSecond(); + virtual int calc_result_type1(ObExprResType &type, + ObExprResType &type1, + common::ObExprTypeCtx &type_ctx) const; static int calc_second(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum); private: DISALLOW_COPY_AND_ASSIGN(ObExprSecond); }; +inline int ObExprSecond::calc_result_type1(ObExprResType &type, + ObExprResType &type1, + common::ObExprTypeCtx &type_ctx) const +{ + type.set_int32(); + type.set_precision(4); + type.set_scale(0); + common::ObObjTypeClass tc1 = ob_obj_type_class(type1.get_type()); + if ((common::ObEnumSetTC == tc1) || (common::ObFloatTC == tc1) || (common::ObDoubleTC == tc1)) { + type1.set_calc_type_default_varchar(); + } + return common::OB_SUCCESS; +} + class ObExprMicrosecond: public ObExprTimeBase { public: ObExprMicrosecond(); explicit ObExprMicrosecond(common::ObIAllocator &alloc); virtual ~ObExprMicrosecond(); + virtual int calc_result_type1(ObExprResType &type, + ObExprResType &type1, + common::ObExprTypeCtx &type_ctx) const; static int calc_microsecond(const ObExpr &expr, ObEvalCtx &ctx, ObDatum &expr_datum); private: DISALLOW_COPY_AND_ASSIGN(ObExprMicrosecond); }; +inline int ObExprMicrosecond::calc_result_type1(ObExprResType &type, + ObExprResType &type1, + common::ObExprTypeCtx &type_ctx) const +{ + type.set_int32(); + type.set_precision(4); + type.set_scale(0); + common::ObObjTypeClass tc1 = ob_obj_type_class(type1.get_type()); + if ((common::ObEnumSetTC == tc1) || (common::ObFloatTC == tc1) || (common::ObDoubleTC == tc1)) { + type1.set_calc_type_default_varchar(); + } + return common::OB_SUCCESS; +} + class ObExprYear: public ObExprTimeBase { public: