Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/query/functions/src/scalars/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use databend_common_expression::types::AnyType;
use databend_common_expression::types::ArgType;
use databend_common_expression::types::ArrayType;
use databend_common_expression::types::Bitmap;
use databend_common_expression::types::BitmapType;
use databend_common_expression::types::BooleanType;
use databend_common_expression::types::DataType;
use databend_common_expression::types::DateType;
Expand Down Expand Up @@ -84,6 +85,7 @@ pub fn register(registry: &mut FunctionRegistry) {
register_tuple_cmp(registry);
register_like(registry);
register_interval_cmp(registry);
register_bitmap_cmp(registry);
}

pub const ALL_COMP_FUNC_NAMES: &[&str] = &["eq", "noteq", "lt", "lte", "gt", "gte"];
Expand Down Expand Up @@ -1287,3 +1289,16 @@ fn vectorize_regexp(
}
}
}

fn register_bitmap_cmp(registry: &mut FunctionRegistry) {
registry.register_comparison_2_arg::<BitmapType, BitmapType, _, _>(
"eq",
|_, _, _| FunctionDomain::Full,
|lhs, rhs, _| lhs == rhs,
);
registry.register_comparison_2_arg::<BitmapType, BitmapType, _, _>(
"noteq",
|_, _, _| FunctionDomain::Full,
|lhs, rhs, _| lhs != rhs,
);
}
24 changes: 24 additions & 0 deletions src/query/functions/tests/it/scalars/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ fn test_eq(file: &mut impl Write) {
];
run_ast(file, "parse_json(lhs) = parse_json(rhs)", &table);
run_ast(file, "lhs = rhs", &table);

run_ast(
file,
"build_bitmap([3, 7, 9]) = build_bitmap([3, 7, 9])",
&[],
);
run_ast(
file,
"build_bitmap([3, 7, 9]) = build_bitmap([3, 7, 10])",
&[],
);
run_ast(file, "null = build_bitmap([3, 7, 10])", &[]);
}

fn test_noteq(file: &mut impl Write) {
Expand Down Expand Up @@ -186,6 +198,18 @@ fn test_noteq(file: &mut impl Write) {
];
run_ast(file, "parse_json(lhs) != parse_json(rhs)", &table);
run_ast(file, "lhs != rhs", &table);

run_ast(
file,
"build_bitmap([3, 7, 9]) != build_bitmap([3, 7, 9])",
&[],
);
run_ast(
file,
"build_bitmap([3, 7, 9]) != build_bitmap([3, 7, 10])",
&[],
);
run_ast(file, "null != build_bitmap([3, 7, 10])", &[]);
}

fn test_lt(file: &mut impl Write) {
Expand Down
58 changes: 56 additions & 2 deletions src/query/functions/tests/it/scalars/testdata/comparison.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ candidate functions:
eq(Variant, Variant) :: Boolean : unable to unify `Tuple(UInt8, String)` with `Variant`
eq(Variant NULL, Variant NULL) :: Boolean NULL : unable to unify `Tuple(UInt8, String)` with `Variant`
eq(String, String) :: Boolean : unable to unify `Tuple(UInt8, String)` with `String`
... and 76 more
... and 78 more



Expand Down Expand Up @@ -312,6 +312,33 @@ evaluation (internal):
+--------+--------------------------------------------------------------------------------------------------------------------+


ast : build_bitmap([3, 7, 9]) = build_bitmap([3, 7, 9])
raw expr : eq(build_bitmap(array(3, 7, 9)), build_bitmap(array(3, 7, 9)))
checked expr : eq<Bitmap, Bitmap>(build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 9_u8) AS Array(UInt8 NULL))), build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 9_u8) AS Array(UInt8 NULL))))
optimized expr : true
output type : Boolean
output domain : {TRUE}
output : true


ast : build_bitmap([3, 7, 9]) = build_bitmap([3, 7, 10])
raw expr : eq(build_bitmap(array(3, 7, 9)), build_bitmap(array(3, 7, 10)))
checked expr : eq<Bitmap, Bitmap>(build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 9_u8) AS Array(UInt8 NULL))), build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 10_u8) AS Array(UInt8 NULL))))
optimized expr : false
output type : Boolean
output domain : {FALSE}
output : false


ast : null = build_bitmap([3, 7, 10])
raw expr : eq(NULL, build_bitmap(array(3, 7, 10)))
checked expr : eq<Bitmap NULL, Bitmap NULL>(CAST<NULL>(NULL AS Bitmap NULL), CAST<Bitmap>(build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 10_u8) AS Array(UInt8 NULL))) AS Bitmap NULL))
optimized expr : NULL
output type : Boolean NULL
output domain : {NULL}
output : NULL


ast : '1'!='2'
raw expr : noteq('1', '2')
checked expr : noteq<String, String>("1", "2")
Expand Down Expand Up @@ -429,7 +456,7 @@ candidate functions:
noteq(Variant, Variant) :: Boolean : unable to unify `Tuple(UInt8, String)` with `Variant`
noteq(Variant NULL, Variant NULL) :: Boolean NULL : unable to unify `Tuple(UInt8, String)` with `Variant`
noteq(String, String) :: Boolean : unable to unify `Tuple(UInt8, String)` with `String`
... and 76 more
... and 78 more



Expand Down Expand Up @@ -544,6 +571,33 @@ evaluation (internal):
+--------+------------------------------------------------------------------------------+


ast : build_bitmap([3, 7, 9]) != build_bitmap([3, 7, 9])
raw expr : noteq(build_bitmap(array(3, 7, 9)), build_bitmap(array(3, 7, 9)))
checked expr : noteq<Bitmap, Bitmap>(build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 9_u8) AS Array(UInt8 NULL))), build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 9_u8) AS Array(UInt8 NULL))))
optimized expr : false
output type : Boolean
output domain : {FALSE}
output : false


ast : build_bitmap([3, 7, 9]) != build_bitmap([3, 7, 10])
raw expr : noteq(build_bitmap(array(3, 7, 9)), build_bitmap(array(3, 7, 10)))
checked expr : noteq<Bitmap, Bitmap>(build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 9_u8) AS Array(UInt8 NULL))), build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 10_u8) AS Array(UInt8 NULL))))
optimized expr : true
output type : Boolean
output domain : {TRUE}
output : true


ast : null != build_bitmap([3, 7, 10])
raw expr : noteq(NULL, build_bitmap(array(3, 7, 10)))
checked expr : noteq<Bitmap NULL, Bitmap NULL>(CAST<NULL>(NULL AS Bitmap NULL), CAST<Bitmap>(build_bitmap<Array(UInt8 NULL)>(CAST<Array(UInt8)>(array<T0=UInt8><T0, T0, T0>(3_u8, 7_u8, 10_u8) AS Array(UInt8 NULL))) AS Bitmap NULL))
optimized expr : NULL
output type : Boolean NULL
output domain : {NULL}
output : NULL


ast : '1'<'2'
raw expr : lt('1', '2')
checked expr : lt<String, String>("1", "2")
Expand Down
12 changes: 12 additions & 0 deletions src/query/functions/tests/it/scalars/testdata/function_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,8 @@ Functions overloads:
77 eq FACTORY
78 eq(Interval, Interval) :: Boolean
79 eq(Interval NULL, Interval NULL) :: Boolean NULL
80 eq(Bitmap, Bitmap) :: Boolean
81 eq(Bitmap NULL, Bitmap NULL) :: Boolean NULL
0 exp(UInt8) :: Float64
1 exp(UInt8 NULL) :: Float64 NULL
2 exp(UInt16) :: Float64
Expand Down Expand Up @@ -2093,6 +2095,8 @@ Functions overloads:
77 gt FACTORY
78 gt(Interval, Interval) :: Boolean
79 gt(Interval NULL, Interval NULL) :: Boolean NULL
80 gt(Bitmap, Bitmap) :: Boolean
81 gt(Bitmap NULL, Bitmap NULL) :: Boolean NULL
0 gte(Variant, Variant) :: Boolean
1 gte(Variant NULL, Variant NULL) :: Boolean NULL
2 gte(String, String) :: Boolean
Expand Down Expand Up @@ -2173,6 +2177,8 @@ Functions overloads:
77 gte FACTORY
78 gte(Interval, Interval) :: Boolean
79 gte(Interval NULL, Interval NULL) :: Boolean NULL
80 gte(Bitmap, Bitmap) :: Boolean
81 gte(Bitmap NULL, Bitmap NULL) :: Boolean NULL
0 h3_cell_area_m2(UInt64) :: Float64
1 h3_cell_area_m2(UInt64 NULL) :: Float64 NULL
0 h3_cell_area_rads2(UInt64) :: Float64
Expand Down Expand Up @@ -2566,6 +2572,8 @@ Functions overloads:
77 lt FACTORY
78 lt(Interval, Interval) :: Boolean
79 lt(Interval NULL, Interval NULL) :: Boolean NULL
80 lt(Bitmap, Bitmap) :: Boolean
81 lt(Bitmap NULL, Bitmap NULL) :: Boolean NULL
0 lte(Variant, Variant) :: Boolean
1 lte(Variant NULL, Variant NULL) :: Boolean NULL
2 lte(String, String) :: Boolean
Expand Down Expand Up @@ -2646,6 +2654,8 @@ Functions overloads:
77 lte FACTORY
78 lte(Interval, Interval) :: Boolean
79 lte(Interval NULL, Interval NULL) :: Boolean NULL
80 lte(Bitmap, Bitmap) :: Boolean
81 lte(Bitmap NULL, Bitmap NULL) :: Boolean NULL
0 ltrim(String) :: String
1 ltrim(String NULL) :: String NULL
2 ltrim(String, String) :: String
Expand Down Expand Up @@ -3415,6 +3425,8 @@ Functions overloads:
77 noteq FACTORY
78 noteq(Interval, Interval) :: Boolean
79 noteq(Interval NULL, Interval NULL) :: Boolean NULL
80 noteq(Bitmap, Bitmap) :: Boolean
81 noteq(Bitmap NULL, Bitmap NULL) :: Boolean NULL
0 now() :: Timestamp
0 object_construct FACTORY
0 object_construct_keep_null FACTORY
Expand Down
8 changes: 4 additions & 4 deletions src/query/functions/tests/it/type_check/testdata/decimal.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3152,7 +3152,7 @@ candidate functions:
eq(Variant, Variant) :: Boolean : unable to unify `Decimal(38, 0)` with `Variant`
eq(Variant NULL, Variant NULL) :: Boolean NULL : unable to unify `Decimal(38, 0)` with `Variant`
eq(String, String) :: Boolean : unable to unify `Decimal(38, 0)` with `String`
... and 75 more
... and 77 more



Expand Down Expand Up @@ -3502,7 +3502,7 @@ candidate functions:
eq(Variant, Variant) :: Boolean : unable to unify `Decimal(38, 0) NULL` with `Variant`
eq(Variant NULL, Variant NULL) :: Boolean NULL : unable to unify `Decimal(38, 0)` with `Variant`
eq(String, String) :: Boolean : unable to unify `Decimal(38, 0) NULL` with `String`
... and 75 more
... and 77 more



Expand Down Expand Up @@ -3852,7 +3852,7 @@ candidate functions:
eq(Variant, Variant) :: Boolean : unable to unify `Decimal(76, 0)` with `Variant`
eq(Variant NULL, Variant NULL) :: Boolean NULL : unable to unify `Decimal(76, 0)` with `Variant`
eq(String, String) :: Boolean : unable to unify `Decimal(76, 0)` with `String`
... and 75 more
... and 77 more



Expand Down Expand Up @@ -4202,7 +4202,7 @@ candidate functions:
eq(Variant, Variant) :: Boolean : unable to unify `Decimal(76, 0) NULL` with `Variant`
eq(Variant NULL, Variant NULL) :: Boolean NULL : unable to unify `Decimal(76, 0)` with `Variant`
eq(String, String) :: Boolean : unable to unify `Decimal(76, 0) NULL` with `String`
... and 75 more
... and 77 more



Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Copyright 2023 Databend Cloud
##
## Licensed under the Elastic 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
##
## https://www.elastic.co/licensing/elastic-license
##
## 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.

statement ok
create or replace database issue_19037;

statement ok
use issue_19037;

statement ok
create or replace table t( a int, b BITMAP);

statement ok
create or replace stream s on table t APPEND_ONLY = false;

statement ok
insert into t values(1, BUILD_BITMAP([3, 7, 9]));

query T
select count() from s with consume;
----
1

statement ok
update t set b = BUILD_BITMAP([3, 7, 10]) where a = 1;

query T
select count() from s with consume;
----
2
Loading