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

Rebase #7223: improve contracts error message #7319

Merged
merged 11 commits into from
Apr 11, 2023

Conversation

jtcohen6
Copy link
Contributor

@jtcohen6 jtcohen6 commented Apr 11, 2023

resolves #7209
rebases #7223

Description

@kentkr did the heavy lifting here! I just added a few small touch-ups:

  • Only display columns with diffs / mismatches
  • Use agate for structured representation, and to print to stdout in a markdown table
09:52:16  Completed with 1 error and 0 warnings:
09:52:16
09:52:16  Compilation Error in model my_important_model (models/.../my_important_model.sql)
09:52:16    This model has an enforced contract that failed.
09:52:16    Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.
09:52:16
09:52:16    | column_name                 | definition_type | contract_type | mismatch_reason       |
09:52:16    | --------------------------- | --------------- | ------------- | --------------------- |
09:52:16    | ADDRESS_ZIP                 | TEXT            | FIXED         | data type mismatch    |
09:52:16    | HAS_DOCS                    | FIXED           | BOOLEAN       | data type mismatch    |
09:52:16    | HAS_SUCCESSFUL_SESSION      | FIXED           |               | missing in contract   |
09:52:16    | HAS_VERY_SUCCESSFUL_SESSION |                 | FIXED         | missing in definition |
09:52:16
09:52:16
09:52:16    > in macro assert_columns_equivalent (macros/materializations/models/table/columns_spec_ddl.sql)
09:52:16    > called by macro default__get_assert_columns_equivalent (macros/materializations/models/table/columns_spec_ddl.sql)
09:52:16    > called by macro get_assert_columns_equivalent (macros/materializations/models/table/columns_spec_ddl.sql)
09:52:16    > called by macro snowflake__create_table_as (macros/adapters.sql)
09:52:16    > called by macro create_table_as (macros/materializations/models/table/create_table_as.sql)
09:52:16    > called by macro statement (macros/etc/statement.sql)
09:52:16    > called by macro materialization_table_snowflake (macros/materializations/table.sql)
09:52:16    > called by model my_important_model (models/.../my_important_model.sql)

Checklist

@cla-bot
Copy link

cla-bot bot commented Apr 11, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Kyle Kent.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https:/settings/emails

@jtcohen6 jtcohen6 force-pushed the jerco/rebase-7223-contract-error-message branch from 9cb5b3f to 5d58707 Compare April 11, 2023 10:06
@cla-bot cla-bot bot added the cla:yes label Apr 11, 2023
row = [yaml_col["name"], "", yaml_col["data_type"], "missing in definition"]
mismatches += [dict(zip(column_names, row))]

mismatches_sorted = sorted(mismatches, key=lambda d: d["column_name"])
Copy link
Contributor

@MichelleArk MichelleArk Apr 11, 2023

Choose a reason for hiding this comment

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

💯✨

# if name matches
if sql_col["name"] == yaml_col["name"]:
# if type matches
if sql_col["formatted"] == yaml_col["formatted"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

for my own understanding - any reason not to do the comparison on data_type at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MichelleArk Good point! Since we're already comparing columns with the same name, might as well compare just the data_type instead of the formatted value.

This was just how Kyle had it, and it does match the logic here performing the functional comparison.

@jtcohen6 jtcohen6 merged commit c9d4051 into main Apr 11, 2023
@jtcohen6 jtcohen6 deleted the jerco/rebase-7223-contract-error-message branch April 11, 2023 16:27
@kentkr
Copy link
Contributor

kentkr commented Apr 11, 2023

Thanks @jtcohen6 !

@dbeatty10
Copy link
Contributor

Nice work @kentkr ! 🏆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-2322] [Feature] Side-by-side diff when an enforced model contract fails
5 participants