File tree Expand file tree Collapse file tree 5 files changed +65
-16
lines changed
core/src/datasource/file_format Expand file tree Collapse file tree 5 files changed +65
-16
lines changed Original file line number Diff line number Diff line change @@ -213,16 +213,14 @@ pub fn transform_schema_to_view(schema: &Schema) -> Schema {
213
213
. fields
214
214
. iter ( )
215
215
. map ( |field| match field. data_type ( ) {
216
- DataType :: Utf8 | DataType :: LargeUtf8 => Arc :: new ( Field :: new (
217
- field. name ( ) ,
218
- DataType :: Utf8View ,
219
- field. is_nullable ( ) ,
220
- ) ) ,
221
- DataType :: Binary | DataType :: LargeBinary => Arc :: new ( Field :: new (
222
- field. name ( ) ,
223
- DataType :: BinaryView ,
224
- field. is_nullable ( ) ,
225
- ) ) ,
216
+ DataType :: Utf8 | DataType :: LargeUtf8 => Arc :: new (
217
+ Field :: new ( field. name ( ) , DataType :: Utf8View , field. is_nullable ( ) )
218
+ . with_metadata ( field. metadata ( ) . to_owned ( ) ) ,
219
+ ) ,
220
+ DataType :: Binary | DataType :: LargeBinary => Arc :: new (
221
+ Field :: new ( field. name ( ) , DataType :: BinaryView , field. is_nullable ( ) )
222
+ . with_metadata ( field. metadata ( ) . to_owned ( ) ) ,
223
+ ) ,
226
224
_ => field. clone ( ) ,
227
225
} )
228
226
. collect ( ) ;
Original file line number Diff line number Diff line change @@ -69,15 +69,22 @@ impl CrossJoinExec {
69
69
/// Create a new [CrossJoinExec].
70
70
pub fn new ( left : Arc < dyn ExecutionPlan > , right : Arc < dyn ExecutionPlan > ) -> Self {
71
71
// left then right
72
- let all_columns: Fields = {
72
+ let ( all_columns, metadata ) = {
73
73
let left_schema = left. schema ( ) ;
74
74
let right_schema = right. schema ( ) ;
75
75
let left_fields = left_schema. fields ( ) . iter ( ) ;
76
76
let right_fields = right_schema. fields ( ) . iter ( ) ;
77
- left_fields. chain ( right_fields) . cloned ( ) . collect ( )
77
+
78
+ let mut metadata = left_schema. metadata ( ) . clone ( ) ;
79
+ metadata. extend ( right_schema. metadata ( ) . clone ( ) ) ;
80
+
81
+ (
82
+ left_fields. chain ( right_fields) . cloned ( ) . collect :: < Fields > ( ) ,
83
+ metadata,
84
+ )
78
85
} ;
79
86
80
- let schema = Arc :: new ( Schema :: new ( all_columns) ) ;
87
+ let schema = Arc :: new ( Schema :: new ( all_columns) . with_metadata ( metadata ) ) ;
81
88
let cache = Self :: compute_properties ( & left, & right, Arc :: clone ( & schema) ) ;
82
89
CrossJoinExec {
83
90
left,
Original file line number Diff line number Diff line change @@ -474,7 +474,16 @@ fn union_schema(inputs: &[Arc<dyn ExecutionPlan>]) -> SchemaRef {
474
474
. iter ( )
475
475
. filter_map ( |input| {
476
476
if input. schema ( ) . fields ( ) . len ( ) > i {
477
- Some ( input. schema ( ) . field ( i) . clone ( ) )
477
+ let field = input. schema ( ) . field ( i) . clone ( ) ;
478
+ let right_hand_metdata = inputs
479
+ . get ( 1 )
480
+ . map ( |right_input| {
481
+ right_input. schema ( ) . field ( i) . metadata ( ) . clone ( )
482
+ } )
483
+ . unwrap_or_default ( ) ;
484
+ let mut metadata = field. metadata ( ) . clone ( ) ;
485
+ metadata. extend ( right_hand_metdata) ;
486
+ Some ( field. with_metadata ( metadata) )
478
487
} else {
479
488
None
480
489
}
Original file line number Diff line number Diff line change @@ -310,8 +310,13 @@ pub async fn register_metadata_tables(ctx: &SessionContext) {
310
310
String :: from ( "metadata_key" ) ,
311
311
String :: from ( "the name field" ) ,
312
312
) ] ) ) ;
313
+ let l_name =
314
+ Field :: new ( "l_name" , DataType :: Utf8 , true ) . with_metadata ( HashMap :: from ( [ (
315
+ String :: from ( "metadata_key" ) ,
316
+ String :: from ( "the l_name field" ) ,
317
+ ) ] ) ) ;
313
318
314
- let schema = Schema :: new ( vec ! [ id, name] ) . with_metadata ( HashMap :: from ( [ (
319
+ let schema = Schema :: new ( vec ! [ id, name, l_name ] ) . with_metadata ( HashMap :: from ( [ (
315
320
String :: from ( "metadata_key" ) ,
316
321
String :: from ( "the entire schema" ) ,
317
322
) ] ) ) ;
@@ -321,6 +326,7 @@ pub async fn register_metadata_tables(ctx: &SessionContext) {
321
326
vec ! [
322
327
Arc :: new( Int32Array :: from( vec![ Some ( 1 ) , None , Some ( 3 ) ] ) ) as _,
323
328
Arc :: new( StringArray :: from( vec![ None , Some ( "bar" ) , Some ( "baz" ) ] ) ) as _,
329
+ Arc :: new( StringArray :: from( vec![ None , Some ( "l_bar" ) , Some ( "l_baz" ) ] ) ) as _,
324
330
] ,
325
331
)
326
332
. unwrap ( ) ;
Original file line number Diff line number Diff line change 25
25
## with metadata in SQL.
26
26
27
27
query IT
28
- select * from table_with_metadata;
28
+ select id, name from table_with_metadata;
29
29
----
30
30
1 NULL
31
31
NULL bar
@@ -96,5 +96,34 @@ select count(id) cnt from table_with_metadata group by name order by cnt;
96
96
1
97
97
98
98
99
+
100
+ # Regression test: missing schema metadata, when aggregate on cross join
101
+ query I
102
+ SELECT count("data"."id")
103
+ FROM
104
+ (
105
+ SELECT "id" FROM "table_with_metadata"
106
+ ) as "data",
107
+ (
108
+ SELECT "id" FROM "table_with_metadata"
109
+ ) as "samples";
110
+ ----
111
+ 6
112
+
113
+ # Regression test: missing field metadata, from the NULL field on the left side of the union
114
+ query ITT
115
+ (SELECT id, NULL::string as name, l_name FROM "table_with_metadata")
116
+ UNION
117
+ (SELECT id, name, NULL::string as l_name FROM "table_with_metadata")
118
+ ORDER BY id, name, l_name;
119
+ ----
120
+ 1 NULL NULL
121
+ 3 baz NULL
122
+ 3 NULL l_baz
123
+ NULL bar NULL
124
+ NULL NULL l_bar
125
+
126
+
127
+
99
128
statement ok
100
129
drop table table_with_metadata;
You can’t perform that action at this time.
0 commit comments