From 3a4c2b5d77912eb9af09221c0dc3a80f3496fc49 Mon Sep 17 00:00:00 2001 From: Duong Cong Toai Date: Sun, 28 Apr 2024 21:39:00 +0200 Subject: [PATCH] chore: update test --- datafusion/sql/src/planner.rs | 4 +-- datafusion/sqllogictest/test_files/struct.slt | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs index f4440ca38d7e..220dea173ab1 100644 --- a/datafusion/sql/src/planner.rs +++ b/datafusion/sql/src/planner.rs @@ -446,13 +446,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { let data_type = self.convert_data_type(&field.field_type)?; let field_name = match &field.field_name{ Some(ident) => ident.clone(), - None => Ident::new(format!("col{idx}")) + None => Ident::new(format!("c{idx}")) }; Ok(Arc::new(Field::new( self.normalizer.normalize(field_name), data_type, - false, // TODO: confirm this + true, // TODO: confirm this ))) }) .collect::>>()?; diff --git a/datafusion/sqllogictest/test_files/struct.slt b/datafusion/sqllogictest/test_files/struct.slt index 938379263ae6..103d954904a8 100644 --- a/datafusion/sqllogictest/test_files/struct.slt +++ b/datafusion/sqllogictest/test_files/struct.slt @@ -31,10 +31,12 @@ CREATE TABLE values( (3, 3.3, 'c', NULL) ; + +# named and named less struct fields statement ok -CREATE TABLE toai( - s1 struct, - s2 struct +CREATE TABLE struct_values ( + s1 struct, + s2 struct ) AS VALUES (struct(1), struct(1, 'string1')), (struct(2), struct(2, 'string2')), @@ -42,11 +44,18 @@ CREATE TABLE toai( ; query ?? -select * from toai; ---- -{col0: 1} {a: 1, b: string1} -{col0: 2} {a: 2, b: string2} -{col0: 3} {a: 3, b: string3} +select * from struct_values; +---- +{c0: 1} {a: 1, b: string1} +{c0: 2} {a: 2, b: string2} +{c0: 3} {a: 3, b: string3} + +query TT +select arrow_typeof(s1), arrow_typeof(s2) from struct_values; +---- +Struct([Field { name: "c0", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) Struct([Field { name: "a", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) +Struct([Field { name: "c0", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) Struct([Field { name: "a", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) +Struct([Field { name: "c0", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) Struct([Field { name: "a", data_type: Int32, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }, Field { name: "b", data_type: Utf8, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }]) # struct[i]