Repository navigation
Conversation
… in schema baselines Postgres reports these columns as integer, double precision, time without time zone and timestamp without time zone. A baseline that declares them as int, int4, float, time or timestamp normalized to a different value, so schema_changes_from_baseline reported a type change for every such column. Map the aliases to the value their info schema type already normalizes to, so stored column snapshots are unaffected.
|
👋 @DG47 |
|
@EladBarkay @haritamar would one of you have time to review this? It fixes #1087: on Postgres, |
|
Checking back on the Postgres alias fix for #1087: |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Fixes #1087
Problem
On Postgres,
schema_changes_from_baselinereportstype_changedfor columns whose baselinedata_typeisint,int4,float,timeortimestamp, even though the type has not changed.The table side comes from
information_schema.columns, so it usesinteger,double precision,time without time zoneandtimestamp without time zone.postgres__get_normalized_data_typemapsINTEGERtoINT, INT4andDOUBLE PRECISIONtoFLOAT8, and leaves the twoWITHOUT TIME ZONEnames as they are. The aliases are not in the map, so they never match:Change
Add the five aliases to the Postgres map, each pointing at the value its info schema type already normalizes to. The info schema names themselves are never one of these aliases, so the values written to
schema_columns_snapshotdo not change andschema_changeswill not report a one-off type change for existing tables after upgrading.This keeps
INT, INT4as the normalized value forinteger. Changing it toINT4would read better in alerts, but every Postgres user would then get atype_changedresult for each integer column on the firstschema_changesrun after upgrading, because the previous snapshot storesINT, INT4. I left that out of this PR; happy to change it if you'd rather take that one-time hit.Tests
Added
test_schema_changes_from_baseline_postgres_type_aliases(Postgres only, parametrized overintandint4). It builds a table withinteger,timestamp,timeandfloatcolumns and runsschema_changes_from_baselinewithenforce_types: trueagainst a baseline that uses the aliases. It fails onmasterwith the four results above and passes with this change.Ran locally against Postgres 15 (dbt-core 1.12.6, dbt-postgres 1.11.0):
pytest test_schema_changes.py --target postgres: 4 passedpytest test_schema_changes.py test_exposure_schema_validity.py test_column_anomalies.py test_volume_anomalies.py --target postgres -n 4: 67 passed, 1 skippedpre-commit runon the changed files: all hooks passedSummary by CodeRabbit