Skip to content

Commit

Permalink
[function](bitmap) add function alias bitmap_andnot and bitmap_andnot…
Browse files Browse the repository at this point in the history
…_count
  • Loading branch information
jacktengg committed Sep 22, 2023
1 parent cec3fcd commit 7b9a3ac
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 16 deletions.
7 changes: 5 additions & 2 deletions be/src/vec/functions/function_bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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>();
Expand Down
15 changes: 15 additions & 0 deletions be/test/vec/function/function_bitmap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{
"title": "BITMAP_AND_NOT_COUNT",
"title": "BITMAP_AND_NOT_COUNT,BITMAP_ANDNOT_COUNT",
"language": "en"
}
---
Expand All @@ -24,7 +24,7 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_not_count
## bitmap_and_not_count,bitmap_andnot_count
### description
#### Syntax

Expand All @@ -46,4 +46,4 @@ mysql> select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_strin

### keywords

BITMAP_AND_NOT_COUNT,BITMAP
BITMAP_AND_NOT_COUNT,BITMAP_ANDNOT_COUNT,BITMAP
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{
"title": "BITMAP_AND_NOT",
"title": "BITMAP_AND_NOT,BITMAP_ANDNOT",
"language": "en"
}
---
Expand All @@ -24,7 +24,7 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_not
## bitmap_and_not,bitmap_andnot
### description
#### Syntax

Expand Down Expand Up @@ -66,4 +66,4 @@ mysql> select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),NULL))

### keywords

BITMAP_AND_NOT,BITMAP
BITMAP_AND_NOT,BITMAP_ANDNOT,BITMAP
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{
"title": "BITMAP_AND_NOT_COUNT",
"title": "BITMAP_AND_NOT_COUNT,BITMAP_ANDNOT_COUNT",
"language": "zh-CN"
}
---
Expand All @@ -24,7 +24,7 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_not_count
## bitmap_and_not_count,bitmap_andnot_count
### description
#### Syntax

Expand All @@ -45,4 +45,4 @@ mysql> select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_strin

### keywords

BITMAP_AND_NOT_COUNT,BITMAP
BITMAP_AND_NOT_COUNT,BITMAP_ANDNOT_COUNT,BITMAP
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{
"title": "BITMAP_AND_NOT",
"title": "BITMAP_AND_NOT,BITMAP_ANDNOT",
"language": "zh-CN"
}
---
Expand All @@ -24,7 +24,7 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_not
## bitmap_and_not,bitmap_andnot
### description
#### Syntax

Expand Down Expand Up @@ -67,4 +67,4 @@ mysql> select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),NULL))

### keywords

BITMAP_AND_NOT,BITMAP
BITMAP_AND_NOT,BITMAP_ANDNOT,BITMAP
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
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;
Expand Down Expand Up @@ -446,7 +448,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"),
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
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;
Expand Down Expand Up @@ -580,6 +582,14 @@ default R visitBitmapAndNotCount(BitmapAndNotCount bitmapAndNotCount, C context)
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);
}
Expand Down
4 changes: 2 additions & 2 deletions gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@
[['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'], ''],
Expand All @@ -1845,7 +1845,7 @@
[['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'],
Expand Down
Loading

0 comments on commit 7b9a3ac

Please sign in to comment.