Skip to content

Commit

Permalink
feat(expr): support array_cat function and || operator for arrays (
Browse files Browse the repository at this point in the history
…#5060)

* add support for array_cat in frontend

Signed-off-by: Richard Chien <stdrc@outlook.com>

* implement ArrayCatExpression

Signed-off-by: Richard Chien <stdrc@outlook.com>

* wrap single element in frontend

Signed-off-by: Richard Chien <stdrc@outlook.com>

* add unit tests for array_cat function

Signed-off-by: Richard Chien <stdrc@outlook.com>

* fix clippy

Signed-off-by: Richard Chien <stdrc@outlook.com>

* add e2e tests

Signed-off-by: Richard Chien <stdrc@outlook.com>

* add `array_append` and `array_prepend` in frontend

Signed-off-by: Richard Chien <stdrc@outlook.com>

* reject (array, array) for array_prepend and array_append

Signed-off-by: Richard Chien <stdrc@outlook.com>

* implement all logic of array_cat, array_append, array_prepend

Signed-off-by: Richard Chien <stdrc@outlook.com>

* update tests

Signed-off-by: Richard Chien <stdrc@outlook.com>

* fix clippy warnings

Signed-off-by: Richard Chien <stdrc@outlook.com>

* fix e2e tests

Signed-off-by: Richard Chien <stdrc@outlook.com>

* add planner tests

Signed-off-by: Richard Chien <stdrc@outlook.com>

* fix warning

Signed-off-by: Richard Chien <stdrc@outlook.com>

* fix typo

Signed-off-by: Richard Chien <stdrc@outlook.com>

* improve error messages

Signed-off-by: Richard Chien <stdrc@outlook.com>

* update planner tests

Signed-off-by: Richard Chien <stdrc@outlook.com>

* use function pointer as op_func

Signed-off-by: Richard Chien <stdrc@outlook.com>

* return [[233]] for array_cat(null::int[][], array[233])

Signed-off-by: Richard Chien <stdrc@outlook.com>

* add a test for multidimentsional array

Signed-off-by: Richard Chien <stdrc@outlook.com>

* make `Operation` private

Signed-off-by: Richard Chien <stdrc@outlook.com>

* adjust match order

Signed-off-by: Richard Chien <stdrc@outlook.com>

* add comment

Signed-off-by: Richard Chien <stdrc@outlook.com>

Signed-off-by: Richard Chien <stdrc@outlook.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
stdrc and mergify[bot] authored Sep 5, 2022
1 parent cbd69ca commit 52b259a
Show file tree
Hide file tree
Showing 9 changed files with 812 additions and 21 deletions.
134 changes: 134 additions & 0 deletions e2e_test/batch/functions/array_concat.slt.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
query T
select array_cat(array[66], array[123]);
----
{66,123}

query T
select array_cat(array[66], null::int[]);
----
{66}

query T
select array_cat(null::int[], array[123]);
----
{123}

query T
select array_cat(array[array[66]], array[233]);
----
{{66},{233}}

query T
select array_cat(array[array[66]], null::int[]);
----
{{66}}

query T
select array_cat(null::int[][], array[233]);
----
{{233}}

query T
select array_cat(null::int[][], null::int[]);
----
NULL

query T
select array_append(array[66], 123);
----
{66,123}

query T
select array_append(array[66], null::int);
----
{66,NULL}

query T
select array_append(null::int[], 233);
----
{233}

query T
select array_append(null::int[], null::int);
----
{NULL}

query T
select array_cat(array[233], array[array[66]]);
----
{{233},{66}}

query T
select array_cat(null::int[], array[array[66]]);
----
{{66}}

query T
select array_cat(array[233], null::int[][]);
----
{{233}}

query T
select array_cat(null::int[], null::int[][]);
----
NULL

query T
select array_prepend(123, array[66]);
----
{123,66}

query T
select array_prepend(null::int, array[66]);
----
{NULL,66}

query T
select array_prepend(233, null::int[]);
----
{233}

query T
select array_prepend(null::int, null::int[]);
----
{NULL}

query T
select array[1,2,3] || array[4,5,6];
----
{1,2,3,4,5,6}

query T
select array[1,2,3] || 4;
----
{1,2,3,4}

query T
select 6 || array[7,8];
----
{6,7,8}

query T
select array[array[1,2]] || array[array[3,4]];
----
{{1,2},{3,4}}

query T
select array[array[1,2]] || array[3,4];
----
{{1,2},{3,4}}

query T
select array[1,2] || array[array[3,4]];
----
{{1,2},{3,4}}

query T
select '123'::varchar || array['abc'];
----
{123,abc}

query T
select array['abc'] || '123'::varchar;
----
{abc,123}
5 changes: 5 additions & 0 deletions e2e_test/batch/types/array_ty.slt.part
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ select max(ARRAY[1, v1*2]) from t;

statement ok
drop table t;

# Now we don't disallow arrays with unmatching dimensions in multidimensional arrays.
# This is different from PostgreSQL, we may want to change this in the future.
statement ok
select array[array[1,2], array[3]];
4 changes: 4 additions & 0 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ message ExprNode {
ARRAY = 521;
ARRAY_ACCESS = 522;
ROW = 523;
// Array functions
ARRAY_CAT = 531;
ARRAY_APPEND = 532;
ARRAY_PREPEND = 533;
// Search operator and Search ARGument
SEARCH = 998;
SARG = 999;
Expand Down
Loading

0 comments on commit 52b259a

Please sign in to comment.