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 {
213213 . fields
214214 . iter ( )
215215 . 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+ ) ,
226224 _ => field. clone ( ) ,
227225 } )
228226 . collect ( ) ;
Original file line number Diff line number Diff line change @@ -69,15 +69,22 @@ impl CrossJoinExec {
6969 /// Create a new [CrossJoinExec].
7070 pub fn new ( left : Arc < dyn ExecutionPlan > , right : Arc < dyn ExecutionPlan > ) -> Self {
7171 // left then right
72- let all_columns: Fields = {
72+ let ( all_columns, metadata ) = {
7373 let left_schema = left. schema ( ) ;
7474 let right_schema = right. schema ( ) ;
7575 let left_fields = left_schema. fields ( ) . iter ( ) ;
7676 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+ )
7885 } ;
7986
80- let schema = Arc :: new ( Schema :: new ( all_columns) ) ;
87+ let schema = Arc :: new ( Schema :: new ( all_columns) . with_metadata ( metadata ) ) ;
8188 let cache = Self :: compute_properties ( & left, & right, Arc :: clone ( & schema) ) ;
8289 CrossJoinExec {
8390 left,
Original file line number Diff line number Diff line change @@ -474,7 +474,16 @@ fn union_schema(inputs: &[Arc<dyn ExecutionPlan>]) -> SchemaRef {
474474 . iter ( )
475475 . filter_map ( |input| {
476476 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) )
478487 } else {
479488 None
480489 }
Original file line number Diff line number Diff line change @@ -310,8 +310,13 @@ pub async fn register_metadata_tables(ctx: &SessionContext) {
310310 String :: from ( "metadata_key" ) ,
311311 String :: from ( "the name field" ) ,
312312 ) ] ) ) ;
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+ ) ] ) ) ;
313318
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 ( [ (
315320 String :: from ( "metadata_key" ) ,
316321 String :: from ( "the entire schema" ) ,
317322 ) ] ) ) ;
@@ -321,6 +326,7 @@ pub async fn register_metadata_tables(ctx: &SessionContext) {
321326 vec ! [
322327 Arc :: new( Int32Array :: from( vec![ Some ( 1 ) , None , Some ( 3 ) ] ) ) as _,
323328 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 _,
324330 ] ,
325331 )
326332 . unwrap ( ) ;
Original file line number Diff line number Diff line change 2525## with metadata in SQL.
2626
2727query IT
28- select * from table_with_metadata;
28+ select id, name from table_with_metadata;
2929----
30301 NULL
3131NULL bar
@@ -96,5 +96,34 @@ select count(id) cnt from table_with_metadata group by name order by cnt;
96961
9797
9898
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+
99128statement ok
100129drop table table_with_metadata;
You can’t perform that action at this time.
0 commit comments