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 17:09:18 UTC

(superset) 03/03: fix(partition-mapping): preview the transform at an instant off every boundary

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

commit 9261bfe4236c14209c2fef32de8349fbfe0d8421
Author: Hugh A Miles II <hu...@gmail.com>
AuthorDate: Wed Oct 21 18:08:30 2026 +0100

    fix(partition-mapping): preview the transform at an instant off every boundary
    
    The preview sample was 2026-01-15 00:00:00, where :value and an hour- or
    day-floored :value are the same number, so a bucketing transform that did not
    round previewed as valid. Epoch, strftime-text and TIMESTAMP/DATETIME samples
    are now 10:47:23; DATE and untyped columns keep midnight, since a time of day
    declines an equality on a day-resolution column.
    
    Co-Authored-By: Claude Opus 5.5 <no...@anthropic.com>
---
 .../PartitionFilterMapping/utils.test.ts           | 33 +++++++++++++--
 .../components/PartitionFilterMapping/utils.ts     | 47 +++++++++++++++++-----
 2 files changed, 66 insertions(+), 14 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 9e11a8e3ed5..18c6486a439 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
@@ -613,7 +613,7 @@ test('a temporal column stored as a number previews in its stored representation
       is_dttm: true,
       python_date_format: 'epoch_s',
     }),
-  ).toEqual(['1768435200']);
+  ).toEqual(['1768474043']);
   expect(
     sampleValuesFor({
       column_name: 'event_epoch_ms',
@@ -621,7 +621,7 @@ test('a temporal column stored as a number previews in its stored representation
       is_dttm: true,
       python_date_format: 'epoch_ms',
     }),
-  ).toEqual(['1768435200000']);
+  ).toEqual(['1768474043000']);
   // A numeric temporal column without an epoch format still gets numbers,
   // never a timestamp string its own type cannot hold.
   expect(
@@ -634,6 +634,31 @@ test('a temporal column stored as a number previews in its stored representation
       is_dttm: true,
       python_date_format: 'epoch_s',
     }),
+  ).toEqual(['2026-01-15 10:47:23']);
+});
+
+test('the sample instant sits off every hour and day boundary', () => {
+  // At a boundary, `:value` and an hour- or day-floored `:value` are the same
+  // number, so a transform that forgot to round previewed as valid. Ribbon's
+  // hour bucket is the case: `:value - :value % 3600` and plain `:value` must
+  // preview differently.
+  const [epoch] = sampleValuesFor({
+    column_name: 'event_epoch',
+    type: 'BIGINT',
+    is_dttm: true,
+    python_date_format: 'epoch_s',
+  });
+  expect(Number(epoch) % 3600).not.toBe(0);
+  expect(
+    sampleValuesFor({ column_name: 'ts', type: 'DATETIME', is_dttm: true }),
+  ).toEqual(['2026-01-15 10:47:23']);
+});
+
+test('a column that may compare by the day keeps a midnight sample', () => {
+  // A time of day on a day-resolution column declines an equality, so the
+  // preview would report a working DATE mapping as broken.
+  expect(
+    sampleValuesFor({ column_name: 'ds', type: 'DATE', is_dttm: true }),
   ).toEqual(['2026-01-15 00:00:00']);
 });
 
@@ -658,7 +683,7 @@ test('a temporal column stored as formatted text previews in that format', () =>
       is_dttm: true,
       python_date_format: '%Y-%m-%d %H:%M:%S',
     }),
-  ).toEqual(['2026-01-15 00:00:00']);
+  ).toEqual(['2026-01-15 10:47:23']);
   expect(
     sampleValuesFor({
       column_name: 'ds',
@@ -677,7 +702,7 @@ test('a temporal column stored as formatted text previews in that format', () =>
       is_dttm: true,
       python_date_format: '%Y%m%d',
     }),
-  ).toEqual(['2026-01-15 00:00:00']);
+  ).toEqual(['2026-01-15 10:47:23']);
 
   // And a directive the renderer does not know falls back rather than sending
   // a sample with a literal `%c` in it.
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 d908a8e473b..8fed6311045 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
@@ -302,14 +302,34 @@ export function defaultTransformFor(
 const NUMERIC_TYPE_RE =
   /INT|NUMERIC|DECIMAL|DOUBLE|FLOAT|REAL|NUMBER|BIGNUMERIC/i;
 
-/** The sample instant, 2026-01-15 00:00:00 UTC, in each epoch representation. */
+/**
+ * The sample instant, 2026-01-15 10:47:23 UTC, in each epoch representation.
+ *
+ * Deliberately off every boundary. Bucketing is the usual transform -- an epoch
+ * floored to the hour or the day -- and at a boundary a transform that does not
+ * round at all answers exactly what one that rounds correctly does, so the
+ * preview showed a broken key as valid.
+ */
 const EPOCH_SAMPLES: Record<string, string> = {
-  epoch_s: '1768435200',
-  epoch_ms: '1768435200000',
+  epoch_s: '1768474043',
+  epoch_ms: '1768474043000',
 };
 
-/** The sample instant as ISO text, which is what an unformatted column gets. */
-const TIMESTAMP_SAMPLE = '2026-01-15 00:00:00';
+/** The sample instant as ISO text, for a column whose type keeps a time of day. */
+const TIMESTAMP_SAMPLE = '2026-01-15 10:47:23';
+
+/**
+ * The same day at midnight, for a column that may be compared by the day.
+ *
+ * A `DATE` column -- or one whose declared type is unknown -- can compare at
+ * day resolution, where an equality carrying a time of day is declined
+ * (`_engine_literal_resolution`), and a preview of `=` with the off-boundary
+ * sample would report a working mapping as broken.
+ */
+const DATE_SAMPLE = '2026-01-15 00:00:00';
+
+/** Declared types that keep a time of day: TIMESTAMP, DATETIME, TIME. */
+const TIME_OF_DAY_TYPE_RE = /TIME/i;
 
 /**
  * Declared types the engine renders a datetime for on its own.
@@ -334,10 +354,10 @@ const STRFTIME_FIELDS: Record<string, string> = {
   y: '26',
   m: '01',
   d: '15',
-  H: '00',
-  I: '12',
-  M: '00',
-  S: '00',
+  H: '10',
+  I: '10',
+  M: '47',
+  S: '23',
   f: '000000',
   j: '015',
   p: 'AM',
@@ -411,7 +431,14 @@ export function sampleValuesFor(
         format.includes('%') && !TEMPORAL_TYPE_RE.test(column.type ?? '')
           ? renderSampleWithFormat(format)
           : undefined;
-      return [formatted || TIMESTAMP_SAMPLE];
+      if (formatted) {
+        return [formatted];
+      }
+      return [
+        TIME_OF_DAY_TYPE_RE.test(column.type ?? '')
+          ? TIMESTAMP_SAMPLE
+          : DATE_SAMPLE,
+      ];
     }
     const epochSample = EPOCH_SAMPLES[format];
     if (epochSample) {