@@ -3211,6 +3211,48 @@ def test__to_requested_schema_timestamps_without_downcast_raises_exception(
32113211 assert "Unsupported schema projection from timestamp[ns] to timestamp[us]" in str (exc_info .value )
32123212
32133213
3214+ def test__to_requested_schema_null_map_of_structs () -> None :
3215+ requested_schema = Schema (
3216+ NestedField (
3217+ 1 ,
3218+ "col_map_with_struct" ,
3219+ MapType (
3220+ 11 ,
3221+ StringType (),
3222+ 12 ,
3223+ StructType (NestedField (121 , "source" , StringType (), required = False )),
3224+ value_required = False ,
3225+ ),
3226+ required = False ,
3227+ ),
3228+ NestedField (2 , "col_map" , MapType (21 , StringType (), 22 , IntegerType (), value_required = False ), required = False ),
3229+ )
3230+ arrow_schema = pa .schema (
3231+ [
3232+ pa .field ("col_map_with_struct" , pa .map_ (pa .string (), pa .struct ([pa .field ("source" , pa .string ())]))),
3233+ pa .field ("col_map" , pa .map_ (pa .string (), pa .int32 ())),
3234+ ]
3235+ )
3236+ batch = pa .RecordBatch .from_arrays (
3237+ [
3238+ pa .array (
3239+ [[("a" , {"source" : "x" })], [], None , [("b" , {"source" : "y" }), ("c" , None )]], type = arrow_schema .field (0 ).type
3240+ ),
3241+ pa .array ([[("a" , 1 )], [], None , [("b" , 2 ), ("c" , None )]], type = arrow_schema .field (1 ).type ),
3242+ ],
3243+ schema = arrow_schema ,
3244+ )
3245+
3246+ result = _to_requested_schema (requested_schema , requested_schema , batch )
3247+ assert result .column (0 ).to_pylist () == [[("a" , {"source" : "x" })], [], None , [("b" , {"source" : "y" }), ("c" , None )]]
3248+ assert result .column (1 ).to_pylist () == [[("a" , 1 )], [], None , [("b" , 2 ), ("c" , None )]]
3249+
3250+ # A sliced batch has to keep the nulls as well
3251+ result = _to_requested_schema (requested_schema , requested_schema , batch .slice (1 , 3 ))
3252+ assert result .column (0 ).to_pylist () == [[], None , [("b" , {"source" : "y" }), ("c" , None )]]
3253+ assert result .column (1 ).to_pylist () == [[], None , [("b" , 2 ), ("c" , None )]]
3254+
3255+
32143256@pytest .mark .parametrize (
32153257 "arrow_type,iceberg_type,expected_arrow_type" ,
32163258 [
0 commit comments