Skip to content

Commit

Permalink
[FIX](array-func) fix array() with decimal type (apache#23117)
Browse files Browse the repository at this point in the history
if we write sql with : select array(1.0,2.0,null, null,2.0)
here will pass arg type with uint8 to be which does not match array() func sign with deicmal, and make be core. so here should cast from be and make null tag to cast decimal type
  • Loading branch information
amorynan authored and airborne12 committed Aug 21, 2023
1 parent b87e2dc commit 177d7a8
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1669,10 +1669,6 @@ && collectChildReturnTypes()[0].isDecimalV3()) {
|| fnName.getFunction().equalsIgnoreCase("hist"))
&& children.get(0).getType().isDecimalV3() && args[ix].isDecimalV3()) {
continue;
} else if (fnName.getFunction().equalsIgnoreCase("array")
&& (children.get(0).getType().isDecimalV3() && args[ix].isDecimalV3()
|| children.get(0).getType().isDatetimeV2() && args[ix].isDatetimeV2())) {
continue;
} else if ((fnName.getFunction().equalsIgnoreCase("array_min") || fnName.getFunction()
.equalsIgnoreCase("array_max") || fnName.getFunction().equalsIgnoreCase("element_at"))
&& ((
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,54 @@
-- !sql --
[1, 1, 2, 2, 2, 2]

-- !sql_1 --
[1.0, 2.0, NULL, NULL, 2.0]

-- !sql_1 --
["a", "2.0", NULL, NULL, "2.0"]

-- !sql_1 --
[1, 2, NULL, NULL, 2]

-- !sql_2 --
[NULL, NULL, 1.0, 2.0, 2.0]

-- !sql_3 --
1.0

-- !sql_4 --
2.0

-- !sql_5 --
1.6

-- !sql_6 --
5.0

-- !sql_7 --
4.0

-- !sql_8 --
[1.0, 2.0, NULL]

-- !sql_9 --
[NULL, 1.0, 2.0]

-- !sql_10 --
[]

-- !sql_11 --
[1.0, 2.0, NULL]

-- !sql_14 --
[2.0, NULL, NULL, 2.0]

-- !sql_15 --
[1.0, 2.0, NULL, NULL]

-- !sql_16 --
[1.0, 2.0, NULL, NULL, 2.0, 1.0, 2.0, NULL, NULL, 2.0]

-- !sql --
true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ suite("test_array_functions_by_literal") {
// array_nested function
qt_sql "select a from (select array(1, 1, 2, 2, 2, 2) as a) t"

// array with decimal and other types
qt_sql_1 """select array(1.0,2.0,null, null,2.0);"""
qt_sql_1 """select array('a',2.0,null, null,2.0);"""
qt_sql_1 """select array(1,2.0,null, null,2.0);"""
qt_sql_2 """select array_sort(array(1.0,2.0,null, null,2.0));"""
qt_sql_3 """select array_min(array(1.0,2.0,null, null,2.0));"""
qt_sql_4 """select array_max(array(1.0,2.0,null, null,2.0));"""
qt_sql_5 """select array_avg(array(1.0,2.0,null, null,2.0));"""
qt_sql_6 """select array_sum(array(1.0,2.0,null, null,2.0));"""
qt_sql_7 """select array_product(array(1.0,2.0,null, null,2.0));"""
qt_sql_8 """select array_distinct(array(1.0,2.0,null, null,2.0));"""
qt_sql_9 """select array_intersect(array(1.0,2.0,null, null,2.0), array(1.0,2.0,null, null,2.0));"""
qt_sql_10 """select array_except(array(1.0,2.0,null, null,2.0), array(1.0,2.0,null, null,2.0));"""
qt_sql_11 """select array_union(array(1.0,2.0,null, null,2.0), array(1.0,2.0,null, null,2.0));"""
qt_sql_14 """select array_popfront(array(1.0,2.0,null, null,2.0));"""
qt_sql_15 """select array_popback(array(1.0,2.0,null, null,2.0));"""
qt_sql_16 """select array_concat(array(1.0,2.0,null, null,2.0), array(1.0,2.0,null, null,2.0));"""


// array_contains function
qt_sql "select array_contains([1,2,3], 1)"
Expand Down

0 comments on commit 177d7a8

Please sign in to comment.