:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(data-warehouse): force microsecond precision for snowflake arrow batches (#61842)
Marcus Hof1b3c9cfc744c
diff --git a/posthog/temporal/data_imports/sources/snowflake/snowflake.py b/posthog/temporal/data_imports/sources/snowflake/snowflake.pyindex 4170afd5e961..cd0c7d8a6f7d 100644--- a/posthog/temporal/data_imports/sources/snowflake/snowflake.py+++ b/posthog/temporal/data_imports/sources/snowflake/snowflake.py@@ -446,7 +446,14 @@ class SnowflakeImplementation(# We cant control the batch size from snowflake when using the arrow function# https://github.com/snowflakedb/snowflake-connector-python/issues/1712- yield from streaming_cursor.fetch_arrow_batches()+ #+ # Force microsecond precision so every batch shares one timestamp unit.+ # Otherwise the connector picks the unit per batch from the data — `ns` for+ # values in the nanosecond range (~1677–2262) and `us` for anything outside it+ # (e.g. a `0001-01-01`/`9999-12-31` sentinel) — and the mixed units make+ # pyarrow fail to assemble the batches ("Schema at index N was different").+ # The pipeline normalizes timestamps to `us` downstream regardless.+ yield from streaming_cursor.fetch_arrow_batches(force_microsecond_precision=True)name = NamingConvention.normalize_identifier(table_name)diff --git a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.pyindex 4375b30d9989..187da0c8034e 100644--- a/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py+++ b/posthog/temporal/data_imports/sources/snowflake/tests/test_snowflake.py@@ -369,3 +369,5 @@ class TestBuildPipeline:assert response.primary_keys == ["id"]assert response.rows_to_sync == 5assert list(response.items()) == [b"batch-1", b"batch-2"]+ # Pin a single timestamp unit so mixed ns/us batches don't break pyarrow assembly.+ streaming_cursor.fetch_arrow_batches.assert_called_once_with(force_microsecond_precision=True)