@@ -404,54 +404,55 @@ def test_delta_timestamps(make_mocked_engine_adapter: t.Callable):
404404 }
405405
406406
407- def test_trino_to_delta_timestamp_mapping ():
408- """Test that trino_to_delta_timestamp_mapping config property is properly defined and accessible."""
407+ def test_timestamp_mapping ():
408+ """Test that timestamp_mapping config property is properly defined and accessible."""
409409 config = TrinoConnectionConfig (
410410 user = "user" ,
411411 host = "host" ,
412412 catalog = "catalog" ,
413413 )
414414
415415 adapter = config .create_engine_adapter ()
416- assert adapter .trino_to_delta_timestamp_mapping is None
416+ assert adapter .timestamp_mapping is None
417417
418418 config = TrinoConnectionConfig (
419419 user = "user" ,
420420 host = "host" ,
421421 catalog = "catalog" ,
422- trino_to_delta_timestamp_mapping = {
423- "TIMESTAMP" : "TIMESTAMP" ,
424- "TIMESTAMP(3)" : "TIMESTAMP_NTZ " ,
422+ timestamp_mapping = {
423+ "TIMESTAMP" : "TIMESTAMP(6) " ,
424+ "TIMESTAMP(3)" : "TIMESTAMP WITH TIME ZONE " ,
425425 },
426426 )
427427 adapter = config .create_engine_adapter ()
428- assert adapter .trino_to_delta_timestamp_mapping is not None
429- assert adapter .trino_to_delta_timestamp_mapping [
430- exp . DataType . build ( "TIMESTAMP" )
431- ] == exp . DataType . build ( "TIMESTAMP" )
428+ assert adapter .timestamp_mapping is not None
429+ assert adapter .timestamp_mapping [ exp . DataType . build ( "TIMESTAMP" )] == exp . DataType . build (
430+ "TIMESTAMP(6)"
431+ )
432432
433433
434434def test_delta_timestamps_with_custom_mapping (make_mocked_engine_adapter : t .Callable ):
435- """Test that _to_delta_ts respects custom trino_to_delta_timestamp_mapping ."""
436- # Create config with custom timestamp mapping using valid Delta Lake types
437- # Delta Lake only supports: TIMESTAMP (TZ-aware) and TIMESTAMP_NTZ (no TZ)
435+ """Test that _apply_timestamp_mapping + _to_delta_ts respects custom timestamp_mapping ."""
436+ # Create config with custom timestamp mapping
437+ # Mapped columns are skipped by _to_delta_ts
438438 config = TrinoConnectionConfig (
439439 user = "user" ,
440440 host = "host" ,
441441 catalog = "catalog" ,
442- trino_to_delta_timestamp_mapping = {
443- "TIMESTAMP" : "TIMESTAMP" ,
444- "TIMESTAMP(1)" : "TIMESTAMP" ,
445- "TIMESTAMP WITH TIME ZONE" : "TIMESTAMP" ,
446- "TIMESTAMP(1) WITH TIME ZONE" : "TIMESTAMP" ,
442+ timestamp_mapping = {
443+ "TIMESTAMP" : "TIMESTAMP(3) " ,
444+ "TIMESTAMP(1)" : "TIMESTAMP(3) " ,
445+ "TIMESTAMP WITH TIME ZONE" : "TIMESTAMP(6) WITH TIME ZONE " ,
446+ "TIMESTAMP(1) WITH TIME ZONE" : "TIMESTAMP(6) WITH TIME ZONE " ,
447447 },
448448 )
449449
450450 adapter = make_mocked_engine_adapter (
451- TrinoEngineAdapter , trino_to_delta_timestamp_mapping = config .trino_to_delta_timestamp_mapping
451+ TrinoEngineAdapter , timestamp_mapping = config .timestamp_mapping
452452 )
453453
454- ts3_tz = exp .DataType .build ("timestamp(3) with time zone" )
454+ ts3 = exp .DataType .build ("timestamp(3)" )
455+ ts6_tz = exp .DataType .build ("timestamp(6) with time zone" )
455456
456457 columns_to_types = {
457458 "ts" : exp .DataType .build ("TIMESTAMP" ),
@@ -460,32 +461,37 @@ def test_delta_timestamps_with_custom_mapping(make_mocked_engine_adapter: t.Call
460461 "ts_tz_1" : exp .DataType .build ("TIMESTAMP(1) WITH TIME ZONE" ),
461462 }
462463
463- delta_columns_to_types = adapter ._to_delta_ts (columns_to_types )
464+ # Apply mapping first, then convert to delta types (skipping mapped columns)
465+ mapped_columns_to_types , mapped_column_names = adapter ._apply_timestamp_mapping (
466+ columns_to_types
467+ )
468+ delta_columns_to_types = adapter ._to_delta_ts (mapped_columns_to_types , mapped_column_names )
464469
465- # All types mapped to Delta's TIMESTAMP get converted to TIMESTAMPTZ then ts3_tz
470+ # All types were mapped, so _to_delta_ts skips them - they keep their mapped types
466471 assert delta_columns_to_types == {
467- "ts" : ts3_tz ,
468- "ts_1" : ts3_tz ,
469- "ts_tz" : ts3_tz ,
470- "ts_tz_1" : ts3_tz ,
472+ "ts" : ts3 ,
473+ "ts_1" : ts3 ,
474+ "ts_tz" : ts6_tz ,
475+ "ts_tz_1" : ts6_tz ,
471476 }
472477
473478
474479def test_delta_timestamps_with_partial_mapping (make_mocked_engine_adapter : t .Callable ):
475- """Test that _to_delta_ts uses custom mapping for specified types and defaults for others ."""
480+ """Test that _apply_timestamp_mapping + _to_delta_ts uses custom mapping for specified types."""
476481 config = TrinoConnectionConfig (
477482 user = "user" ,
478483 host = "host" ,
479484 catalog = "catalog" ,
480- trino_to_delta_timestamp_mapping = {
481- "TIMESTAMP" : "TIMESTAMP" ,
485+ timestamp_mapping = {
486+ "TIMESTAMP" : "TIMESTAMP(3) " ,
482487 },
483488 )
484489
485490 adapter = make_mocked_engine_adapter (
486- TrinoEngineAdapter , trino_to_delta_timestamp_mapping = config .trino_to_delta_timestamp_mapping
491+ TrinoEngineAdapter , timestamp_mapping = config .timestamp_mapping
487492 )
488493
494+ ts3 = exp .DataType .build ("TIMESTAMP(3)" )
489495 ts6 = exp .DataType .build ("timestamp(6)" )
490496 ts3_tz = exp .DataType .build ("timestamp(3) with time zone" )
491497
@@ -495,15 +501,19 @@ def test_delta_timestamps_with_partial_mapping(make_mocked_engine_adapter: t.Cal
495501 "ts_tz" : exp .DataType .build ("TIMESTAMP WITH TIME ZONE" ),
496502 }
497503
498- delta_columns_to_types = adapter ._to_delta_ts (columns_to_types )
504+ # Apply mapping first, then convert to delta types (skipping mapped columns)
505+ mapped_columns_to_types , mapped_column_names = adapter ._apply_timestamp_mapping (
506+ columns_to_types
507+ )
508+ delta_columns_to_types = adapter ._to_delta_ts (mapped_columns_to_types , mapped_column_names )
499509
500- # TIMESTAMP is in mapping → TIMESTAMP → TIMESTAMPTZ → ts3_tz
501- # TIMESTAMP(1) is NOT in mapping (exact match) , uses default TIMESTAMP → ts6
510+ # TIMESTAMP is in mapping → TIMESTAMP(3), skipped by _to_delta_ts
511+ # TIMESTAMP(1) is NOT in mapping, uses default TIMESTAMP → ts6
502512 # TIMESTAMP WITH TIME ZONE is NOT in mapping, uses default TIMESTAMPTZ → ts3_tz
503513 assert delta_columns_to_types == {
504- "ts" : ts3_tz ,
514+ "ts" : ts3 , # Mapped to TIMESTAMP(3), skipped by _to_delta_ts
505515 "ts_1" : ts6 , # Not in mapping, uses default
506- "ts_tz" : ts3_tz ,
516+ "ts_tz" : ts3_tz , # Not in mapping, uses default
507517 }
508518
509519
@@ -861,22 +871,22 @@ def test_insert_overwrite_time_partition_iceberg(
861871
862872
863873def test_delta_timestamps_with_non_timestamp_columns (make_mocked_engine_adapter : t .Callable ):
864- """Test that _to_delta_ts handles non-timestamp columns alongside custom mapping ."""
874+ """Test that _apply_timestamp_mapping + _to_delta_ts handles non-timestamp columns."""
865875 config = TrinoConnectionConfig (
866876 user = "user" ,
867877 host = "host" ,
868878 catalog = "catalog" ,
869- trino_to_delta_timestamp_mapping = {
870- "TIMESTAMP" : "TIMESTAMP" ,
879+ timestamp_mapping = {
880+ "TIMESTAMP" : "TIMESTAMP(3) " ,
871881 },
872882 )
873883
874884 adapter = make_mocked_engine_adapter (
875- TrinoEngineAdapter , trino_to_delta_timestamp_mapping = config .trino_to_delta_timestamp_mapping
885+ TrinoEngineAdapter , timestamp_mapping = config .timestamp_mapping
876886 )
877887
888+ ts3 = exp .DataType .build ("TIMESTAMP(3)" )
878889 ts6 = exp .DataType .build ("timestamp(6)" )
879- ts3_tz = exp .DataType .build ("timestamp(3) with time zone" )
880890
881891 columns_to_types = {
882892 "ts" : exp .DataType .build ("TIMESTAMP" ),
@@ -886,13 +896,17 @@ def test_delta_timestamps_with_non_timestamp_columns(make_mocked_engine_adapter:
886896 "decimal_col" : exp .DataType .build ("DECIMAL(10,2)" ),
887897 }
888898
889- delta_columns_to_types = adapter ._to_delta_ts (columns_to_types )
899+ # Apply mapping first, then convert to delta types (skipping mapped columns)
900+ mapped_columns_to_types , mapped_column_names = adapter ._apply_timestamp_mapping (
901+ columns_to_types
902+ )
903+ delta_columns_to_types = adapter ._to_delta_ts (mapped_columns_to_types , mapped_column_names )
890904
891- # TIMESTAMP is in mapping → TIMESTAMP → TIMESTAMPTZ → ts3_tz
905+ # TIMESTAMP is in mapping → TIMESTAMP(3), skipped by _to_delta_ts
892906 # TIMESTAMP(1) is NOT in mapping (exact match), uses default TIMESTAMP → ts6
893907 # Non-timestamp columns should pass through unchanged
894908 assert delta_columns_to_types == {
895- "ts" : ts3_tz ,
909+ "ts" : ts3 , # Mapped to TIMESTAMP(3), skipped by _to_delta_ts
896910 "ts_1" : ts6 , # Not in mapping, uses default
897911 "int_col" : exp .DataType .build ("INT" ),
898912 "varchar_col" : exp .DataType .build ("VARCHAR(100)" ),
@@ -906,11 +920,11 @@ def test_delta_timestamps_with_empty_mapping(make_mocked_engine_adapter: t.Calla
906920 user = "user" ,
907921 host = "host" ,
908922 catalog = "catalog" ,
909- trino_to_delta_timestamp_mapping = {},
923+ timestamp_mapping = {},
910924 )
911925
912926 adapter = make_mocked_engine_adapter (
913- TrinoEngineAdapter , trino_to_delta_timestamp_mapping = config .trino_to_delta_timestamp_mapping
927+ TrinoEngineAdapter , timestamp_mapping = config .timestamp_mapping
914928 )
915929
916930 ts6 = exp .DataType .build ("timestamp(6)" )
0 commit comments