You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2026/10/21 18:00:46 UTC

(superset) branch hughhhh/pfm-6-explore-indicator updated: fix(partition-mapping): report a mapping onto an array column as inactive

This is an automated email from the ASF dual-hosted git repository.

hughhhh pushed a commit to branch hughhhh/pfm-6-explore-indicator
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/hughhhh/pfm-6-explore-indicator by this push:
     new 4d2053daaa9 fix(partition-mapping): report a mapping onto an array column as inactive
4d2053daaa9 is described below

commit 4d2053daaa91e3dfc05209c6e82647aff910aee1
Author: Hugh A Miles II <hu...@gmail.com>
AuthorDate: Wed Oct 21 19:00:31 2026 +0100

    fix(partition-mapping): report a mapping onto an array column as inactive
    
    482b72ac50 stopped the broken predicate, but only at the per-value type
    gate: the probe of :value still succeeded and recorded a working
    transform, so Explore kept the partition icon on the filter and the editor
    banner still said filters would apply to the array column (SC-128852,
    page 3). An array partition column can never take a mirror, so
    resolve_partition_mapping, the summary's active flag and the editor's own
    check now all refuse it up front -- which also skips the probe.
    
    Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
 .../PartitionFilterMapping/utils.test.ts           | 21 ++++++++++++++++
 .../components/PartitionFilterMapping/utils.ts     | 16 +++++++++++++
 superset/connectors/sqla/models.py                 |  2 ++
 superset/connectors/sqla/partition_mapping.py      |  7 ++++++
 .../connectors/sqla/partition_mapping_test.py      | 28 ++++++++++++++++++++++
 .../unit_tests/models/partition_mirroring_test.py  | 11 +++++----
 6 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.test.ts b/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.test.ts
index 6eb7f816248..90faa2d3403 100644
--- a/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.test.ts
+++ b/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.test.ts
@@ -611,6 +611,27 @@ test('a temporal column stored as a number or as text gets no pre-fill', () => {
   ).toBe('unix_timestamp(:value)');
 });
 
+test('a mapping onto an array partition column is never active', () => {
+  // SC-128852: the banner said filters would apply to `region_keys TEXT[]`,
+  // which no mirror can compare against.
+  const datasource = {
+    main_dttm_col: 'event_time',
+    partition_column: 'region_keys',
+    partition_mapped_column: 'region',
+  };
+  const columns = (partitionType: string) => [
+    {
+      column_name: 'region',
+      type: 'TEXT',
+      partition_value_transform: ':value',
+    },
+    { column_name: 'region_keys', type: partitionType },
+  ];
+  expect(mappingIsActive(datasource, columns('TEXT'))).toBe(true);
+  expect(mappingIsActive(datasource, columns('TEXT[]'))).toBe(false);
+  expect(mappingIsActive(datasource, columns('ARRAY<STRING>'))).toBe(false);
+});
+
 test('an engine with no default offers no pre-fill', () => {
   // `unix_timestamp(:value)` would not parse on Postgres, and a wrong default
   // is worse than none.
diff --git a/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.ts b/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.ts
index 588a837e6d9..4553d6eedd4 100644
--- a/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.ts
+++ b/superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.ts
@@ -96,6 +96,13 @@ export function transformCanPreview(
   return true;
 }
 
+/**
+ * A declared type naming an array, as the server's `declares_array_type` reads
+ * it: PostgreSQL's `TEXT[]`, and the `ARRAY<...>` / `ARRAY(...)` / `Array(...)`
+ * spellings.
+ */
+const ARRAY_TYPE_RE = /(\[\s*\d*\s*\])+\s*$|^\s*ARRAY\b/i;
+
 /**
  * Whether the mapping will actually mirror anything.
  *
@@ -120,6 +127,15 @@ export function mappingIsActive(
   if (!mappedColumnName || mappedColumnName === datasource.partition_column) {
     return false;
   }
+  // An array partition column can never take a mirror: there is no scalar a
+  // transform could return that compares. The server refuses the mapping the
+  // same way (`declares_array_type`), so the banner must not promise one.
+  const partitionColumn = columns.find(
+    column => column.column_name === datasource.partition_column,
+  );
+  if (partitionColumn?.type && ARRAY_TYPE_RE.test(partitionColumn.type)) {
+    return false;
+  }
   const mappedColumn = columns.find(
     column => column.column_name === mappedColumnName,
   );
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 6206f635ed8..97dee582a12 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -72,6 +72,7 @@ from superset_core.common.models import Dataset as CoreDataset
 from superset import db, is_feature_enabled, security_manager
 from superset.common.db_query_status import QueryStatus
 from superset.connectors.sqla.partition_mapping import (
+    declares_array_type,
     equality_mirrors_safely,
     FEATURE_FLAG as PARTITION_FILTER_MAPPING_FLAG,
     has_active_advanced_data_type,
@@ -2059,6 +2060,7 @@ class SqlaTable(
         transform = mapped_column.partition_value_transform if mapped_column else None
         active = bool(
             self.partition_column in columns_by_name
+            and not declares_array_type(columns_by_name[self.partition_column].type)
             and mapped_column is not None
             and mapped_column_name != self.partition_column
             and is_transform_active(transform, self.database.backend)
diff --git a/superset/connectors/sqla/partition_mapping.py b/superset/connectors/sqla/partition_mapping.py
index 443c8c6ff49..f366368ccc9 100644
--- a/superset/connectors/sqla/partition_mapping.py
+++ b/superset/connectors/sqla/partition_mapping.py
@@ -1159,6 +1159,13 @@ def resolve_partition_mapping(datasource: SqlaTable) -> PartitionMapping | None:
         # Self-mapping: the mirrored predicate would duplicate the original.
         return None
 
+    # An array holds no scalar a transform could return, so no mirror onto it
+    # can ever compare. Refused for the mapping rather than only per value, so
+    # the Explore glyph stops promising one: a probe of ``:value`` succeeds and
+    # records a working transform, and only the later type gate declined.
+    if declares_array_type(columns_by_name[partition_column].type):
+        return None
+
     mapped_column = columns_by_name[mapped_column_name]
     transform = getattr(mapped_column, "partition_value_transform", None)
     if not is_transform_active(transform, datasource.database.backend):
diff --git a/tests/unit_tests/connectors/sqla/partition_mapping_test.py b/tests/unit_tests/connectors/sqla/partition_mapping_test.py
index 78ba14d1aa0..c61932aa53e 100644
--- a/tests/unit_tests/connectors/sqla/partition_mapping_test.py
+++ b/tests/unit_tests/connectors/sqla/partition_mapping_test.py
@@ -581,6 +581,34 @@ def test_resolve_returns_none_when_the_feature_flag_is_off(app: Flask) -> None:
             assert resolve_partition_mapping(table) is None
 
 
+def test_an_array_partition_column_resolves_no_mapping(app: Flask) -> None:
+    """
+    SC-128852, page 3: with only the per-value refusal the chart stopped
+    failing, but the glyph stayed lit -- the probe of ``:value`` succeeds and
+    records a working transform. An array partition column can never take a
+    mirror, so the mapping itself is refused, and the summary the glyph reads
+    reports it inactive.
+    """
+    table = _mapped_table(
+        partition_column="region_keys",
+        mapped_column="country",
+        partition_mapped_column="country",
+        transform=":value",
+    )
+    region_keys = TableColumn(column_name="region_keys", type="VARCHAR")
+    table.columns.append(region_keys)
+    with app.app_context():
+        # The same mapping onto a scalar column is live, so what follows is the
+        # array type's doing and nothing else's.
+        assert resolve_partition_mapping(table) is not None
+
+        region_keys.type = "TEXT[]"
+        assert resolve_partition_mapping(table) is None
+        summary = table.partition_filter_mapping_summary
+        assert summary is not None
+        assert summary["active"] is False
+
+
 def test_resolve_returns_none_without_a_partition_column(app: Flask) -> None:
     table = _mapped_table()
     table.partition_column = None
diff --git a/tests/unit_tests/models/partition_mirroring_test.py b/tests/unit_tests/models/partition_mirroring_test.py
index d8d43f20477..f02504d38d6 100644
--- a/tests/unit_tests/models/partition_mirroring_test.py
+++ b/tests/unit_tests/models/partition_mirroring_test.py
@@ -3163,8 +3163,9 @@ def test_an_array_partition_column_gets_no_mirror(app: Flask) -> None:
     instead of losing its pruning, which is the one outcome this feature may
     not have.
 
-    `probed_value_type_error` refuses it for the *column*, since an array holds
-    no scalar at all and there is no result that could compare. The mapped
+    It is refused for the *mapping*, since an array holds no scalar at all and
+    there is no result that could compare: `resolve_partition_mapping` declines
+    it before any probe, so the warehouse is not asked either. The mapped
     column is numeric here because `equality_mirrors_safely` withdraws ``=`` on
     a text column under ClickHouse anyway, which would mask the gate under test.
     """
@@ -3195,9 +3196,9 @@ def test_an_array_partition_column_gets_no_mirror(app: Flask) -> None:
                     ],
                 )
 
-    # The probe is reached -- the decline is the type gate's, not an earlier
-    # one's -- and nothing is mirrored onto the array.
-    assert probe.called
+    # Declined before the probe -- no round trip for a mapping that can never
+    # mirror -- and nothing is mirrored onto the array.
+    assert not probe.called
     assert "region_keys" not in sql
     # The filter itself is untouched: the query is still correct, it just reads
     # every partition.