You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2023/01/05 05:36:05 UTC

[GitHub] [doris] morrySnow commented on a diff in pull request #15619: [Feature](Nereids)add some scalar functions

morrySnow commented on code in PR #15619:
URL: https://github.com/apache/doris/pull/15619#discussion_r1062122056


##########
fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSignature.java:
##########
@@ -113,4 +118,34 @@ public FunctionSignature varArgs(AbstractDataType...argTypes) {
             return FunctionSignature.of(returnType, true, argTypes);
         }
     }
+
+    public static class MultiFuncSigBuilder {

Review Comment:
   static number initialized when class loading. It has mulit-thread problem. So i don't think use this singleton object to build multi signature is a good idea.



##########
regression-test/suites/nereids_syntax_p0/function.groovy:
##########
@@ -89,5 +89,59 @@ suite("function") {
         sql """select b.number from (select * from numbers(number = 3) a)b"""
         result([[0L], [1L], [2L]])
     }
+
+    // scalar function
+    sql """
+        DROP TABLE IF EXISTS running_difference_test
+    """
+
+    sql """
+        CREATE TABLE running_difference_test (
+            `id` int NOT NULL COMMENT 'id' ,
+            `day` date COMMENT 'day', 
+            `time_val` datetime COMMENT 'time_val',
+            `double_num` double NULL COMMENT 'doublenum'
+        )
+        DUPLICATE KEY(id) 
+        DISTRIBUTED BY HASH(id) BUCKETS 3 
+        PROPERTIES ( 
+            "replication_num" = "1"
+        );
+    """
+
+    sql """                                       
+        INSERT into running_difference_test values 
+            ('1', '2022-10-28', '2022-03-12 10:41:00', null),
+            ('2','2022-10-27', '2022-03-12 10:41:02', 2.6),
+            ('3','2022-10-28', '2022-03-12 10:41:03', 2.5),
+            ('4','2022-9-29', '2022-03-12 10:41:03', null),
+            ('5','2022-10-31', '2022-03-12 10:42:01', 3.3),
+            ('6', '2022-11-08', '2022-03-12 11:05:04', 4.7); 

Review Comment:
   maybe u should test all type running_differece supported.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/RunningDifference.java:
##########
@@ -0,0 +1,92 @@
+// 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.
+
+package org.apache.doris.nereids.trees.expressions.functions.scalar;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.functions.PropagateNullable;
+import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.DateTimeType;
+import org.apache.doris.nereids.types.DateTimeV2Type;
+import org.apache.doris.nereids.types.DateType;
+import org.apache.doris.nereids.types.DateV2Type;
+import org.apache.doris.nereids.types.DecimalV2Type;
+import org.apache.doris.nereids.types.DecimalV3Type;
+import org.apache.doris.nereids.types.DoubleType;
+import org.apache.doris.nereids.types.FloatType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.LargeIntType;
+import org.apache.doris.nereids.types.SmallIntType;
+import org.apache.doris.nereids.types.TinyIntType;
+
+import com.google.common.base.Preconditions;
+
+import java.util.List;
+
+/**
+ * running_difference
+ */
+public class RunningDifference extends ScalarFunction implements UnaryExpression, ExplicitlyCastableSignature,
+        PropagateNullable {
+    public static final List<FunctionSignature> SIGNATURES = FunctionSignature.multi()
+            .ret(SmallIntType.INSTANCE).args(TinyIntType.INSTANCE)
+            .ret(IntegerType.INSTANCE).args(SmallIntType.INSTANCE)
+            .ret(BigIntType.INSTANCE).args(IntegerType.INSTANCE)
+            .ret(LargeIntType.INSTANCE).args(BigIntType.INSTANCE)
+            .ret(LargeIntType.INSTANCE).args(LargeIntType.INSTANCE)
+            .ret(DoubleType.INSTANCE).args(FloatType.INSTANCE)
+            .ret(DoubleType.INSTANCE).args(DoubleType.INSTANCE)
+            .ret(DecimalV2Type.SYSTEM_DEFAULT).args(DecimalV2Type.SYSTEM_DEFAULT)
+            .ret(DecimalV3Type.DEFAULT_DECIMAL32).args(DecimalV3Type.DEFAULT_DECIMAL32)
+            .ret(DecimalV3Type.DEFAULT_DECIMAL64).args(DecimalV3Type.DEFAULT_DECIMAL64)
+            .ret(DecimalV3Type.DEFAULT_DECIMAL128).args(DecimalV3Type.DEFAULT_DECIMAL128)

Review Comment:
   remove decimal v3 type



-- 
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-unsubscribe@doris.apache.org

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


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