-
Notifications
You must be signed in to change notification settings - Fork 2.3k
CT 2196, CT2121 constraints column order #7161
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
Changes from 1 commit
b3002e1
e257ef1
4d06b6c
d64810b
7780040
bbc18b7
561a4a7
3ea1c0a
39fa7b1
852a4b8
bdd555f
6a98e60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2136,6 +2136,22 @@ def get_message(self) -> str: | |
| return msg | ||
|
|
||
|
|
||
| class ContractError(CompilationError): | ||
| def __init__(self, yaml_columns, sql_columns): | ||
| self.yaml_columns = yaml_columns | ||
| self.sql_columns = sql_columns | ||
| super().__init__(msg=self.get_message()) | ||
|
|
||
| def get_message(self) -> str: | ||
| msg = ( | ||
| "Please ensure the name, data_type, and number of columns in your `yml` file " | ||
| "match the columns in your SQL file.\n" | ||
| f"Schema File Columns: {self.yaml_columns}\n" | ||
| f"SQL File Columns: {self.sql_columns}" | ||
| ) | ||
|
Member
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. Were you going to update this as related to #7147? |
||
| return msg | ||
|
|
||
|
|
||
| # not modifying these since rpc should be deprecated soon | ||
| class UnknownAsyncIDException(Exception): | ||
| CODE = 10012 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,31 +37,29 @@ | |
| {#--Obtain the column schema provided by the schema file by generating an 'empty schema' query from the model's columns. #} | ||
mikealfare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {%- set schema_file_provided_columns = get_column_schema_from_query(get_empty_schema_sql(model['columns'])) -%} | ||
|
|
||
| {#-- Build compiler error msg #} | ||
| {%- set sql_file_provided_columns_formatted = format_columns(sql_file_provided_columns) -%} | ||
| {%- set schema_file_provided_columns_formatted = format_columns(schema_file_provided_columns) -%} | ||
| {%- set compiler_error_msg = 'Please ensure the name, data_type, and number of columns in your `yml` file match the columns in your SQL file.\nSchema File Columns: ' ~ (schema_file_provided_columns_formatted|trim) ~ '\n\nSQL File Columns: ' ~ (sql_file_provided_columns_formatted|trim) ~ ' ' -%} | ||
|
|
||
| {#-- For compiler error msg #} | ||
| {%- set sql_columns = (format_columns(sql_file_provided_columns)|trim) -%} | ||
| {%- set yaml_columns = (format_columns(schema_file_provided_columns)|trim) -%} | ||
|
|
||
| {%- if sql_file_provided_columns|length != schema_file_provided_columns|length -%} | ||
| {%- do exceptions.raise_compiler_error(compiler_error_msg) -%} | ||
| {%- do exceptions.raise_contract_error(yaml_columns, sql_columns) -%} | ||
| {%- endif -%} | ||
|
|
||
| {%- for sql_col in sql_file_provided_columns -%} | ||
| {%- set yaml_col = [] -%} | ||
gshank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {%- for schema_col in schema_file_provided_columns -%} | ||
| {%- if schema_col.name == sql_col.name -%} | ||
| {%- do yaml_col.append(schema_col) -%} | ||
| {% break %} | ||
| {%- break -%} | ||
| {%- endif -%} | ||
| {%- endfor -%} | ||
| {%- if not yaml_col -%} | ||
| {#-- Column with name not found in yaml --#} | ||
| {%- do exceptions.raise_compiler_error(compiler_error_msg) -%} | ||
| {%- do exceptions.raise_contract_error(yaml_columns, sql_columns) -%} | ||
| {%- endif -%} | ||
| {%- if sql_col.dtype != yaml_col[0].dtype -%} | ||
|
||
| {#-- Column data types don't match --#} | ||
| {%- do exceptions.raise_compiler_error(compiler_error_msg) -%} | ||
| {%- do exceptions.raise_contract_error(yaml_columns, sql_columns) -%} | ||
| {%- endif -%} | ||
| {%- endfor -%} | ||
|
|
||
|
|
||
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.
It might be useful to sort these both alphabetically (message only) so that it's easier for the user to spot the difference.