Skip to content

Commit

Permalink
feat: add ARRAY_SIZE alias for ARRAY_LENGTH (#16685)
Browse files Browse the repository at this point in the history
Co-authored-by: Bohu <overred.shuttler@gmail.com>
  • Loading branch information
ding-young and BohuTANG authored Oct 25, 2024
1 parent 005b31c commit c1c0362
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/query/functions/src/scalars/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const ARRAY_SORT_FUNCTIONS: &[(&str, (bool, bool)); 4] = &[
pub fn register(registry: &mut FunctionRegistry) {
registry.register_aliases("contains", &["array_contains"]);
registry.register_aliases("get", &["array_get"]);
registry.register_aliases("length", &["array_length"]);
registry.register_aliases("length", &["array_length", "array_size"]);
registry.register_aliases("slice", &["array_slice"]);

register_array_aggr(registry);
Expand Down
2 changes: 2 additions & 0 deletions src/query/functions/tests/it/scalars/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fn test_length(file: &mut impl Write) {
run_ast(file, "length([1, 2, 3])", &[]);
run_ast(file, "length([true, false])", &[]);
run_ast(file, "length(['a', 'b', 'c', 'd'])", &[]);
run_ast(file, "array_size(['a', 'b', 'c', 'd'])", &[]);
run_ast(file, "array_length(['a', 'b', 'c', 'd'])", &[]);
}

fn test_range(file: &mut impl Write) {
Expand Down
18 changes: 18 additions & 0 deletions src/query/functions/tests/it/scalars/testdata/array.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,24 @@ output domain : {4..=4}
output : 4


ast : array_size(['a', 'b', 'c', 'd'])
raw expr : array_size(array('a', 'b', 'c', 'd'))
checked expr : length<T0=String><Array(T0)>(array<T0=String><T0, T0, T0, T0>("a", "b", "c", "d"))
optimized expr : 4_u64
output type : UInt64
output domain : {4..=4}
output : 4


ast : array_length(['a', 'b', 'c', 'd'])
raw expr : array_length(array('a', 'b', 'c', 'd'))
checked expr : length<T0=String><Array(T0)>(array<T0=String><T0, T0, T0, T0>("a", "b", "c", "d"))
optimized expr : 4_u64
output type : UInt64
output domain : {4..=4}
output : 4


ast : range(10, 20)
raw expr : range(10, 20)
checked expr : range<UInt64, UInt64>(to_uint64<UInt8>(10_u8), to_uint64<UInt8>(20_u8))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add -> plus
array_contains -> contains
array_get -> get
array_length -> length
array_size -> length
array_slice -> slice
bitmap_and_not -> bitmap_not
bitmap_cardinality -> bitmap_count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ select length(col1), length(col2), length(col3), length(col4) from t
----
4 4 1 1

query II
select array_length(col1), array_length(col2) from t
----
4 4

query II
select array_size(col3), array_size(col4) from t
----
1 1

query ITT
select get(col1, index - 7), get(col2, index - 8), get(col3, index - 9) from t
----
Expand Down Expand Up @@ -309,6 +319,11 @@ select length(col1), length(col2), length(col3), length(col4) from t
----
4 4 1 1

query IIII
select array_size(col1), array_size(col2), array_length(col3), array_length(col4) from t1
----
3 3 3 3

statement ok
DROP TABLE IF EXISTS t2

Expand Down

0 comments on commit c1c0362

Please sign in to comment.