malon64 commented on code in PR #41055:
URL: https://github.com/apache/superset/pull/41055#discussion_r3414527727


##########
tests/unit_tests/db_engine_specs/test_trino.py:
##########
@@ -343,6 +343,124 @@ def test_get_extra_table_metadata(mocker: MockerFixture) 
-> None:
     assert result["partitions"]["latest"] == {"ds": "01-01-19", "hour": 1}
 
 
+def test_get_extra_table_metadata_iceberg_unpartitioned(
+    mocker: MockerFixture,
+) -> None:
+    """
+    Iceberg ``$partitions`` metadata fields must not be treated as partition
+    columns, so an unpartitioned Iceberg table yields no partition metadata and
+    no latest-partition query.
+    """
+    from superset.db_engine_specs.trino import TrinoEngineSpec
+
+    db_mock = mocker.MagicMock()
+    db_mock.get_indexes = Mock(
+        return_value=[
+            {
+                "name": "partition",
+                "column_names": ["data", "file_count", "record_count", 
"total_size"],
+            }
+        ]
+    )
+    db_mock.get_extra = Mock(return_value={})
+    db_mock.has_view = Mock(return_value=None)
+    db_mock.get_df = Mock()
+    result = TrinoEngineSpec.get_extra_table_metadata(
+        db_mock,
+        Table("test_table", "test_schema"),
+    )
+    assert "partitions" not in result
+    db_mock.get_df.assert_not_called()
+
+
+def test_get_extra_table_metadata_iceberg_partitioned(
+    mocker: MockerFixture,
+) -> None:
+    """
+    A genuinely partitioned Iceberg table exposes a ``partition`` ROW column
+    alongside the metadata fields. Since the real partition columns are nested
+    in the ROW and not directly queryable here, the partition block is skipped
+    rather than generating an invalid latest-partition query.
+    """
+    from superset.db_engine_specs.trino import TrinoEngineSpec
+
+    db_mock = mocker.MagicMock()
+    db_mock.get_indexes = Mock(
+        return_value=[
+            {
+                "name": "partition",
+                "column_names": [
+                    "partition",
+                    "record_count",
+                    "file_count",
+                    "total_size",
+                    "data",
+                ],
+            }
+        ]
+    )
+    db_mock.get_extra = Mock(return_value={})
+    db_mock.has_view = Mock(return_value=None)
+    db_mock.get_df = Mock()
+    result = TrinoEngineSpec.get_extra_table_metadata(
+        db_mock,
+        Table("test_table", "test_schema"),
+    )
+    assert "partitions" not in result
+    db_mock.get_df.assert_not_called()
+
+
+def test_filter_iceberg_partition_indexes() -> None:
+    from superset.db_engine_specs.trino import TrinoEngineSpec

Review Comment:
   docstring added



-- 
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]

Reply via email to