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


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java:
##########
@@ -532,14 +534,16 @@
 /**
  * Builtin scalar functions.
  * <p>
- * Note: Please ensure that this class only has some lists and no procedural 
code.
+ * Note: Please ensure that this class only has some lists and no procedural
+ * code.

Review Comment:
   dont format irrelative code 



##########
be/src/vec/functions/function_date_or_datetime_computation.h:
##########
@@ -1246,5 +1246,120 @@ class FunctionTime : public IFunction {
         return Status::OK();
     }
 };
+
+struct AddTimeImpl {
+    static constexpr auto name = "add_time";
+    static bool is_negative() { return false; }
+};
+
+struct SubTimeImpl {
+    static constexpr auto name = "sub_time";
+    static bool is_negative() { return true; }
+};
+
+template <PrimitiveType PType, typename Impl>
+class FunctionAddTime : public IFunction {
+public:
+    static constexpr auto name = Impl::name;
+    static constexpr PrimitiveType ReturnType = PType;
+    static constexpr PrimitiveType ArgType1 = PType;
+    static constexpr PrimitiveType ArgType2 = TYPE_TIMEV2;
+    using ColumnType1 = typename PrimitiveTypeTraits<PType>::ColumnType;
+    using ColumnType2 = typename PrimitiveTypeTraits<TYPE_TIMEV2>::ColumnType;
+    using InputType1 = typename 
PrimitiveTypeTraits<PType>::DataType::FieldType;
+    using InputType2 = typename 
PrimitiveTypeTraits<TYPE_TIMEV2>::DataType::FieldType;
+    using ReturnNativeType = InputType1;
+    using ReturnDataType = typename PrimitiveTypeTraits<PType>::DataType;
+
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 2; }
+    DataTypes get_variadic_argument_types_impl() const override {
+        return {std::make_shared<typename 
PrimitiveTypeTraits<PType>::DataType>(),
+                std::make_shared<typename 
PrimitiveTypeTraits<TYPE_TIMEV2>::DataType>()};
+    }
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) 
const override {
+        return std::make_shared<ReturnDataType>();
+    }
+
+    ReturnNativeType compute(const InputType1& arg1, const InputType2& arg2) 
const {
+        if constexpr (PType == TYPE_DATETIMEV2) {
+            DateV2Value<DateTimeV2ValueType> dtv1 =
+                    binary_cast<InputType1, 
DateV2Value<DateTimeV2ValueType>>(arg1);
+            auto tv2 = static_cast<TimeValue::TimeType>(arg2);
+            TimeInterval interval(TimeUnit::MICROSECOND, tv2, 
Impl::is_negative());
+            bool out_range = dtv1.template 
date_add_interval<TimeUnit::MICROSECOND>(interval);
+            if (!out_range) {
+                throw Exception(ErrorCode::INVALID_ARGUMENT,
+                                "datetime value is out of range in function 
{}", name);
+            }
+            return binary_cast<DateV2Value<DateTimeV2ValueType>, 
ReturnNativeType>(dtv1);
+        } else if constexpr (PType == TYPE_TIMEV2) {
+            auto tv1 = static_cast<TimeValue::TimeType>(arg1);
+            auto tv2 = static_cast<TimeValue::TimeType>(arg2);
+            bool neg = std::string_view(name) == "sub_time";

Review Comment:
   这个忘改了



##########
be/src/vec/functions/function_date_or_datetime_computation.h:
##########
@@ -1246,5 +1246,120 @@ class FunctionTime : public IFunction {
         return Status::OK();
     }
 };
+
+struct AddTimeImpl {
+    static constexpr auto name = "add_time";
+    static bool is_negative() { return false; }
+};
+
+struct SubTimeImpl {
+    static constexpr auto name = "sub_time";
+    static bool is_negative() { return true; }
+};
+
+template <PrimitiveType PType, typename Impl>
+class FunctionAddTime : public IFunction {
+public:
+    static constexpr auto name = Impl::name;
+    static constexpr PrimitiveType ReturnType = PType;
+    static constexpr PrimitiveType ArgType1 = PType;
+    static constexpr PrimitiveType ArgType2 = TYPE_TIMEV2;
+    using ColumnType1 = typename PrimitiveTypeTraits<PType>::ColumnType;
+    using ColumnType2 = typename PrimitiveTypeTraits<TYPE_TIMEV2>::ColumnType;
+    using InputType1 = typename 
PrimitiveTypeTraits<PType>::DataType::FieldType;
+    using InputType2 = typename 
PrimitiveTypeTraits<TYPE_TIMEV2>::DataType::FieldType;
+    using ReturnNativeType = InputType1;
+    using ReturnDataType = typename PrimitiveTypeTraits<PType>::DataType;
+
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 2; }
+    DataTypes get_variadic_argument_types_impl() const override {
+        return {std::make_shared<typename 
PrimitiveTypeTraits<PType>::DataType>(),
+                std::make_shared<typename 
PrimitiveTypeTraits<TYPE_TIMEV2>::DataType>()};
+    }
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) 
const override {
+        return std::make_shared<ReturnDataType>();
+    }
+
+    ReturnNativeType compute(const InputType1& arg1, const InputType2& arg2) 
const {
+        if constexpr (PType == TYPE_DATETIMEV2) {
+            DateV2Value<DateTimeV2ValueType> dtv1 =
+                    binary_cast<InputType1, 
DateV2Value<DateTimeV2ValueType>>(arg1);
+            auto tv2 = static_cast<TimeValue::TimeType>(arg2);
+            TimeInterval interval(TimeUnit::MICROSECOND, tv2, 
Impl::is_negative());
+            bool out_range = dtv1.template 
date_add_interval<TimeUnit::MICROSECOND>(interval);
+            if (!out_range) {

Review Comment:
   unlikely



##########
regression-test/suites/nereids_p0/sql_functions/datetime_functions/test_date_function_v2.groovy:
##########


Review Comment:
   加一下建表测试。vector和const的情况



##########
be/src/vec/functions/function_date_or_datetime_computation.h:
##########
@@ -1246,5 +1246,120 @@ class FunctionTime : public IFunction {
         return Status::OK();
     }
 };
+
+struct AddTimeImpl {
+    static constexpr auto name = "add_time";
+    static bool is_negative() { return false; }
+};
+
+struct SubTimeImpl {
+    static constexpr auto name = "sub_time";
+    static bool is_negative() { return true; }
+};
+
+template <PrimitiveType PType, typename Impl>
+class FunctionAddTime : public IFunction {
+public:
+    static constexpr auto name = Impl::name;
+    static constexpr PrimitiveType ReturnType = PType;
+    static constexpr PrimitiveType ArgType1 = PType;
+    static constexpr PrimitiveType ArgType2 = TYPE_TIMEV2;
+    using ColumnType1 = typename PrimitiveTypeTraits<PType>::ColumnType;
+    using ColumnType2 = typename PrimitiveTypeTraits<TYPE_TIMEV2>::ColumnType;
+    using InputType1 = typename 
PrimitiveTypeTraits<PType>::DataType::FieldType;
+    using InputType2 = typename 
PrimitiveTypeTraits<TYPE_TIMEV2>::DataType::FieldType;
+    using ReturnNativeType = InputType1;
+    using ReturnDataType = typename PrimitiveTypeTraits<PType>::DataType;
+
+    String get_name() const override { return name; }
+    size_t get_number_of_arguments() const override { return 2; }
+    DataTypes get_variadic_argument_types_impl() const override {
+        return {std::make_shared<typename 
PrimitiveTypeTraits<PType>::DataType>(),
+                std::make_shared<typename 
PrimitiveTypeTraits<TYPE_TIMEV2>::DataType>()};
+    }
+    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) 
const override {
+        return std::make_shared<ReturnDataType>();
+    }
+
+    ReturnNativeType compute(const InputType1& arg1, const InputType2& arg2) 
const {
+        if constexpr (PType == TYPE_DATETIMEV2) {
+            DateV2Value<DateTimeV2ValueType> dtv1 =
+                    binary_cast<InputType1, 
DateV2Value<DateTimeV2ValueType>>(arg1);
+            auto tv2 = static_cast<TimeValue::TimeType>(arg2);
+            TimeInterval interval(TimeUnit::MICROSECOND, tv2, 
Impl::is_negative());
+            bool out_range = dtv1.template 
date_add_interval<TimeUnit::MICROSECOND>(interval);
+            if (!out_range) {
+                throw Exception(ErrorCode::INVALID_ARGUMENT,
+                                "datetime value is out of range in function 
{}", name);
+            }
+            return binary_cast<DateV2Value<DateTimeV2ValueType>, 
ReturnNativeType>(dtv1);
+        } else if constexpr (PType == TYPE_TIMEV2) {
+            auto tv1 = static_cast<TimeValue::TimeType>(arg1);
+            auto tv2 = static_cast<TimeValue::TimeType>(arg2);
+            bool neg = std::string_view(name) == "sub_time";
+            double res = TimeValue::limit_with_bound(neg ? tv1 - tv2 : tv1 + 
tv2);
+            return res;
+        } else {
+            throw Exception(ErrorCode::INTERNAL_ERROR, "not support type for 
function {}", name);

Review Comment:
   FatalError



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to