Skip to content

Conversation

@themisvaltinos
Copy link
Contributor

This adds support to detect table references in column expressions for models and ctes (e.g. sushi.orders.customer_id). (needed for: #4718)

@themisvaltinos themisvaltinos changed the title Fix(lsp): Extend support for table references to when used with columns Fix(lsp): Extend support for table references with columns Jun 19, 2025
The Range covering the table reference in the column
"""

table_parts = column.parts[:-1] if len(column.parts) > 1 else [column.parts[0]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about the else branch here. If there's only one part in a Column instance, isn't that the column name and not a table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually yes there's no need for it altogether since if we're here it would have more than one part so table_parts = column.parts[:-1] will be enough

Comment on lines 842 to 848
table_parts = [part.name for part in column.parts[:-1]]
table_ref = ".".join(table_parts)
normalized_reference_name = normalize_model_name(
table_ref,
default_catalog=default_catalog,
dialect=dialect,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This section seems a little sketchy: part.name gets rid of the quotes, so normalize_model_name will normalize even case-sensitive (quoted) identifiers. Has this been tested / taken into account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes the reference_name it compares it too has gone through the same normalisation in get_model_definitions_for_a_path this is why, but I will test further with more edge cases to ensure

Copy link
Contributor Author

@themisvaltinos themisvaltinos Jun 19, 2025

Choose a reason for hiding this comment

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

revised it to use .sql(0 instead which is used in get_model_definitions_for_a_path as well and added a test for it : test_quoted_uppercase_table_and_column_references

@themisvaltinos themisvaltinos merged commit a830e4c into main Jun 20, 2025
25 checks passed
@themisvaltinos themisvaltinos deleted the themis/refere branch June 20, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants