zclllyybb commented on code in PR #47320:
URL: https://github.com/apache/doris/pull/47320#discussion_r1942167356


##########
be/src/vec/functions/function_date_or_datetime_computation.h:
##########
@@ -995,4 +995,32 @@ class CurrentDateFunctionBuilder : public 
FunctionBuilderImpl {
     }
 };
 
+class FunctionTime : public IFunction {
+public:
+    static constexpr auto name = "time";
+    static FunctionPtr create() { return std::make_shared<FunctionTime>(); }
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return std::make_shared<DataTypeTimeV2>();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        DCHECK_EQ(arguments.size(), 1);
+        ColumnPtr col = block.get_by_position(arguments[0]).column;
+        const auto* arg = assert_cast<const ColumnUInt64*>(col.get());
+        auto res = ColumnFloat64::create(input_rows_count);
+        auto& res_data = res->get_data();
+        for (int i = 0; i < arg->size(); i++) {
+            auto v = arg->get_element(i);
+            res_data[i] = TimeValue::make_time((v & 0x1f00000000) >> 32, (v & 
0xfc000000) >> 26,

Review Comment:
   make the const vars constexpr. and add comment for this line.



##########
regression-test/suites/query_p0/sql_functions/datetime_functions/test_time.groovy:
##########
@@ -0,0 +1,46 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_time") {
+    qt_sql """ select time('2025-1-1 12:12:12') """
+    qt_sql """ select time('2025-1-1 12:12:61') """
+    qt_sql """ select time('2025-1-1 12:61:12') """
+    qt_sql """ select time('2025-1-1 25:12:12') """

Review Comment:
   add more testcases about nullable input. see `test_templeta_one_arg.groovy`



##########
be/src/vec/functions/function_date_or_datetime_computation.h:
##########
@@ -995,4 +995,32 @@ class CurrentDateFunctionBuilder : public 
FunctionBuilderImpl {
     }
 };
 
+class FunctionTime : public IFunction {
+public:
+    static constexpr auto name = "time";
+    static FunctionPtr create() { return std::make_shared<FunctionTime>(); }
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return std::make_shared<DataTypeTimeV2>();
+    }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        uint32_t result, size_t input_rows_count) const 
override {
+        DCHECK_EQ(arguments.size(), 1);
+        ColumnPtr col = block.get_by_position(arguments[0]).column;
+        const auto* arg = assert_cast<const ColumnUInt64*>(col.get());
+        auto res = ColumnFloat64::create(input_rows_count);

Review Comment:
   we'd better not use auto here. but `ColumnFloat64::MutablePtr`. then people 
will know the L1017 it not a virtual function call



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to