This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 518c01932bd [fix](function) make TIMESTAMP function DEPEND_ON_ARGUMENT 
(#27343) (#27458)
518c01932bd is described below

commit 518c01932bd17a20e87df1df021054765eef2a32
Author: Mryange <[email protected]>
AuthorDate: Thu Nov 23 18:05:55 2023 +0800

    [fix](function) make TIMESTAMP function DEPEND_ON_ARGUMENT (#27343) (#27458)
---
 be/src/vec/functions/function_timestamp.cpp        |  33 ++--
 gensrc/script/doris_builtins_functions.py          |   6 +-
 .../test_from_millisecond_microsecond.out          | 108 ++++++++++--
 .../test_from_millisecond_microsecond.groovy       | 190 +++++++++++++++++++--
 4 files changed, 287 insertions(+), 50 deletions(-)

diff --git a/be/src/vec/functions/function_timestamp.cpp 
b/be/src/vec/functions/function_timestamp.cpp
index e928e40ce30..9a42569dde4 100644
--- a/be/src/vec/functions/function_timestamp.cpp
+++ b/be/src/vec/functions/function_timestamp.cpp
@@ -816,7 +816,10 @@ public:
     size_t get_number_of_arguments() const override { return 1; }
 
     DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) 
const override {
-        return make_nullable(std::make_shared<DataTypeInt64>());
+        if (arguments[0].type->is_nullable()) {
+            return make_nullable(std::make_shared<DataTypeInt64>());
+        }
+        return std::make_shared<DataTypeInt64>();
     }
 
     Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
@@ -824,31 +827,23 @@ public:
         const auto& arg_col = block.get_by_position(arguments[0]).column;
         const auto& column_data = assert_cast<const ColumnUInt64&>(*arg_col);
         auto res_col = ColumnInt64::create();
-        auto null_vector = ColumnVector<UInt8>::create();
-        res_col->get_data().resize_fill(input_rows_count, 0);
-        null_vector->get_data().resize_fill(input_rows_count, false);
-        NullMap& null_map = null_vector->get_data();
         auto& res_data = res_col->get_data();
-        const cctz::time_zone& time_zone = context->state()->timezone_obj();
+        res_col->get_data().resize_fill(input_rows_count, 0);
         for (int i = 0; i < input_rows_count; i++) {
-            if (arg_col->is_null_at(i)) {
-                null_map[i] = true;
-                continue;
-            }
             StringRef source = column_data.get_data_at(i);
             const DateV2Value<DateTimeV2ValueType>& dt =
                     reinterpret_cast<const 
DateV2Value<DateTimeV2ValueType>&>(*source.data);
+            const cctz::time_zone& time_zone = 
context->state()->timezone_obj();
             int64_t timestamp {0};
-            if (!dt.unix_timestamp(&timestamp, time_zone)) {
-                null_map[i] = true;
-            } else {
-                auto microsecond = dt.microsecond();
-                timestamp = timestamp * Impl::ratio + microsecond / 
ratio_to_micro;
-                res_data[i] = timestamp;
-            }
+            auto ret = dt.unix_timestamp(&timestamp, time_zone);
+            // ret must be true
+            DCHECK(ret);
+            auto microsecond = dt.microsecond();
+            timestamp = timestamp * Impl::ratio + microsecond / ratio_to_micro;
+            res_data[i] = timestamp;
         }
-        block.get_by_position(result).column =
-                ColumnNullable::create(std::move(res_col), 
std::move(null_vector));
+        block.replace_by_position(result, std::move(res_col));
+
         return Status::OK();
     }
 };
diff --git a/gensrc/script/doris_builtins_functions.py 
b/gensrc/script/doris_builtins_functions.py
index f1a71ef6f98..e3338008fb7 100644
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -843,9 +843,9 @@ visible_functions = {
         [['from_microsecond'], 'DATETIMEV2', ['BIGINT'], 'ALWAYS_NULLABLE'],
         [['from_millisecond'], 'DATETIMEV2', ['BIGINT'], 'ALWAYS_NULLABLE'],
         [['from_second'], 'DATETIMEV2', ['BIGINT'], 'ALWAYS_NULLABLE'],
-        [['second_timestamp'], 'BIGINT', ['DATETIMEV2'], 'ALWAYS_NULLABLE'],
-        [['millisecond_timestamp'], 'BIGINT', ['DATETIMEV2'], 
'ALWAYS_NULLABLE'],
-        [['microsecond_timestamp'], 'BIGINT', ['DATETIMEV2'], 
'ALWAYS_NULLABLE'],
+        [['second_timestamp'], 'BIGINT', ['DATETIMEV2'], 'DEPEND_ON_ARGUMENT'],
+        [['millisecond_timestamp'], 'BIGINT', ['DATETIMEV2'], 
'DEPEND_ON_ARGUMENT'],
+        [['microsecond_timestamp'], 'BIGINT', ['DATETIMEV2'], 
'DEPEND_ON_ARGUMENT'],
         [['now', 'current_timestamp', 'localtime', 'localtimestamp'], 
'DATETIME', [], 'DEPEND_ON_ARGUMENT'],
         [['now', 'current_timestamp', 'localtime', 'localtimestamp'], 
'DATETIMEV2', ['INT'], 'DEPEND_ON_ARGUMENT'],
         [['curtime', 'current_time'], 'TIME', [], 'ALWAYS_NOT_NULLABLE'],
diff --git 
a/regression-test/data/correctness/test_from_millisecond_microsecond.out 
b/regression-test/data/correctness/test_from_millisecond_microsecond.out
index 50861a9400b..42d533f29f9 100644
--- a/regression-test/data/correctness/test_from_millisecond_microsecond.out
+++ b/regression-test/data/correctness/test_from_millisecond_microsecond.out
@@ -1,18 +1,15 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
 -- !select1 --
-2030-11-02T08:35:14.514        2030-11-02T08:35:14.514
-4803-07-17T15:07:14.789        \N
-2009-02-28T18:44:56.941        2009-02-28T18:44:56.941
-\N     \N
+2030-11-02T08:35:14.514
+4803-07-17T15:07:14.789
+2009-02-28T18:44:56.941
+\N
 
 -- !select2 --
-1970-01-23T13:16:50.114514     1970-01-23T13:16:50.114514
-1972-11-01T06:18:11.234789     1972-11-01T06:18:11.234789
-1970-01-15T15:16:57.896941     1970-01-15T15:16:57.896941
-\N     \N
-
--- !select3 --
-2038-01-19 11:14:07    2038-01-19T11:14:07     \N      2038-01-19T11:14:08     
\N      2650-07-06T16:21:10
+1970-01-23T13:16:50.114514
+1972-11-01T06:18:11.234789
+1970-01-15T15:16:57.896941
+\N
 
 -- !select4 --
 1919810114514          1919810114514
@@ -44,8 +41,83 @@
 1970-01-15T15:16:57.896941
 \N
 
--- !select9 --
-2038-01-19 11:14:07    2038-01-19T11:14:07     \N      2038-01-19T11:14:08     
\N      2650-07-06T16:21:10
+-- !select10 --
+1919810114514          1919810114514
+89417891234789         488885820389
+1235817896941          1235817896941
+\N     \N      \N
+
+-- !select11 --
+1919810114514  2030-11-02T08:35:14.514 1919810114514
+89417891234789 4803-07-17T15:07:14.789 89417891234789
+1235817896941  2009-02-28T18:44:56.941 1235817896941
+\N     \N      \N
+
+-- !select12 --
+1919810114514  1970-01-23T13:16:50.114514      1919810114514
+89417891234789 1972-11-01T06:18:11.234789      89417891234789
+1235817896941  1970-01-15T15:16:57.896941      1235817896941
+\N     \N      \N
+
+-- !select13 --
+1700237372
+
+-- !select14 --
+1700237372000
+
+-- !select15 --
+1700237372000000
+
+-- !select16 --
+1700237372
+
+-- !select17 --
+1700237372000
+
+-- !select18 --
+1700237372000000
+
+-- !select1 --
+2030-11-02T08:35:14.514
+4803-07-17T15:07:14.789
+2009-02-28T18:44:56.941
+\N
+
+-- !select2 --
+1970-01-23T13:16:50.114514
+1972-11-01T06:18:11.234789
+1970-01-15T15:16:57.896941
+\N
+
+-- !select4 --
+1919810114514          1919810114514
+89417891234789         488885820389
+1235817896941          1235817896941
+\N     \N      \N
+
+-- !select5 --
+1919810114514  2030-11-02T08:35:14.514 1919810114514
+89417891234789 4803-07-17T15:07:14.789 89417891234789
+1235817896941  2009-02-28T18:44:56.941 1235817896941
+\N     \N      \N
+
+-- !select6 --
+1919810114514  1970-01-23T13:16:50.114514      1919810114514
+89417891234789 1972-11-01T06:18:11.234789      89417891234789
+1235817896941  1970-01-15T15:16:57.896941      1235817896941
+\N     \N      \N
+
+-- !select7 --
+2030-11-02T08:35:14.514
+4803-07-17T15:07:14.789
+2009-02-28T18:44:56.941
+\N
+
+-- !select8 --
+1970-01-23T13:16:50.114514
+1972-11-01T06:18:11.234789
+1970-01-15T15:16:57.896941
+\N
 
 -- !select10 --
 1919810114514          1919810114514
@@ -65,3 +137,13 @@
 1235817896941  1970-01-15T15:16:57.896941      1235817896941
 \N     \N      \N
 
+-- !select_null_datetime --
+1      1672502400      1672502400000   1672502400000000
+2      1672502400      1672502400123   1672502400123000
+3      1672502400      1672502400123   1672502400123456
+
+-- !select_not_null_datetime --
+1      1672502400      1672502400000   1672502400000000
+2      1672502400      1672502400123   1672502400123000
+3      1672502400      1672502400123   1672502400123456
+
diff --git 
a/regression-test/suites/correctness/test_from_millisecond_microsecond.groovy 
b/regression-test/suites/correctness/test_from_millisecond_microsecond.groovy
index 15335cfd68b..13727ff08a9 100644
--- 
a/regression-test/suites/correctness/test_from_millisecond_microsecond.groovy
+++ 
b/regression-test/suites/correctness/test_from_millisecond_microsecond.groovy
@@ -49,25 +49,16 @@ suite("test_from_millisecond_microsecond") {
 
     qt_select1 """
         select 
-        from_millisecond(t) as t1 , 
-        microseconds_add(cast(from_unixtime(t/1000) as datetime(3)), cast((t % 
1000) * 1000 as int)) as t2 
+        from_millisecond(t) as t1
         from millimicro order by id;
     """
 
     qt_select2 """
         select 
-        from_microsecond(t) as t1 , 
-        microseconds_add(cast(from_unixtime(t/1000000) as datetime(6)), 
cast((t % 1000000) as int)) as t2 
+        from_microsecond(t) as t1
         from millimicro order by id;
     """ 
 
-    qt_select3 """
-        select 
-        FROM_UNIXTIME(2147483647),from_second(2147483647),
-        FROM_UNIXTIME(2147483647 + 1),from_second(2147483647 + 1),
-        FROM_UNIXTIME(21474836470),from_second(21474836470);
-    """ 
-
     qt_select4 """
         select 
         t,
@@ -100,12 +91,110 @@ suite("test_from_millisecond_microsecond") {
         select from_microsecond(t) as t1 from millimicro order by id;
     """
 
-    qt_select9 """
+    qt_select10 """
+        select 
+        t,
+        from_second(t), 
+        second_timestamp(from_second(t))
+        from millimicro order by id;
+    """ 
+    qt_select11 """
+        select 
+        t,
+        from_millisecond(t), 
+        millisecond_timestamp(from_millisecond(t))
+        from millimicro order by id;
+    """ 
+    qt_select12 """
+        select 
+        t,
+        from_microsecond(t), 
+        microsecond_timestamp(from_microsecond(t))
+        from millimicro order by id;
+    """ 
+    qt_select13 """select SECOND_TIMESTAMP(cast('2023-11-18 00:09:32' as 
datetime));""" 
+    qt_select14 """select MILLISECOND_TIMESTAMP(cast('2023-11-18 00:09:32' as 
datetime));""" 
+    qt_select15 """select MICROSECOND_TIMESTAMP(cast('2023-11-18 00:09:32' as 
datetime));""" 
+    sql """
+        set enable_nereids_planner=false
+    """
+    qt_select16 """select SECOND_TIMESTAMP(cast('2023-11-18 00:09:32' as 
datetime));""" 
+    qt_select17 """select MILLISECOND_TIMESTAMP(cast('2023-11-18 00:09:32' as 
datetime));""" 
+    qt_select18 """select MICROSECOND_TIMESTAMP(cast('2023-11-18 00:09:32' as 
datetime));"""
+
+    // not null 
+    sql """ DROP TABLE IF EXISTS millimicro """
+    sql """
+        CREATE TABLE IF NOT EXISTS millimicro (
+              `id` INT(11)  COMMENT ""   ,
+              `t` BigINT  COMMENT ""
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+    );
+    """
+
+    sql """
+        insert into millimicro values(1,1919810114514);
+    """
+    sql """
+        insert into millimicro values(2,89417891234789);
+    """
+    sql """
+        insert into millimicro values(3,1235817896941);
+    """
+
+    sql """
+        insert into millimicro values(4,NULL);
+    """
+
+
+    qt_select1 """
+        select 
+        from_millisecond(t) as t1 
+        from millimicro order by id;
+    """
+
+    qt_select2 """
+        select 
+        from_microsecond(t) as t1 
+        from millimicro order by id;
+    """ 
+
+    qt_select4 """
+        select 
+        t,
+        from_second(t), 
+        second_timestamp(from_second(t))
+        from millimicro order by id;
+    """ 
+    qt_select5 """
+        select 
+        t,
+        from_millisecond(t), 
+        millisecond_timestamp(from_millisecond(t))
+        from millimicro order by id;
+    """ 
+    qt_select6 """
         select 
-        FROM_UNIXTIME(2147483647),from_second(2147483647),
-        FROM_UNIXTIME(2147483647 + 1),from_second(2147483647 + 1),
-        FROM_UNIXTIME(21474836470),from_second(21474836470);
+        t,
+        from_microsecond(t), 
+        microsecond_timestamp(from_microsecond(t))
+        from millimicro order by id;
     """ 
+    sql """
+        set enable_nereids_planner=true,enable_fold_constant_by_be = 
false,forbid_unknown_col_stats = false
+    """
+   
+    qt_select7 """
+        select from_millisecond(t) as t1 from millimicro order by id;
+    """
+    qt_select8 """
+        select from_microsecond(t) as t1 from millimicro order by id;
+    """
 
     qt_select10 """
         select 
@@ -128,4 +217,75 @@ suite("test_from_millisecond_microsecond") {
         microsecond_timestamp(from_microsecond(t))
         from millimicro order by id;
     """ 
+
+    // null datetime
+    sql """ DROP TABLE IF EXISTS millimicro """
+    sql """
+        CREATE TABLE IF NOT EXISTS millimicro (
+              `id` INT(11) NULL COMMENT ""   ,
+              `t` Datetime(6) NULL COMMENT ""
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+    );
+    """
+
+    sql """
+        insert into millimicro values(1,'2023-01-01 00:00:00');
+    """
+    sql """
+        insert into millimicro values(2,'2023-01-01 00:00:00.123');
+    """
+    sql """
+        insert into millimicro values(3,'2023-01-01 00:00:00.123456');
+    """
+
+    qt_select_null_datetime """
+        select 
+        id,
+        SECOND_TIMESTAMP(t),
+        MILLISECOND_TIMESTAMP(t),
+        MICROSECOND_TIMESTAMP(t)
+        from millimicro
+        order by id;
+    """ 
+
+
+    // not null datetime
+    sql """ DROP TABLE IF EXISTS millimicro """
+    sql """
+        CREATE TABLE IF NOT EXISTS millimicro (
+              `id` INT(11) NULL COMMENT ""   ,
+              `t` Datetime(6)  COMMENT ""
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`id`)
+            DISTRIBUTED BY HASH(`id`) BUCKETS 1
+            PROPERTIES (
+            "replication_allocation" = "tag.location.default: 1",
+            "storage_format" = "V2"
+    );
+    """
+
+    sql """
+        insert into millimicro values(1,'2023-01-01 00:00:00');
+    """
+    sql """
+        insert into millimicro values(2,'2023-01-01 00:00:00.123');
+    """
+    sql """
+        insert into millimicro values(3,'2023-01-01 00:00:00.123456');
+    """
+
+    qt_select_not_null_datetime """
+        select 
+        id,
+        SECOND_TIMESTAMP(t),
+        MILLISECOND_TIMESTAMP(t),
+        MICROSECOND_TIMESTAMP(t)
+        from millimicro
+        order by id;
+    """ 
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to