Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"requests",
"rich[jupyter]",
"ruamel.yaml",
"sqlglot[rs]~=20.11.0",
"sqlglot[rs]~=21.0.0",
],
extras_require={
"bigquery": [
Expand Down
6 changes: 4 additions & 2 deletions sqlmesh/core/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ def _parse_types(
# MacroVar, it'll render into @<path>, so it won't break staged file path references.
#
# See: https://docs.snowflake.com/en/user-guide/querying-stage
def _parse_table_parts(self: Parser, schema: bool = False) -> exp.Table:
table = self.__parse_table_parts(schema=schema) # type: ignore
def _parse_table_parts(
self: Parser, schema: bool = False, is_db_reference: bool = False
) -> exp.Table:
table = self.__parse_table_parts(schema=schema, is_db_reference=is_db_reference) # type: ignore
table_arg = table.this

if isinstance(table_arg, exp.Var) and table_arg.name.startswith(SQLMESH_MACRO_PREFIX):
Expand Down
4 changes: 3 additions & 1 deletion sqlmesh/core/schema_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,9 @@ def _alter_operation(
root_struct: exp.DataType,
new_kwarg: exp.ColumnDef,
) -> t.List[TableAlterOperation]:
current_type = exp.DataType.build(current_type)
# We don't copy on purpose here because current_type may need to be mutated inside
Copy link
Contributor

Choose a reason for hiding this comment

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

why does data.build mutate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't mutate, it copies current_type which caused an issue in this module because we are mutating the struct expression in several places (search for .pop and .insert calls, as mentioned in the comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so before my sqlglot commit we weren't copying inside DataType.build and this worked because the mutations were being propagated here, now that we copy they don't unless I switch it off here

# _get_operations (struct.expressions.pop and struct.expressions.insert)
current_type = exp.DataType.build(current_type, copy=False)
if self.support_nested_operations:
if new_type.this == current_type.this == exp.DataType.Type.STRUCT:
return self._get_operations(
Expand Down