Skip to content

fix: normalize internal state timestamps#18

Merged
nicosuave merged 1 commit into
mainfrom
fix/state-created-at-timestamp
Jun 19, 2026
Merged

fix: normalize internal state timestamps#18
nicosuave merged 1 commit into
mainfrom
fix/state-created-at-timestamp

Conversation

@nicosuave

Copy link
Copy Markdown
Member

Summary

  • Normalize dlt internal metadata timestamp columns before Iceberg schema inference/evolution.
  • Keep _dlt_pipeline_state.created_at as Iceberg timestamp when incoming Arrow batches are timestamp[us, tz=UTC].
  • Align _dlt_loads.inserted_at with the existing naive UTC TimestampType convention used by _dlt_version.

Addresses #9.

Tests

  • uv run pytest tests/test_with_state_sync.py::TestWithStateSyncMethods::test_state_table_created_at_timestamptz_batch_matches_existing_timestamp_schema -q
  • uv run pytest tests/test_with_state_sync.py tests/test_load_metadata_resilience.py tests/test_schema_evolution.py -q
  • uv run pytest tests/test_class_based_atomic.py tests/test_e2e_sqlite_catalog.py tests/test_destination_e2e.py -q
  • uv run pytest tests/test_schema_converter.py tests/test_schema_casting.py tests/test_state_sync_e2e.py -q
  • uv run pytest -q -m "not integration" (148 passed, 15 deselected)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e303bc7c1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/dlt_iceberg/destination_client.py Outdated
(
table_schema,
file_path,
_normalize_internal_metadata_timestamps(table_name, arrow_table),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve existing timestamptz metadata tables

When an internal metadata table was already created by the previous code with Iceberg TimestamptzType (for example _dlt_pipeline_state.created_at from an earlier timestamp[us, tz=UTC] batch), this unconditional normalization turns the next incoming batch into TimestampType before schema evolution runs. The existing-table path then compares TimestamptzType to TimestampType and evolve_schema_if_needed rejects that as an unsafe type change, so affected pipelines fail on the first run after upgrading instead of simply casting to the existing schema. Consider only normalizing when the existing column is already TimestampType, or treating the internal timestamp/timestamptz pair as compatible during evolution.

Useful? React with 👍 / 👎.

@nicosuave nicosuave force-pushed the fix/state-created-at-timestamp branch from 5e303bc to 62a752d Compare June 19, 2026 22:19
@nicosuave nicosuave merged commit 355e307 into main Jun 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant