@@ -4,6 +4,8 @@ using RustyIceberg: SortDirection, ASC, DESC
44using RustyIceberg: NullOrder, NULLS_FIRST, NULLS_LAST
55using Test
66using JSON
7+ using Arrow
8+ using Dates
79
810@testset " Schema Types" begin
911 @testset " Field Creation" begin
256258 end
257259end
258260
261+ @testset " Arrow Type Mappings" begin
262+ @testset " iceberg_type_to_arrow_type" begin
263+ # Basic types
264+ @test iceberg_type_to_arrow_type (" boolean" ) == Bool
265+ @test iceberg_type_to_arrow_type (" int" ) == Int32
266+ @test iceberg_type_to_arrow_type (" long" ) == Int64
267+ @test iceberg_type_to_arrow_type (" float" ) == Float32
268+ @test iceberg_type_to_arrow_type (" double" ) == Float64
269+ @test iceberg_type_to_arrow_type (" string" ) == String
270+
271+ # Temporal types
272+ @test iceberg_type_to_arrow_type (" date" ) == Dates. Date
273+ @test iceberg_type_to_arrow_type (" time" ) == Int64
274+ @test iceberg_type_to_arrow_type (" timestamp" ) == Arrow. Timestamp{Arrow. Flatbuf. TimeUnit. MICROSECOND, nothing }
275+ @test iceberg_type_to_arrow_type (" timestamptz" ) == Arrow. Timestamp{Arrow. Flatbuf. TimeUnit. MICROSECOND, :UTC }
276+ @test iceberg_type_to_arrow_type (" timestamp_ns" ) == Arrow. Timestamp{Arrow. Flatbuf. TimeUnit. NANOSECOND, nothing }
277+ @test iceberg_type_to_arrow_type (" timestamptz_ns" ) == Arrow. Timestamp{Arrow. Flatbuf. TimeUnit. NANOSECOND, :UTC }
278+
279+ # Complex types
280+ @test iceberg_type_to_arrow_type (" uuid" ) == NTuple{16 , UInt8}
281+ @test iceberg_type_to_arrow_type (" binary" ) == Vector{UInt8}
282+
283+ # Decimal types with different precisions
284+ @test iceberg_type_to_arrow_type (" decimal(5,2)" ) == Int32
285+ @test iceberg_type_to_arrow_type (" decimal(9,0)" ) == Int32
286+ @test iceberg_type_to_arrow_type (" decimal(15,4)" ) == Int64
287+ @test iceberg_type_to_arrow_type (" decimal(18,6)" ) == Int64
288+ @test iceberg_type_to_arrow_type (" decimal(25,10)" ) == NTuple{16 , UInt8}
289+ @test iceberg_type_to_arrow_type (" decimal(38,18)" ) == NTuple{16 , UInt8}
290+ end
291+
292+ @testset " arrow_type with nullable fields" begin
293+ # Required field should return base type
294+ field_required = Field (Int32 (1 ), " id" , " long" ; required= true )
295+ @test arrow_type (field_required) == Int64
296+
297+ # Nullable field should return Union{Missing, T}
298+ field_nullable = Field (Int32 (2 ), " name" , " string" ; required= false )
299+ @test arrow_type (field_nullable) == Union{Missing, String}
300+
301+ # Test with date field
302+ field_date_required = Field (Int32 (3 ), " birth_date" , " date" ; required= true )
303+ @test arrow_type (field_date_required) == Dates. Date
304+
305+ field_date_nullable = Field (Int32 (4 ), " death_date" , " date" ; required= false )
306+ @test arrow_type (field_date_nullable) == Union{Missing, Dates. Date}
307+
308+ # Test with timestamp field
309+ field_ts_nullable = Field (Int32 (5 ), " created_at" , " timestamp" ; required= false )
310+ @test arrow_type (field_ts_nullable) == Union{Missing, Arrow. Timestamp{Arrow. Flatbuf. TimeUnit. MICROSECOND, nothing }}
311+ end
312+
313+ @testset " arrow_types for schema" begin
314+ schema = Schema ([
315+ Field (Int32 (1 ), " id" , " long" ; required= true ),
316+ Field (Int32 (2 ), " name" , " string" ; required= false ),
317+ Field (Int32 (3 ), " event_date" , " date" ; required= false ),
318+ Field (Int32 (4 ), " created_at" , " timestamp" ; required= true ),
319+ ])
320+
321+ types = arrow_types (schema)
322+
323+ # Required fields should have base types
324+ @test types[" id" ] == Int64
325+ @test types[" created_at" ] == Arrow. Timestamp{Arrow. Flatbuf. TimeUnit. MICROSECOND, nothing }
326+
327+ # Nullable fields should have Union{Missing, T}
328+ @test types[" name" ] == Union{Missing, String}
329+ @test types[" event_date" ] == Union{Missing, Dates. Date}
330+ end
331+ end
332+
259333println (" All schema tests passed!" )
0 commit comments