codeant-ai-for-open-source[bot] commented on code in PR #41727:
URL: https://github.com/apache/superset/pull/41727#discussion_r3517857344


##########
superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/transformData.ts:
##########
@@ -0,0 +1,164 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { DTTM_ALIAS } from '@superset-ui/core';
+
+const DAY_MS = 24 * 60 * 60 * 1000;
+const WEEKDAYS = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'];
+
+/**
+ * Rolls a timestamp back to the start of its period the way pandas
+ * offset.rollback(normalize=True) does for the offset aliases the
+ * frequency control offers (AS/A, MS/M, W and W-XXX, D, H, T/MIN).
+ * The multiplier prefix (e.g. 52W-MON) does not change the anchor.
+ */
+export const rollback = (timestamp: number, freq: string): number => {
+  const match = /^\d*(AS|YS|A|Y|MS|M|W(?:-([A-Z]{3}))?|D|H|T|MIN)$/i.exec(
+    (freq || 'W-MON').trim(),
+  );
+  const date = new Date(timestamp);
+  const midnight = Date.UTC(
+    date.getUTCFullYear(),
+    date.getUTCMonth(),
+    date.getUTCDate(),
+  );
+  if (!match) {
+    return midnight; // freeform rules fall back to day boundaries
+  }

Review Comment:
   **Suggestion:** The new frequency parser only supports a narrow alias subset 
and silently falls back to daily boundaries for everything else, which 
regresses legacy behavior where free-form pandas offsets were accepted. 
Existing charts using valid pandas aliases outside this regex (for example 
quarterly/business offsets) will now be bucketed incorrectly instead of 
honoring the configured period. Preserve full pandas-compatible semantics (or 
explicitly reject unsupported aliases) rather than silently coercing to daily 
rollback. [incomplete implementation]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Time-series Period Pivot misbuckets unsupported pandas freq aliases.
   - ⚠️ Existing quarterly/business frequency charts show incorrect period 
overlays.
   - ⚠️ Users receive no error when freq silently downgraded.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Configure a Time-series Period Pivot chart in Explore with `viz_type: 
'time_pivot'`
   (metadata defined in
   
`superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/index.ts:5-16`)
 and set
   the Frequency control `freq` to a valid pandas offset alias that is not 
covered by the new
   regex, e.g. `'Q'` for quarterly frequency, using the free-form SelectControl 
in
   
`superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/controlPanel.ts:11-27`
   which explicitly allows arbitrary "Pandas" offset aliases.
   
   2. When the chart is run, `ChartDataProvider`
   
(`superset-frontend/packages/superset-ui-core/src/chart/components/ChartDataProvider.tsx:69-123`)
   invokes `ChartClient.loadQueryData`, which, for `viz_type: 'time_pivot'`, 
uses the chart
   metadata without `useLegacyApi: true` (see `TimePivot/index.ts:5-16`) and 
therefore calls
   the v1 endpoint `/api/v1/chart/data` (decision logic in 
`ChartClient.loadQueryData` at
   
`superset-frontend/packages/superset-ui-core/src/chart/clients/ChartClient.ts:98-124`).
   
   3. The v1 response arrives in the frontend as `queriesData[0].data`, an 
array of flat
   records with `__timestamp` and metric fields, and TimePivot’s transformProps
   
(`superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/transformProps.ts:23-34`)
   assigns `rawData = queriesData[0].data` and calls `transformData(rawData,
   getMetricLabel(formData.metric), formData.freq as string)`, passing the 
free-form `freq`
   value `'Q'`.
   
   4. Inside `transformData.rollback`
   
(`superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/transformData.ts:24-42`),
   the regex `/^\d*(AS|YS|A|Y|MS|M|W(?:-([A-Z]{3}))?|D|H|T|MIN)$/i` does not 
match `'Q'`, so
   `match` is null and the function returns `midnight` (day boundary) in the 
`if (!match) {
   return midnight; }` branch, causing all timestamps to be bucketed at daily 
boundaries
   instead of quarterly ones, unlike the legacy backend implementation
   (`superset/viz.py:31-43`) which used `pandas.to_offset(freq).rollback` and 
supported the
   full pandas offset alias set; as a result, existing time_pivot charts 
configured with
   quarterly or business frequencies are now period-bucketed incorrectly 
without any error.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=26deee88f2c34c8a9547f5541a1bbb8e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=26deee88f2c34c8a9547f5541a1bbb8e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/legacy-preset-chart-nvd3/src/TimePivot/transformData.ts
   **Line:** 31:42
   **Comment:**
        *Incomplete Implementation: The new frequency parser only supports a 
narrow alias subset and silently falls back to daily boundaries for everything 
else, which regresses legacy behavior where free-form pandas offsets were 
accepted. Existing charts using valid pandas aliases outside this regex (for 
example quarterly/business offsets) will now be bucketed incorrectly instead of 
honoring the configured period. Preserve full pandas-compatible semantics (or 
explicitly reject unsupported aliases) rather than silently coercing to daily 
rollback.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41727&comment_hash=34113a9961739940beb56760681098f00c7acf4c3ad8b00cf015af469c73b30d&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41727&comment_hash=34113a9961739940beb56760681098f00c7acf4c3ad8b00cf015af469c73b30d&reaction=dislike'>👎</a>



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