-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
spike: inferred contracts #8339
Draft
MichelleArk
wants to merge
2
commits into
main
Choose a base branch
from
7432/inferred-contract-spike
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,22 @@ | |
|
||
{% macro table_columns_and_constraints() %} | ||
{# loop through user_provided_columns to create DDL with data types and constraints #} | ||
{%- if defer_relation and config.get('contract').inferred -%} | ||
{% set prod_columns = get_column_schema_from_query(get_empty_subquery_sql("select * from " ~ defer_relation)) %} | ||
{% set raw_columns = {} %} | ||
{% for column in prod_columns -%} | ||
{# TODO: reconsider this mutating operation, could be done with an additional warehouse call #} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 At minimum, we should probably be deepcopying to avoid mutating the user-provided value stored in the context... right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can either:
|
||
{%- if column.name not in model['columns'] -%} | ||
{% do model['columns'].update( | ||
{column.name: {'name': column.name, 'data_type': column.data_type, 'description': '', 'constraints': [], 'tags': [], 'meta': {}}} | ||
) %} | ||
{%- endif -%} | ||
{% endfor -%} | ||
{%- endif -%} | ||
|
||
{%- set raw_column_constraints = adapter.render_raw_columns_constraints(raw_columns=model['columns']) -%} | ||
{%- set raw_model_constraints = adapter.render_raw_model_constraints(raw_constraints=model['constraints']) -%} | ||
|
||
( | ||
{% for c in raw_column_constraints -%} | ||
{{ c }}{{ "," if not loop.last or raw_model_constraints }} | ||
|
@@ -36,15 +50,30 @@ | |
|
||
{#-- First ensure the user has defined 'columns' in yaml specification --#} | ||
{%- set user_defined_columns = model['columns'] -%} | ||
{%- if not user_defined_columns -%} | ||
|
||
{%- if not user_defined_columns and not config.get('contract').inferred -%} | ||
{{ exceptions.raise_contract_error([], []) }} | ||
{%- endif -%} | ||
|
||
{#-- Obtain the column schema provided by sql file. #} | ||
{%- set sql_file_provided_columns = get_column_schema_from_query(sql, config.get('sql_header', none)) -%} | ||
{#--Obtain the column schema provided by the schema file by generating an 'empty schema' query from the model's columns. #} | ||
{%- set schema_file_provided_columns = get_column_schema_from_query(get_empty_schema_sql(user_defined_columns)) -%} | ||
{%- if defer_relation and config.get('contract').inferred -%} | ||
{% set prod_columns = get_column_schema_from_query(get_empty_subquery_sql("select * from " ~ defer_relation)) %} | ||
|
||
{% set provided_column_dict = {} %} | ||
{%- for provided_column in schema_file_provided_columns-%} | ||
{%- do provided_column_dict.update({provided_column.name: provided_column}) %} | ||
{%- endfor -%} | ||
|
||
{#-- Add any inferred columns not provided to full list of provided columns #} | ||
{%- for prod_colum in prod_columns -%} | ||
{%- if prod_colum.name not in provided_column_dict -%} | ||
{% do schema_file_provided_columns.append(prod_colum) -%} | ||
{%- endif -%} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
{#-- create dictionaries with name and formatted data type and strings for exception #} | ||
{%- set sql_columns = format_columns(sql_file_provided_columns) -%} | ||
{%- set yaml_columns = format_columns(schema_file_provided_columns) -%} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely want to avoid the need for this. I had previously wondered if we'd be able to consolidate the deferral methods used by
clone
and other commands, by:defer_relation
for selected resources only (to supportclone
)(this comment/issue: #7965)
Edit: Michelle already made this change below. Then we can also refactor the
clone
task to usemerge_from_artifact
, and deleteadd_from_artifact
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussing live with @MichelleArk: We should overwrite
compiled_code
(also aliased assql
) within theclone
task. Then we don't need to have this task-aware conditional logic live in the context method.