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

commit cff1714e529263d5e18fa33d0d3452e2d78cd486
Author: TengJianPing <[email protected]>
AuthorDate: Fri Sep 22 12:18:31 2023 +0800

    [function](bitmap) add function alias bitmap_andnot and bitmap_andnot_count 
(#24771)
---
 be/src/vec/functions/function_bitmap.cpp           |  7 ++-
 be/test/vec/function/function_bitmap_test.cpp      | 15 +++++
 .../doris/catalog/BuiltinScalarFunctions.java      |  4 ++
 .../functions/scalar/BitmapAndNotAlias.java        | 68 ++++++++++++++++++++
 .../functions/scalar/BitmapAndNotCountAlias.java   | 73 ++++++++++++++++++++++
 .../expressions/visitor/ScalarFunctionVisitor.java | 10 +++
 gensrc/script/doris_builtins_functions.py          |  4 +-
 .../data/nereids_function_p0/scalar_function/B.out | 58 +++++++++++++++++
 .../bitmap_functions/test_bitmap_function.out      |  9 +++
 .../nereids_function_p0/scalar_function/B.groovy   |  6 ++
 .../bitmap_functions/test_bitmap_function.groovy   | 10 +++
 11 files changed, 260 insertions(+), 4 deletions(-)

diff --git a/be/src/vec/functions/function_bitmap.cpp 
b/be/src/vec/functions/function_bitmap.cpp
index 038741c3947..7f90db70abd 100644
--- a/be/src/vec/functions/function_bitmap.cpp
+++ b/be/src/vec/functions/function_bitmap.cpp
@@ -724,13 +724,14 @@ Status execute_bitmap_op_count_null_to_zero(
     return Status::OK();
 }
 
+template <typename FunctionName>
 class FunctionBitmapAndNotCount : public IFunction {
 public:
     using LeftDataType = DataTypeBitMap;
     using RightDataType = DataTypeBitMap;
     using ResultDataType = typename BitmapAndNotCount<LeftDataType, 
RightDataType>::ResultDataType;
 
-    static constexpr auto name = "bitmap_and_not_count";
+    static constexpr auto name = FunctionName::name;
     static FunctionPtr create() { return 
std::make_shared<FunctionBitmapAndNotCount>(); }
     String get_name() const override { return name; }
     size_t get_number_of_arguments() const override { return 2; }
@@ -1297,7 +1298,9 @@ void register_function_bitmap(SimpleFunctionFactory& 
factory) {
     factory.register_function<FunctionBitmapToString>();
     factory.register_function<FunctionBitmapNot>();
     factory.register_function<FunctionBitmapAndNot>();
-    factory.register_function<FunctionBitmapAndNotCount>();
+    factory.register_alias(NameBitmapAndNot::name, "bitmap_andnot");
+    
factory.register_function<FunctionBitmapAndNotCount<NameBitmapAndNotCount>>();
+    factory.register_alias(NameBitmapAndNotCount::name, "bitmap_andnot_count");
     factory.register_function<FunctionBitmapContains>();
     factory.register_function<FunctionBitmapRemove>();
     factory.register_function<FunctionBitmapHasAny>();
diff --git a/be/test/vec/function/function_bitmap_test.cpp 
b/be/test/vec/function/function_bitmap_test.cpp
index 75bbe32527c..ba286bf5ac5 100644
--- a/be/test/vec/function/function_bitmap_test.cpp
+++ b/be/test/vec/function/function_bitmap_test.cpp
@@ -430,6 +430,21 @@ TEST(function_bitmap_test, function_bitmap_and_not_count) {
 
     check_function<DataTypeInt64, true>(func_name, input_types, data_set);
 }
+TEST(function_bitmap_test, function_bitmap_and_not_count_alias) {
+    std::string func_name = "bitmap_andnot_count";
+    InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap};
+    BitmapValue bitmap1({1, 2, 3});
+    BitmapValue bitmap2({3, 4, std::numeric_limits<uint64_t>::min()});
+    BitmapValue bitmap3({33, 5, std::numeric_limits<uint64_t>::max()});
+    BitmapValue empty_bitmap;
+
+    DataSet data_set = {{{&bitmap1, &empty_bitmap}, (int64_t)3}, //1,2,3
+                        {{&bitmap2, Null()}, (int64_t)0},
+                        {{&bitmap2, &bitmap3}, (int64_t)3},  //0,3,4
+                        {{&bitmap1, &bitmap2}, (int64_t)2}}; //1,2
+
+    check_function<DataTypeInt64, true>(func_name, input_types, data_set);
+}
 TEST(function_bitmap_test, function_bitmap_has_all) {
     std::string func_name = "bitmap_has_all";
     InputTypeSet input_types = {TypeIndex::BitMap, TypeIndex::BitMap};
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 b4d5e0e8117..96111abd949 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
@@ -56,7 +56,9 @@ import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitLength;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAnd;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndCount;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNot;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNotAlias;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNotCount;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNotCountAlias;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapContains;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapCount;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapEmpty;
@@ -404,7 +406,9 @@ public class BuiltinScalarFunctions implements 
FunctionHelper {
             scalar(BitmapAnd.class, "bitmap_and"),
             scalar(BitmapAndCount.class, "bitmap_and_count"),
             scalar(BitmapAndNot.class, "bitmap_and_not"),
+            scalar(BitmapAndNotAlias.class, "bitmap_andnot"),
             scalar(BitmapAndNotCount.class, "bitmap_and_not_count"),
+            scalar(BitmapAndNotCountAlias.class, "bitmap_andnot_count"),
             scalar(BitmapContains.class, "bitmap_contains"),
             scalar(BitmapCount.class, "bitmap_count"),
             scalar(BitmapEmpty.class, "bitmap_empty"),
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotAlias.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotAlias.java
new file mode 100644
index 00000000000..08cd20e199f
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotAlias.java
@@ -0,0 +1,68 @@
+// 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.BinaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.BitmapType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ScalarFunction 'bitmap_and_not'. This class is generated by 
GenerateFunction.
+ */
+public class BitmapAndNotAlias extends ScalarFunction
+        implements BinaryExpression, ExplicitlyCastableSignature, 
PropagateNullable {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(BitmapType.INSTANCE).args(BitmapType.INSTANCE, 
BitmapType.INSTANCE)
+    );
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public BitmapAndNotAlias(Expression arg0, Expression arg1) {
+        super("bitmap_andnot", arg0, arg1);
+    }
+
+    /**
+     * withChildren.
+     */
+    @Override
+    public BitmapAndNotAlias withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() == 2);
+        return new BitmapAndNotAlias(children.get(0), children.get(1));
+    }
+
+    @Override
+    public List<FunctionSignature> getSignatures() {
+        return SIGNATURES;
+    }
+
+    @Override
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitBitmapAndNotAlias(this, context);
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotCountAlias.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotCountAlias.java
new file mode 100644
index 00000000000..f71bc2cbe67
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/BitmapAndNotCountAlias.java
@@ -0,0 +1,73 @@
+// 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.shape.BinaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.BitmapType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * ScalarFunction 'bitmap_and_not_count'. This class is generated by 
GenerateFunction.
+ */
+public class BitmapAndNotCountAlias extends ScalarFunction
+        implements BinaryExpression, ExplicitlyCastableSignature {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            
FunctionSignature.ret(BigIntType.INSTANCE).args(BitmapType.INSTANCE, 
BitmapType.INSTANCE)
+    );
+
+    /**
+     * constructor with 2 arguments.
+     */
+    public BitmapAndNotCountAlias(Expression arg0, Expression arg1) {
+        super("bitmap_andnot_count", arg0, arg1);
+    }
+
+    /**
+     * withChildren.
+     */
+    @Override
+    public BitmapAndNotCountAlias withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() == 2);
+        return new BitmapAndNotCountAlias(children.get(0), children.get(1));
+    }
+
+    @Override
+    public List<FunctionSignature> getSignatures() {
+        return SIGNATURES;
+    }
+
+    @Override
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitBitmapAndNotCountAlias(this, context);
+    }
+
+    @Override
+    public boolean nullable() {
+        return children().stream().anyMatch(Expression::nullable);
+    }
+}
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 efff54db6e4..5570a540c8e 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
@@ -60,7 +60,9 @@ import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitLength;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAnd;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndCount;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNot;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNotAlias;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNotCount;
+import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapAndNotCountAlias;
 import 
org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapContains;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapCount;
 import org.apache.doris.nereids.trees.expressions.functions.scalar.BitmapEmpty;
@@ -516,6 +518,14 @@ public interface ScalarFunctionVisitor<R, C> {
         return visitScalarFunction(bitmapAndNotCount, context);
     }
 
+    default R visitBitmapAndNotAlias(BitmapAndNotAlias bitmapAndNotAlias, C 
context) {
+        return visitScalarFunction(bitmapAndNotAlias, context);
+    }
+
+    default R visitBitmapAndNotCountAlias(BitmapAndNotCountAlias 
bitmapAndNotCountAlias, C context) {
+        return visitScalarFunction(bitmapAndNotCountAlias, context);
+    }
+
     default R visitBitmapContains(BitmapContains bitmapContains, C context) {
         return visitScalarFunction(bitmapContains, context);
     }
diff --git a/gensrc/script/doris_builtins_functions.py 
b/gensrc/script/doris_builtins_functions.py
index d0a86533d1e..cb8dcb3155a 100644
--- a/gensrc/script/doris_builtins_functions.py
+++ b/gensrc/script/doris_builtins_functions.py
@@ -1786,7 +1786,7 @@ visible_functions = {
         [['bitmap_hash'], 'BITMAP', ['STRING'], 'ALWAYS_NOT_NULLABLE'],
         [['bitmap_hash64'], 'BITMAP', ['STRING'], 'ALWAYS_NOT_NULLABLE'],
         [['bitmap_count'], 'BIGINT', ['BITMAP'], 'ALWAYS_NOT_NULLABLE'],
-        [['bitmap_and_not_count'], 'BIGINT', ['BITMAP','BITMAP'], ''],
+        [['bitmap_and_not_count', 'bitmap_andnot_count'], 'BIGINT', 
['BITMAP','BITMAP'], ''],
         [['bitmap_empty'], 'BITMAP', [], 'ALWAYS_NOT_NULLABLE'],
         [['bitmap_or'], 'BITMAP', ['BITMAP','BITMAP','...'], ''],
         [['bitmap_or'], 'BITMAP', ['BITMAP','BITMAP'], ''],
@@ -1797,7 +1797,7 @@ visible_functions = {
         [['bitmap_not'], 'BITMAP', ['BITMAP','BITMAP'], ''],
         [['bitmap_and'], 'BITMAP', ['BITMAP','BITMAP','...'], ''],
         [['bitmap_and'], 'BITMAP', ['BITMAP','BITMAP'], ''],
-        [['bitmap_and_not'], 'BITMAP', ['BITMAP','BITMAP'], ''],
+        [['bitmap_and_not', 'bitmap_andnot'], 'BITMAP', ['BITMAP','BITMAP'], 
''],
         [['bitmap_to_string'], 'STRING', ['BITMAP'], ''],
         [['bitmap_from_string'], 'BITMAP', ['VARCHAR'], 'ALWAYS_NULLABLE'],
         [['bitmap_from_string'], 'BITMAP', ['STRING'], 'ALWAYS_NULLABLE'],
diff --git a/regression-test/data/nereids_function_p0/scalar_function/B.out 
b/regression-test/data/nereids_function_p0/scalar_function/B.out
index 04a79b36a7a..a896096e16d 100644
--- a/regression-test/data/nereids_function_p0/scalar_function/B.out
+++ b/regression-test/data/nereids_function_p0/scalar_function/B.out
@@ -202,6 +202,64 @@
 0
 0
 
+-- !sql_bitmap_andnot_Bitmap_Bitmap --
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+
+-- !sql_bitmap_andnot_Bitmap_Bitmap_notnull --
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+\N
+
+-- !sql_bitmap_andnot_count_Bitmap_Bitmap --
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+
+-- !sql_bitmap_andnot_count_Bitmap_Bitmap_notnull --
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+0
+
 -- !sql_bitmap_contains_Bitmap_BigInt --
 \N
 true
diff --git 
a/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
 
b/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
index d6ffc0d621a..8afca0f9838 100644
--- 
a/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/bitmap_functions/test_bitmap_function.out
@@ -273,6 +273,12 @@ true
 3      0
 4      0
 
+-- !sql_bitmap_andnot_count3 --
+1      1
+2      1
+3      0
+4      0
+
 -- !sql_bitmap_and_count8 --
 1      2
 2      2
@@ -336,6 +342,9 @@ true
 -- !sql --
 2
 
+-- !sql_bitmap_andnot --
+2
+
 -- !sql_bitmap_and_not_count1 --
 2
 
diff --git 
a/regression-test/suites/nereids_function_p0/scalar_function/B.groovy 
b/regression-test/suites/nereids_function_p0/scalar_function/B.groovy
index bedb440b1cc..b07e2647f08 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/B.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/B.groovy
@@ -33,6 +33,12 @@ suite("nereids_scalar_fn_B") {
        qt_sql_bitmap_and_not_Bitmap_Bitmap_notnull "select 
bitmap_and_not(to_bitmap(kbint), to_bitmap(kbint)) from fn_test_not_nullable 
order by kbint, kbint"
        qt_sql_bitmap_and_not_count_Bitmap_Bitmap "select 
bitmap_and_not_count(to_bitmap(kbint), to_bitmap(kbint)) from fn_test order by 
kbint, kbint"
        qt_sql_bitmap_and_not_count_Bitmap_Bitmap_notnull "select 
bitmap_and_not_count(to_bitmap(kbint), to_bitmap(kbint)) from 
fn_test_not_nullable order by kbint, kbint"
+
+       qt_sql_bitmap_andnot_Bitmap_Bitmap "select 
bitmap_andnot(to_bitmap(kbint), to_bitmap(kbint)) from fn_test order by kbint, 
kbint"
+       qt_sql_bitmap_andnot_Bitmap_Bitmap_notnull "select 
bitmap_andnot(to_bitmap(kbint), to_bitmap(kbint)) from fn_test_not_nullable 
order by kbint, kbint"
+       qt_sql_bitmap_andnot_count_Bitmap_Bitmap "select 
bitmap_andnot_count(to_bitmap(kbint), to_bitmap(kbint)) from fn_test order by 
kbint, kbint"
+       qt_sql_bitmap_andnot_count_Bitmap_Bitmap_notnull "select 
bitmap_andnot_count(to_bitmap(kbint), to_bitmap(kbint)) from 
fn_test_not_nullable order by kbint, kbint"
+
        qt_sql_bitmap_contains_Bitmap_BigInt "select 
bitmap_contains(to_bitmap(kbint), kbint) from fn_test order by kbint, kbint"
        qt_sql_bitmap_contains_Bitmap_BigInt_notnull "select 
bitmap_contains(to_bitmap(kbint), kbint) from fn_test_not_nullable order by 
kbint, kbint"
        qt_sql_bitmap_count_Bitmap "select bitmap_count(to_bitmap(kbint)) from 
fn_test order by kbint"
diff --git 
a/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
index 709d2897212..36e36d67624 100644
--- 
a/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/bitmap_functions/test_bitmap_function.groovy
@@ -386,6 +386,15 @@ suite("test_bitmap_function") {
             on l.dt = r.dt
         order by l.dt, count
     """
+    qt_sql_bitmap_andnot_count3 """
+        select
+            l.dt,
+            bitmap_andnot_count(l.id, r.id) count
+        from
+            test_bitmap1 l left join test_bitmap2 r
+            on l.dt = r.dt
+        order by l.dt, count
+    """
     qt_sql_bitmap_and_count8 """
         select
             l.dt,
@@ -519,6 +528,7 @@ suite("test_bitmap_function") {
 
     // BITMAP_AND_NOT
     qt_sql """ select 
bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')))
 cnt """
+    qt_sql_bitmap_andnot """ select 
bitmap_count(bitmap_andnot(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')))
 cnt """
 
     // BITMAP_AND_NOT_COUNT
     qt_sql_bitmap_and_not_count1 """ select 
bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) 
cnt """


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

Reply via email to