Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CT-2121] Make model contracts agnostic to ordering #6975

Closed
Tracked by #6747
MichelleArk opened this issue Feb 14, 2023 · 1 comment · Fixed by #7161
Closed
Tracked by #6747

[CT-2121] Make model contracts agnostic to ordering #6975

MichelleArk opened this issue Feb 14, 2023 · 1 comment · Fixed by #7161
Assignees
Labels
model_contracts multi_project user docs [docs.getdbt.com] Needs better documentation

Comments

@MichelleArk
Copy link
Contributor

MichelleArk commented Feb 14, 2023

The current model contract comparison (assert_columns_equivalent macro) validates that the user-provided column names and data types are identical: in name, type, and order the column names obtained from the model SQL.

However, it will be cumbersome for users to ensure that the order of configured columns in a model yaml file always matches with the order the database provides.

For example, the SQL model configured with the schema below fails its contract check:

-- model.sql
SELECT 1 as a, 2 as b
-- schema.yml
models:
- model: 
  contract: True
  columns:
    - name: b
       data_type: INT
    - name: a
       data_type: INT

The equality comparison is done directly on formatted columns from the SQL + schema yaml, and could instead be done on the intermediate collection of unordered columns.

Relevant discussion: #6271 (comment)

Note: should not be merged before #7064, as this ordering check is currently done in assert_columns_equivalent and prevents constraint ddl generation from being generated in an invalid order.

@github-actions github-actions bot changed the title Make model contracts agnostic to ordering [CT-2121] Make model contracts agnostic to ordering Feb 14, 2023
@MichelleArk MichelleArk added the user docs [docs.getdbt.com] Needs better documentation label Feb 28, 2023
@gshank gshank self-assigned this Mar 10, 2023
@gshank
Copy link
Contributor

gshank commented Mar 13, 2023

Note: #7064 cannot be merged before this because the column checks would fail. These two tickets will processed in one pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
model_contracts multi_project user docs [docs.getdbt.com] Needs better documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants