Skip to content

Commit 87b0bb7

Browse files
jacktenggYour Name
authored andcommitted
[fix](posexplode) fix return type check failure (#59734)
1 parent 772044e commit 87b0bb7

File tree

4 files changed

+223
-8
lines changed

4 files changed

+223
-8
lines changed

be/src/vec/functions/function_fake.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,20 @@ struct FunctionExplodeMap {
117117
template <bool AlwaysNullable = false>
118118
struct FunctionPoseExplode {
119119
static DataTypePtr get_return_type_impl(const DataTypes& arguments) {
120-
DCHECK(arguments[0]->get_primitive_type() == TYPE_ARRAY)
121-
<< arguments[0]->get_name() << " not supported";
122-
DataTypes fieldTypes(2);
120+
DataTypes fieldTypes(arguments.size() + 1);
123121
fieldTypes[0] = std::make_shared<DataTypeInt32>();
124-
fieldTypes[1] =
125-
check_and_get_data_type<DataTypeArray>(arguments[0].get())->get_nested_type();
122+
for (int i = 0; i < arguments.size(); i++) {
123+
DCHECK_EQ(arguments[i]->get_primitive_type(), TYPE_ARRAY)
124+
<< arguments[i]->get_name() << " not supported";
125+
auto nestedType =
126+
check_and_get_data_type<DataTypeArray>(arguments[i].get())->get_nested_type();
127+
fieldTypes[i + 1] = make_nullable(nestedType);
128+
}
126129
auto struct_type = std::make_shared<vectorized::DataTypeStruct>(fieldTypes);
127130
if constexpr (AlwaysNullable) {
128131
return make_nullable(struct_type);
129132
} else {
130-
return arguments[0]->is_nullable() ? make_nullable(struct_type) : struct_type;
133+
return struct_type;
131134
}
132135
}
133136
static DataTypes get_variadic_argument_types() { return {}; }

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/generator/PosExplode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.doris.catalog.FunctionSignature;
2121
import org.apache.doris.nereids.exceptions.AnalysisException;
2222
import org.apache.doris.nereids.trees.expressions.Expression;
23-
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNullable;
23+
import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
2424
import org.apache.doris.nereids.trees.expressions.functions.ComputePrecision;
2525
import org.apache.doris.nereids.trees.expressions.functions.CustomSignature;
2626
import org.apache.doris.nereids.trees.expressions.functions.SearchSignature;
@@ -44,7 +44,8 @@
4444
* pose column: 0, 1, 2
4545
* value column: 'a', 'b', 'c'
4646
*/
47-
public class PosExplode extends TableGeneratingFunction implements CustomSignature, ComputePrecision, AlwaysNullable {
47+
public class PosExplode extends TableGeneratingFunction implements
48+
CustomSignature, ComputePrecision, AlwaysNotNullable {
4849
public static final String POS_COLUMN = "pos";
4950

5051
/**

regression-test/data/nereids_p0/sql_functions/table_function/posexplode.out

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,140 @@
331331
2 tom ["t1_c"] ["t2_d", "t2_e"] {"pos":1, "col1":null, "col2":"t2_e"} {"pos":0, "col1":"t1_c", "col2":"t2_d"}
332332
2 tom ["t1_c"] ["t2_d", "t2_e"] {"pos":1, "col1":null, "col2":"t2_e"} {"pos":1, "col1":null, "col2":"t2_e"}
333333

334+
-- !mixed_nullable_all --
335+
1 ["t_not_null1_a", "t_not_null1_b"] ["t_not_null2_a", "t_not_null2_b"] ["t_null1_a", "t_null1_b"] ["t_null2_a", "t_null2_b"]
336+
2 ["t_not_null1_c"] ["t_not_null2_c", "t_not_null2_d"] ["t_null1_c"] ["t_null2_c", "t_null2_d"]
337+
3 ["t_not_null1_d", "t_not_null1_e"] ["t_not_null2_e"] ["t_null1_d", "t_null1_e"] ["t_null2_e"]
338+
4 ["t_not_null1_f"] ["t_not_null2_f"] \N ["t_null2_f"]
339+
5 ["t_not_null1_g"] ["t_not_null2_g"] ["t_null1_f"] \N
340+
6 ["t_not_null1_h"] ["t_not_null2_h"] \N \N
341+
342+
-- !mixed_nullable_not_null0 --
343+
1 {"pos":0, "col1":"t_not_null1_a"}
344+
1 {"pos":1, "col1":"t_not_null1_b"}
345+
2 {"pos":0, "col1":"t_not_null1_c"}
346+
3 {"pos":0, "col1":"t_not_null1_d"}
347+
3 {"pos":1, "col1":"t_not_null1_e"}
348+
4 {"pos":0, "col1":"t_not_null1_f"}
349+
5 {"pos":0, "col1":"t_not_null1_g"}
350+
6 {"pos":0, "col1":"t_not_null1_h"}
351+
352+
-- !mixed_nullable_not_null1 --
353+
1 0 t_not_null1_a
354+
1 1 t_not_null1_b
355+
2 0 t_not_null1_c
356+
3 0 t_not_null1_d
357+
3 1 t_not_null1_e
358+
4 0 t_not_null1_f
359+
5 0 t_not_null1_g
360+
6 0 t_not_null1_h
361+
362+
-- !mixed_nullable_not_null2 --
363+
1 {"pos":0, "col1":"t_not_null1_a", "col2":"t_not_null2_a"}
364+
1 {"pos":1, "col1":"t_not_null1_b", "col2":"t_not_null2_b"}
365+
2 {"pos":0, "col1":"t_not_null1_c", "col2":"t_not_null2_c"}
366+
2 {"pos":1, "col1":null, "col2":"t_not_null2_d"}
367+
3 {"pos":0, "col1":"t_not_null1_d", "col2":"t_not_null2_e"}
368+
3 {"pos":1, "col1":"t_not_null1_e", "col2":null}
369+
4 {"pos":0, "col1":"t_not_null1_f", "col2":"t_not_null2_f"}
370+
5 {"pos":0, "col1":"t_not_null1_g", "col2":"t_not_null2_g"}
371+
6 {"pos":0, "col1":"t_not_null1_h", "col2":"t_not_null2_h"}
372+
373+
-- !mixed_nullable_not_null3 --
374+
1 0 t_not_null1_a t_not_null2_a
375+
1 1 t_not_null1_b t_not_null2_b
376+
2 0 t_not_null1_c t_not_null2_c
377+
2 1 \N t_not_null2_d
378+
3 0 t_not_null1_d t_not_null2_e
379+
3 1 t_not_null1_e \N
380+
4 0 t_not_null1_f t_not_null2_f
381+
5 0 t_not_null1_g t_not_null2_g
382+
6 0 t_not_null1_h t_not_null2_h
383+
384+
-- !mixed_nullable_not_null_outer0 --
385+
1 {"pos":0, "col1":"t_not_null1_a"}
386+
1 {"pos":1, "col1":"t_not_null1_b"}
387+
2 {"pos":0, "col1":"t_not_null1_c"}
388+
3 {"pos":0, "col1":"t_not_null1_d"}
389+
3 {"pos":1, "col1":"t_not_null1_e"}
390+
4 {"pos":0, "col1":"t_not_null1_f"}
391+
5 {"pos":0, "col1":"t_not_null1_g"}
392+
6 {"pos":0, "col1":"t_not_null1_h"}
393+
394+
-- !mixed_nullable_not_null_outer1 --
395+
1 0 t_not_null1_a
396+
1 1 t_not_null1_b
397+
2 0 t_not_null1_c
398+
3 0 t_not_null1_d
399+
3 1 t_not_null1_e
400+
4 0 t_not_null1_f
401+
5 0 t_not_null1_g
402+
6 0 t_not_null1_h
403+
404+
-- !mixed_nullable_not_null_outer2 --
405+
1 {"pos":0, "col1":"t_not_null1_a", "col2":"t_not_null2_a"}
406+
1 {"pos":1, "col1":"t_not_null1_b", "col2":"t_not_null2_b"}
407+
2 {"pos":0, "col1":"t_not_null1_c", "col2":"t_not_null2_c"}
408+
2 {"pos":1, "col1":null, "col2":"t_not_null2_d"}
409+
3 {"pos":0, "col1":"t_not_null1_d", "col2":"t_not_null2_e"}
410+
3 {"pos":1, "col1":"t_not_null1_e", "col2":null}
411+
4 {"pos":0, "col1":"t_not_null1_f", "col2":"t_not_null2_f"}
412+
5 {"pos":0, "col1":"t_not_null1_g", "col2":"t_not_null2_g"}
413+
6 {"pos":0, "col1":"t_not_null1_h", "col2":"t_not_null2_h"}
414+
415+
-- !mixed_nullable_not_null_outer3 --
416+
1 0 t_not_null1_a t_not_null2_a
417+
1 1 t_not_null1_b t_not_null2_b
418+
2 0 t_not_null1_c t_not_null2_c
419+
2 1 \N t_not_null2_d
420+
3 0 t_not_null1_d t_not_null2_e
421+
3 1 t_not_null1_e \N
422+
4 0 t_not_null1_f t_not_null2_f
423+
5 0 t_not_null1_g t_not_null2_g
424+
6 0 t_not_null1_h t_not_null2_h
425+
426+
-- !mixed_nullable2 --
427+
1 {"pos":0, "col1":"t_not_null1_a", "col2":"t_null1_a"}
428+
1 {"pos":1, "col1":"t_not_null1_b", "col2":"t_null1_b"}
429+
2 {"pos":0, "col1":"t_not_null1_c", "col2":"t_null1_c"}
430+
3 {"pos":0, "col1":"t_not_null1_d", "col2":"t_null1_d"}
431+
3 {"pos":1, "col1":"t_not_null1_e", "col2":"t_null1_e"}
432+
4 {"pos":0, "col1":"t_not_null1_f", "col2":null}
433+
5 {"pos":0, "col1":"t_not_null1_g", "col2":"t_null1_f"}
434+
6 {"pos":0, "col1":"t_not_null1_h", "col2":null}
435+
436+
-- !mixed_nullable3 --
437+
1 0 t_not_null1_a t_null1_a
438+
1 1 t_not_null1_b t_null1_b
439+
2 0 t_not_null1_c t_null1_c
440+
3 0 t_not_null1_d t_null1_d
441+
3 1 t_not_null1_e t_null1_e
442+
4 0 t_not_null1_f \N
443+
5 0 t_not_null1_g t_null1_f
444+
6 0 t_not_null1_h \N
445+
446+
-- !mixed_nullable_outer2 --
447+
1 {"pos":0, "col1":"t_not_null1_a", "col2":"t_null1_a"}
448+
1 {"pos":1, "col1":"t_not_null1_b", "col2":"t_null1_b"}
449+
2 {"pos":0, "col1":"t_not_null1_c", "col2":"t_null1_c"}
450+
3 {"pos":0, "col1":"t_not_null1_d", "col2":"t_null1_d"}
451+
3 {"pos":1, "col1":"t_not_null1_e", "col2":"t_null1_e"}
452+
4 {"pos":0, "col1":"t_not_null1_f", "col2":null}
453+
5 {"pos":0, "col1":"t_not_null1_g", "col2":"t_null1_f"}
454+
6 {"pos":0, "col1":"t_not_null1_h", "col2":null}
455+
456+
-- !mixed_nullable_outer3 --
457+
1 0 t_not_null1_a t_null1_a
458+
1 1 t_not_null1_b t_null1_b
459+
2 0 t_not_null1_c t_null1_c
460+
3 0 t_not_null1_d t_null1_d
461+
3 1 t_not_null1_e t_null1_e
462+
4 0 t_not_null1_f \N
463+
5 0 t_not_null1_g t_null1_f
464+
6 0 t_not_null1_h \N
465+
466+
-- !fix_return_type --
467+
1 [1, 2, 3] [10.50, 20.00] {"pos":0, "col1":1, "col2":10.50}
468+
1 [1, 2, 3] [10.50, 20.00] {"pos":1, "col1":2, "col2":20.00}
469+
1 [1, 2, 3] [10.50, 20.00] {"pos":2, "col1":3, "col2":null}
470+

regression-test/suites/nereids_p0/sql_functions/table_function/posexplode.groovy

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ suite("posexplode") {
100100
(4, "lily", ["t1_d","t1_e"], null),
101101
(5, "alice", null, null);
102102
"""
103+
103104
order_qt_pos_exp_multi_args_all """
104105
select * from test_posexplode_multi_args;
105106
"""
@@ -132,4 +133,77 @@ suite("posexplode") {
132133
lateral view posexplode_outer(tags1, tags2) tmp as s2
133134
where tags1 is not null and tags2 is not null order by 1,2;
134135
"""
136+
137+
sql """ DROP TABLE IF EXISTS test_posexplode_mixed_nullable"""
138+
sql """
139+
CREATE TABLE `test_posexplode_mixed_nullable`(
140+
`id` INT NULL,
141+
`tags_not_null1` array<string> NOT NULL,
142+
`tags_not_null2` array<string> NOT NULL,
143+
`tags_null1` array<string> NULL,
144+
`tags_null2` array<string> NULL,
145+
) PROPERTIES ("replication_num" = "1");
146+
"""
147+
sql """
148+
insert into test_posexplode_mixed_nullable values
149+
(1, ["t_not_null1_a","t_not_null1_b"], ["t_not_null2_a","t_not_null2_b"], ["t_null1_a","t_null1_b"], ["t_null2_a","t_null2_b"]),
150+
(2, ["t_not_null1_c"], ["t_not_null2_c","t_not_null2_d"], ["t_null1_c"], ["t_null2_c","t_null2_d"]),
151+
(3, ["t_not_null1_d", "t_not_null1_e"], ["t_not_null2_e"], ["t_null1_d", "t_null1_e"], ["t_null2_e"]),
152+
(4, ["t_not_null1_f"], ["t_not_null2_f"], null, ["t_null2_f"]),
153+
(5, ["t_not_null1_g"], ["t_not_null2_g"], ["t_null1_f"], null),
154+
(6, ["t_not_null1_h"], ["t_not_null2_h"], null, null);
155+
"""
156+
order_qt_mixed_nullable_all """
157+
select * from test_posexplode_mixed_nullable;
158+
"""
159+
order_qt_mixed_nullable_not_null0 """
160+
select id, st from test_posexplode_mixed_nullable lateral view posexplode(tags_not_null1) tmp as st order by 1, 2;
161+
"""
162+
order_qt_mixed_nullable_not_null1 """
163+
select id, pos, tmp0 from test_posexplode_mixed_nullable lateral view posexplode(tags_not_null1) tmp as pos, tmp0 order by 1, 2, 3;
164+
"""
165+
order_qt_mixed_nullable_not_null2 """
166+
select id, st from test_posexplode_mixed_nullable lateral view posexplode(tags_not_null1, tags_not_null2) tmp as st order by 1, 2;
167+
"""
168+
order_qt_mixed_nullable_not_null3 """
169+
select id, pos, tmp0, tmp1 from test_posexplode_mixed_nullable lateral view posexplode(tags_not_null1, tags_not_null2) tmp as pos, tmp0, tmp1 order by 1, 2, 3, 4;
170+
"""
171+
172+
order_qt_mixed_nullable_not_null_outer0 """
173+
select id, st from test_posexplode_mixed_nullable lateral view posexplode_outer(tags_not_null1) tmp as st order by 1, 2;
174+
"""
175+
order_qt_mixed_nullable_not_null_outer1 """
176+
select id, pos, tmp0 from test_posexplode_mixed_nullable lateral view posexplode_outer(tags_not_null1) tmp as pos, tmp0 order by 1, 2, 3;
177+
"""
178+
order_qt_mixed_nullable_not_null_outer2 """
179+
select id, st from test_posexplode_mixed_nullable lateral view posexplode_outer(tags_not_null1, tags_not_null2) tmp as st order by 1, 2;
180+
"""
181+
order_qt_mixed_nullable_not_null_outer3 """
182+
select id, pos, tmp0, tmp1 from test_posexplode_mixed_nullable lateral view posexplode_outer(tags_not_null1, tags_not_null2) tmp as pos, tmp0, tmp1 order by 1, 2, 3, 4;
183+
"""
184+
185+
order_qt_mixed_nullable2 """
186+
select id, st from test_posexplode_mixed_nullable lateral view posexplode(tags_not_null1, tags_null1) tmp as st order by 1, 2;
187+
"""
188+
order_qt_mixed_nullable3 """
189+
select id, pos, tmp0, tmp1 from test_posexplode_mixed_nullable lateral view posexplode(tags_not_null1, tags_null1) tmp as pos, tmp0, tmp1 order by 1, 2, 3, 4;
190+
"""
191+
192+
order_qt_mixed_nullable_outer2 """
193+
select id, st from test_posexplode_mixed_nullable lateral view posexplode_outer(tags_not_null1, tags_null1) tmp as st order by 1, 2;
194+
"""
195+
order_qt_mixed_nullable_outer3 """
196+
select id, pos, tmp0, tmp1 from test_posexplode_mixed_nullable lateral view posexplode_outer(tags_not_null1, tags_null1) tmp as pos, tmp0, tmp1 order by 1, 2, 3, 4;
197+
"""
198+
199+
qt_fix_return_type """
200+
SELECT
201+
*
202+
FROM (
203+
SELECT
204+
1 AS id,
205+
ARRAY(1, 2, 3) AS arr_int,
206+
ARRAY(CAST(10.5 AS DECIMAL(10,2)), CAST(20.0 AS DECIMAL(10,2))) AS arr_decimal
207+
) t lateral view posexplode(t.arr_int, t.arr_decimal) t2 AS v order by 1,2,3,4;
208+
"""
135209
}

0 commit comments

Comments
 (0)