Skip to content

Commit 4afd46f

Browse files
committed
Update tests for new feature
1 parent 87563d8 commit 4afd46f

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

datafusion/sqllogictest/test_files/struct.slt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,18 @@ Struct("r": Utf8, "c": Float64)
492492
statement ok
493493
drop table t;
494494

495-
query error DataFusion error: Optimizer rule 'simplify_expressions' failed[\s\S]*Arrow error: Cast error: Cannot cast string 'a' to value of Float64 type
495+
statement ok
496496
create table t as values({r: 'a', c: 1}), ({c: 2.3, r: 'b'});
497497

498+
query ?
499+
select * from t;
500+
----
501+
{c: 1.0, r: a}
502+
{c: 2.3, r: b}
503+
504+
statement ok
505+
drop table t;
506+
498507
##################################
499508
## Test Coalesce with Struct
500509
##################################
@@ -560,10 +569,18 @@ create table t(a struct(r varchar, c int), b struct(r varchar, c float)) as valu
560569
(row('purple', 1), row('green', 2.3));
561570

562571
# out of order struct literal
563-
# TODO: This query should not fail
564-
statement error DataFusion error: Optimizer rule 'simplify_expressions' failed[\s\S]*Arrow error: Cast error: Cannot cast string 'b' to value of Int32 type
572+
statement ok
565573
create table t(a struct(r varchar, c int)) as values ({r: 'a', c: 1}), ({c: 2, r: 'b'});
566574

575+
query ?
576+
select * from t;
577+
----
578+
{r: a, c: 1}
579+
{r: b, c: 2}
580+
581+
statement ok
582+
drop table t;
583+
567584
##################################
568585
## Test Array of Struct
569586
##################################
@@ -573,9 +590,11 @@ select [{r: 'a', c: 1}, {r: 'b', c: 2}];
573590
----
574591
[{r: a, c: 1}, {r: b, c: 2}]
575592

576-
# Can't create a list of struct with different field types
577-
query error
593+
# Create a list of struct with different field types
594+
query ?
578595
select [{r: 'a', c: 1}, {c: 2, r: 'b'}];
596+
----
597+
[{c: 1, r: a}, {c: 2, r: b}]
579598

580599
statement ok
581600
create table t(a struct(r varchar, c int), b struct(r varchar, c float)) as values (row('a', 1), row('b', 2.3));
@@ -592,23 +611,25 @@ drop table t;
592611
statement ok
593612
create table t(a struct(r varchar, c int), b struct(c float, r varchar)) as values (row('a', 1), row(2.3, 'b'));
594613

595-
# create array with different struct type is not valid
596-
query error
614+
# create array with different struct type should be cast
615+
query T
597616
select arrow_typeof([a, b]) from t;
617+
----
618+
List(Struct("c": Float32, "r": Utf8View))
598619

599620
statement ok
600621
drop table t;
601622

602623
statement ok
603624
create table t(a struct(r varchar, c int, g float), b struct(r varchar, c float, g int)) as values (row('a', 1, 2.3), row('b', 2.3, 2));
604625

605-
# type of each column should not coerced but perserve as it is
626+
# type of each column should not coerced but preserve as it is
606627
query T
607628
select arrow_typeof(a) from t;
608629
----
609630
Struct("r": Utf8View, "c": Int32, "g": Float32)
610631

611-
# type of each column should not coerced but perserve as it is
632+
# type of each column should not coerced but preserve as it is
612633
query T
613634
select arrow_typeof(b) from t;
614635
----

0 commit comments

Comments
 (0)