From 18a4f0124256911d5ae490be286374428b5458a1 Mon Sep 17 00:00:00 2001 From: "Akhmad O." <96055449+AestheticAkhmad@users.noreply.github.com> Date: Fri, 17 Oct 2025 18:32:03 +0200 Subject: [PATCH] fix(funcexp): MCOL-4623 Add support for additional types to SEC_TO_TIME() (#3731) --- .../columnstore/bugfixes/mcol_4623.result | 34 ++++++++++++++ .../columnstore/bugfixes/mcol_4623.test | 45 +++++++++++++++++++ utils/funcexp/func_sec_to_time.cpp | 44 +++++++++++++++++- 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 mysql-test/columnstore/bugfixes/mcol_4623.result create mode 100644 mysql-test/columnstore/bugfixes/mcol_4623.test diff --git a/mysql-test/columnstore/bugfixes/mcol_4623.result b/mysql-test/columnstore/bugfixes/mcol_4623.result new file mode 100644 index 000000000..811492282 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol_4623.result @@ -0,0 +1,34 @@ +DROP DATABASE IF EXISTS mcol_4623; +CREATE DATABASE mcol_4623; +USE mcol_4623; +CREATE TABLE t1 (a DOUBLE UNSIGNED) Engine=ColumnStore; +INSERT INTO t1 VALUES (1000); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +SEC_TO_TIME(a) +00:16:40.000000 +DROP TABLE t1; +CREATE TABLE t1 (a TIME) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('17:31:27'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +SEC_TO_TIME(a) +17:31:27 +DROP TABLE t1; +CREATE TABLE t1 (a DATE) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('2023-07-23'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +SEC_TO_TIME(a) +838:59:59 +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('2009-03-17 14:30:45'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +SEC_TO_TIME(a) +838:59:59 +DROP TABLE t1; +CREATE TABLE t1 (a TIMESTAMP) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('2017-01-01 04:30:45'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +SEC_TO_TIME(a) +838:59:59 +DROP TABLE t1; +DROP DATABASE mcol_4623; diff --git a/mysql-test/columnstore/bugfixes/mcol_4623.test b/mysql-test/columnstore/bugfixes/mcol_4623.test new file mode 100644 index 000000000..9e1a879c8 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol_4623.test @@ -0,0 +1,45 @@ +-- source ../include/have_columnstore.inc +--disable_warnings +DROP DATABASE IF EXISTS mcol_4623; +--enable_warnings +CREATE DATABASE mcol_4623; +USE mcol_4623; + +CREATE TABLE t1 (a DOUBLE UNSIGNED) Engine=ColumnStore; +INSERT INTO t1 VALUES (1000); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +--disable_warnings +DROP TABLE t1; +--enable_warnings + +CREATE TABLE t1 (a TIME) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('17:31:27'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +--disable_warnings +DROP TABLE t1; +--enable_warnings + +CREATE TABLE t1 (a DATE) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('2023-07-23'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +--disable_warnings +DROP TABLE t1; +--enable_warnings + +CREATE TABLE t1 (a DATETIME) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('2009-03-17 14:30:45'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +--disable_warnings +DROP TABLE t1; +--enable_warnings + +CREATE TABLE t1 (a TIMESTAMP) ENGINE=ColumnStore; +INSERT INTO t1 VALUES ('2017-01-01 04:30:45'); +SELECT SEC_TO_TIME(a) FROM t1 ORDER BY 1; +--disable_warnings +DROP TABLE t1; +--enable_warnings + +--disable_warnings +DROP DATABASE mcol_4623; +--enable_warnings diff --git a/utils/funcexp/func_sec_to_time.cpp b/utils/funcexp/func_sec_to_time.cpp index d9e2932f1..6bb67a071 100644 --- a/utils/funcexp/func_sec_to_time.cpp +++ b/utils/funcexp/func_sec_to_time.cpp @@ -67,33 +67,73 @@ string Func_sec_to_time::getStrVal(rowgroup::Row& row, FunctionParm& parm, bool& case execplan::CalpontSystemCatalog::USMALLINT: { val = parm[0]->data()->getIntVal(row, isNull); + break; } - break; case execplan::CalpontSystemCatalog::DOUBLE: + case execplan::CalpontSystemCatalog::UDOUBLE: { datatypes::TDouble d(parm[0]->data()->getDoubleVal(row, isNull)); val = d.toMCSSInt64Round(); break; } + case execplan::CalpontSystemCatalog::FLOAT: + case execplan::CalpontSystemCatalog::UFLOAT: { datatypes::TDouble d(parm[0]->data()->getFloatVal(row, isNull)); val = d.toMCSSInt64Round(); + break; + } + + case execplan::CalpontSystemCatalog::LONGDOUBLE: + { + datatypes::TLongDouble d(parm[0]->data()->getLongDoubleVal(row, isNull)); + val = d.toMCSSInt64Round(); + break; } - break; case execplan::CalpontSystemCatalog::DECIMAL: case execplan::CalpontSystemCatalog::UDECIMAL: + { val = parm[0]->data()->getDecimalVal(row, isNull).toSInt64Round(); break; + } case execplan::CalpontSystemCatalog::CHAR: case execplan::CalpontSystemCatalog::VARCHAR: case execplan::CalpontSystemCatalog::TEXT: { val = parm[0]->data()->getIntVal(row, isNull); + break; + } + case execplan::CalpontSystemCatalog::TIME: + { + int64_t timeVal = parm[0]->data()->getTimeIntVal(row, isNull); + uint32_t hour = (uint32_t)((timeVal >> 40) & 0xfff); + uint32_t minute = (uint32_t)((timeVal >> 32) & 0xff); + uint32_t second = (uint32_t)((timeVal >> 24) & 0xff); + val = (int64_t)(hour * 3600 + minute * 60 + second); + break; + } + + case execplan::CalpontSystemCatalog::DATE: + case execplan::CalpontSystemCatalog::DATETIME: + case execplan::CalpontSystemCatalog::TIMESTAMP: + { + return "838:59:59"; + break; + } + + case execplan::CalpontSystemCatalog::BLOB: + case execplan::CalpontSystemCatalog::CLOB: + case execplan::CalpontSystemCatalog::VARBINARY: + case execplan::CalpontSystemCatalog::STRINT: + case execplan::CalpontSystemCatalog::NUM_OF_COL_DATA_TYPE: + case execplan::CalpontSystemCatalog::UNDEFINED: + { + val = parm[0]->data()->getIntVal(row, isNull); break; }