Skip to content

Commit

Permalink
feat(expr): implement greatest and least function (#12838)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenym1 authored Oct 17, 2023
1 parent ddeea32 commit 1c2e5aa
Show file tree
Hide file tree
Showing 7 changed files with 303 additions and 125 deletions.
73 changes: 73 additions & 0 deletions e2e_test/batch/functions/greatest_least.slt.part
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
statement ok
create table t(id int, v1 int2, v2 int4, v3 int8);

statement ok
insert into t values (1, 1, 2, 3), (2, 2, NULL, 5), (3, NULL, NULL, 8), (4, NULL, NULL, NULL);

statement ok
flush;

statement error
select greatest(v1, '123');

statement error
select greatest();

statement error
select least();

query I
select greatest(1, 2, 3);
----
3

query I
select greatest(2);
----
2

query I
select least(1, 2, 3);
----
1

query I
select least(2);
----
2

query I
select greatest(v1, v2, v3) from t order by id;
----
3
5
8
NULL

query I
select least(v1, v2, v3) from t order by id;
----
1
2
8
NULL

query I
select greatest(7, v3) from t order by id;
----
7
7
8
7

query I
select least(NULL, v1, 2) from t order by id;
----
1
2
2
2


statement ok
drop table t;
2 changes: 2 additions & 0 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ message ExprNode {
LESS_THAN_OR_EQUAL = 11;
GREATER_THAN = 12;
GREATER_THAN_OR_EQUAL = 13;
GREATEST = 14;
LEAST = 15;
// logical operators
AND = 21;
OR = 22;
Expand Down
Loading

0 comments on commit 1c2e5aa

Please sign in to comment.