@@ -22,8 +22,9 @@ use std::sync::Arc;
2222use std:: vec;
2323
2424use datafusion:: arrow:: array:: { Array , StringArray } ;
25- use datafusion:: arrow:: datatypes:: DataType ;
25+ use datafusion:: arrow:: datatypes:: { DataType , Field , Schema as ArrowSchema } ;
2626use datafusion:: execution:: context:: SessionContext ;
27+ use datafusion:: parquet:: arrow:: PARQUET_FIELD_ID_META_KEY ;
2728use iceberg:: io:: FileIOBuilder ;
2829use iceberg:: spec:: { NestedField , PrimitiveType , Schema , StructType , Type } ;
2930use iceberg:: { Catalog , NamespaceIdent , Result , TableCreation } ;
@@ -83,7 +84,7 @@ fn get_table_creation(
8384}
8485
8586#[ tokio:: test]
86- async fn test_provider_get_table_schema ( ) -> Result < ( ) > {
87+ async fn test_provider_plan_stream_schema ( ) -> Result < ( ) > {
8788 let iceberg_catalog = get_iceberg_catalog ( ) ;
8889 let namespace = NamespaceIdent :: new ( "test_provider_get_table_schema" . to_string ( ) ) ;
8990 set_test_namespace ( & iceberg_catalog, & namespace) . await ?;
@@ -111,6 +112,26 @@ async fn test_provider_get_table_schema() -> Result<()> {
111112 assert ! ( !field. is_nullable( ) )
112113 }
113114
115+ let df = ctx
116+ . sql ( "select foo2 from catalog.test_provider_get_table_schema.my_table" )
117+ . await
118+ . unwrap ( ) ;
119+
120+ let task_ctx = Arc :: new ( df. task_ctx ( ) ) ;
121+ let plan = df. create_physical_plan ( ) . await . unwrap ( ) ;
122+ let stream = plan. execute ( 1 , task_ctx) . unwrap ( ) ;
123+
124+ // Ensure both the plan and the stream conform to the same schema
125+ assert_eq ! ( plan. schema( ) , stream. schema( ) ) ;
126+ assert_eq ! (
127+ stream. schema( ) . as_ref( ) ,
128+ & ArrowSchema :: new( vec![ Field :: new( "foo2" , DataType :: Utf8 , false )
129+ . with_metadata( HashMap :: from( [ (
130+ PARQUET_FIELD_ID_META_KEY . to_string( ) ,
131+ "2" . to_string( ) ,
132+ ) ] ) ) ] ) ,
133+ ) ;
134+
114135 Ok ( ( ) )
115136}
116137
0 commit comments