You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/01/20 03:31:23 UTC
[doris] branch master updated: [feature](Nereids) add scalar function width_bucket (#16106)
This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 2ed4eac6f8 [feature](Nereids) add scalar function width_bucket (#16106)
2ed4eac6f8 is described below
commit 2ed4eac6f809ea98b82bfce6f88b7e5fc2d538ff
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Fri Jan 20 11:31:17 2023 +0800
[feature](Nereids) add scalar function width_bucket (#16106)
---
.../doris/catalog/BuiltinScalarFunctions.java | 2 +
.../expressions/functions/scalar/WidthBucket.java | 96 ++++++++++++++++++++++
.../expressions/visitor/ScalarFunctionVisitor.java | 5 ++
3 files changed, 103 insertions(+)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java
index 45104ab836..caf6fa48d0 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/BuiltinScalarFunctions.java
@@ -319,6 +319,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Weekday;
import org.apache.doris.nereids.trees.expressions.functions.scalar.WeeksAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.WeeksDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.WeeksSub;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.WidthBucket;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Year;
import org.apache.doris.nereids.trees.expressions.functions.scalar.YearCeil;
import org.apache.doris.nereids.trees.expressions.functions.scalar.YearFloor;
@@ -641,6 +642,7 @@ public class BuiltinScalarFunctions implements FunctionHelper {
scalar(WeeksAdd.class, "weeks_add"),
scalar(WeeksDiff.class, "weeks_diff"),
scalar(WeeksSub.class, "weeks_sub"),
+ scalar(WidthBucket.class, "width_bucket"),
scalar(Year.class, "year"),
scalar(YearCeil.class, "year_ceil"),
scalar(YearFloor.class, "year_floor"),
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java
new file mode 100644
index 0000000000..32a2860286
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/WidthBucket.java
@@ -0,0 +1,96 @@
+// 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.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.DoubleType;
+import org.apache.doris.nereids.types.FloatType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.SmallIntType;
+import org.apache.doris.nereids.types.TinyIntType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * WidthBucket.
+ */
+public class WidthBucket extends ScalarFunction implements ExplicitlyCastableSignature, PropagateNullable {
+ public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+ FunctionSignature.ret(BigIntType.INSTANCE).args(TinyIntType.INSTANCE,
+ TinyIntType.INSTANCE, TinyIntType.INSTANCE, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(SmallIntType.INSTANCE,
+ SmallIntType.INSTANCE, SmallIntType.INSTANCE, SmallIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(IntegerType.INSTANCE,
+ IntegerType.INSTANCE, IntegerType.INSTANCE, IntegerType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE,
+ BigIntType.INSTANCE, BigIntType.INSTANCE, BigIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(FloatType.INSTANCE,
+ FloatType.INSTANCE, FloatType.INSTANCE, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(DoubleType.INSTANCE,
+ DoubleType.INSTANCE, DoubleType.INSTANCE, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(DecimalV2Type.SYSTEM_DEFAULT,
+ DecimalV2Type.SYSTEM_DEFAULT, DecimalV2Type.SYSTEM_DEFAULT, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(DateType.INSTANCE,
+ DateType.INSTANCE, DateType.INSTANCE, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE,
+ DateV2Type.INSTANCE, DateV2Type.INSTANCE, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeType.INSTANCE,
+ DateTimeType.INSTANCE, DateTimeType.INSTANCE, TinyIntType.INSTANCE),
+ FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeV2Type.SYSTEM_DEFAULT,
+ DateTimeV2Type.SYSTEM_DEFAULT, DateTimeV2Type.SYSTEM_DEFAULT, TinyIntType.INSTANCE)
+ );
+
+ /**
+ * constructor with 4 argument.
+ */
+ public WidthBucket(Expression arg0, Expression arg1, Expression arg2, Expression arg3) {
+ super("width_bucket", arg0, arg1, arg2, arg3);
+ }
+
+ /**
+ * withChildren.
+ */
+ @Override
+ public WidthBucket withChildren(List<Expression> children) {
+ Preconditions.checkArgument(children.size() == 4);
+ return new WidthBucket(children.get(0), children.get(1), children.get(2), children.get(3));
+ }
+
+ @Override
+ public List<FunctionSignature> getSignatures() {
+ return SIGNATURES;
+ }
+
+ @Override
+ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+ return visitor.visitWidthBucket(this, context);
+ }
+}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
index 8c5be76f3d..cd2841dc87 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/visitor/ScalarFunctionVisitor.java
@@ -318,6 +318,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.Weekday;
import org.apache.doris.nereids.trees.expressions.functions.scalar.WeeksAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.WeeksDiff;
import org.apache.doris.nereids.trees.expressions.functions.scalar.WeeksSub;
+import org.apache.doris.nereids.trees.expressions.functions.scalar.WidthBucket;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Year;
import org.apache.doris.nereids.trees.expressions.functions.scalar.YearCeil;
import org.apache.doris.nereids.trees.expressions.functions.scalar.YearFloor;
@@ -1539,6 +1540,10 @@ public interface ScalarFunctionVisitor<R, C> {
return visitScalarFunction(weeksSub, context);
}
+ default R visitWidthBucket(WidthBucket widthBucket, C context) {
+ return visitScalarFunction(widthBucket, context);
+ }
+
default R visitYear(Year year, C context) {
return visitScalarFunction(year, context);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org