rusackas commented on code in PR #41946:
URL: https://github.com/apache/superset/pull/41946#discussion_r3565305641
##########
tests/unit_tests/connectors/sqla/models_test.py:
##########
@@ -542,6 +542,91 @@ def
test_fetch_metadata_with_comment_field_existing_columns(
assert columns_by_name["name"].description == "Updated name description"
+def test_fetch_metadata_sets_expression_for_expanded_nested_columns(
+ mocker: MockerFixture,
+) -> None:
+ """
+ Test that fetch_metadata uses the `expression` hint provided by the db
engine
+ spec (e.g. Trino's expansion of nested `ROW` columns via `expand_rows`) to
set
+ the physical `TableColumn.expression`.
+
+ Without this, a nested column like `metadata.uuid` would have no
expression,
+ causing SQLAlchemy to render the whole dotted `column_name` as a single
quoted
+ identifier (`"metadata.uuid"`), which Trino rejects, instead of the correct
+ per-segment quoting (`"metadata"."uuid"`).
+
+ See: https://github.com/apache/superset/issues/27034
+ """
+ # Mock database
+ database = mocker.MagicMock()
+ database.get_metrics.return_value = []
+
+ # Mock db_engine_spec
+ mock_db_engine_spec = mocker.MagicMock()
+ mock_db_engine_spec.alter_new_orm_column = mocker.MagicMock()
+ database.db_engine_spec = mock_db_engine_spec
+
+ # Create table with a pre-existing (already synced) expanded column, to
also
+ # cover the "sync columns from source" (re-fetch) code path
+ table = SqlaTable(table_name="test_table_nested", database=database)
Review Comment:
Added the type annotation.
##########
tests/unit_tests/connectors/sqla/models_test.py:
##########
@@ -542,6 +542,91 @@ def
test_fetch_metadata_with_comment_field_existing_columns(
assert columns_by_name["name"].description == "Updated name description"
+def test_fetch_metadata_sets_expression_for_expanded_nested_columns(
+ mocker: MockerFixture,
+) -> None:
+ """
+ Test that fetch_metadata uses the `expression` hint provided by the db
engine
+ spec (e.g. Trino's expansion of nested `ROW` columns via `expand_rows`) to
set
+ the physical `TableColumn.expression`.
+
+ Without this, a nested column like `metadata.uuid` would have no
expression,
+ causing SQLAlchemy to render the whole dotted `column_name` as a single
quoted
+ identifier (`"metadata.uuid"`), which Trino rejects, instead of the correct
+ per-segment quoting (`"metadata"."uuid"`).
+
+ See: https://github.com/apache/superset/issues/27034
+ """
+ # Mock database
+ database = mocker.MagicMock()
+ database.get_metrics.return_value = []
+
+ # Mock db_engine_spec
+ mock_db_engine_spec = mocker.MagicMock()
+ mock_db_engine_spec.alter_new_orm_column = mocker.MagicMock()
+ database.db_engine_spec = mock_db_engine_spec
+
+ # Create table with a pre-existing (already synced) expanded column, to
also
+ # cover the "sync columns from source" (re-fetch) code path
+ table = SqlaTable(table_name="test_table_nested", database=database)
+ table.id = 1
+
+ existing_col = TableColumn(
+ column_name="metadata.uuid",
+ type="VARCHAR",
+ table=table,
+ expression="",
+ )
Review Comment:
Added the type annotation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]