@@ -7,6 +7,7 @@ use std::ffi::CStr;
77use std:: path:: Path ;
88use std:: slice;
99use std:: str:: FromStr ;
10+ use std:: sync:: Arc ;
1011
1112use anyhow:: Result ;
1213use geo_types:: LineString ;
@@ -37,6 +38,7 @@ use vortex::dtype::PType;
3738use vortex:: encodings:: fastlanes:: RLEData ;
3839use vortex:: file:: WriteOptionsSessionExt ;
3940use vortex:: io:: runtime:: BlockingRuntime ;
41+ use vortex:: layout:: layouts:: flat:: writer:: FlatLayoutStrategy ;
4042use vortex:: scalar:: PValue ;
4143use vortex:: scalar:: Scalar ;
4244use vortex_array:: arrays:: ExtensionArray ;
@@ -1112,3 +1114,35 @@ fn test_vortex_scan_fixed_size_list_length_projection() {
11121114 assert_eq ! ( lengths, vec![ 4i64 ; 6 ] , "{func}(int_lists) mismatch" ) ;
11131115 }
11141116}
1117+
1118+ /// Vortex allows duplicate struct names but duckdb doesn't. Ensure we can't
1119+ /// read a file if names are not unique
1120+ #[ test]
1121+ fn test_duplicate_struct_fields ( ) {
1122+ let array = StructArray :: try_from_iter ( [
1123+ ( "a" , buffer ! [ 1i32 , 2 , 3 ] . into_array ( ) ) ,
1124+ ( "a" , buffer ! [ 10i64 , 20 , 30 ] . into_array ( ) ) ,
1125+ ] )
1126+ . unwrap ( ) ;
1127+ let array = StructArray :: try_from_iter ( [ ( "s" , array) ] )
1128+ . unwrap ( )
1129+ . into_array ( ) ;
1130+ let path = create_temp_file ( ) ;
1131+ RUNTIME . block_on ( async {
1132+ let mut file = async_fs:: File :: create ( & path) . await . unwrap ( ) ;
1133+ SESSION
1134+ . write_options ( )
1135+ . with_strategy ( Arc :: new ( FlatLayoutStrategy :: default ( ) ) )
1136+ . write ( & mut file, array. to_array_stream ( ) )
1137+ . await
1138+ . unwrap ( )
1139+ } ) ;
1140+ let conn = database_connection ( ) ;
1141+ let path = path. path ( ) . to_string_lossy ( ) ;
1142+
1143+ assert ! ( conn. query( & format!( "SELECT s FROM '{path}'" ) ) . is_err( ) ) ;
1144+ assert ! (
1145+ conn. query( & format!( "SELECT string_agg(s::VARCHAR, '') FROM '{path}'" ) )
1146+ . is_err( )
1147+ ) ;
1148+ }
0 commit comments