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


##########
superset-frontend/plugins/plugin-chart-table/src/transformProps.ts:
##########
@@ -532,6 +533,20 @@ const transformProps = (
     comparison_type,
     slice_id,
   } = formData;
+  // Build a mapping from column labels to original column names.
+  // When a user creates an adhoc column with a custom label (e.g. 
sqlExpression: "state",
+  // label: "State_Renamed"), the query result uses the label as the column 
name.
+  // Cross-filtering needs the original column name to work on the receiving 
chart.
+  const columnLabelToNameMap: Record<string, string> = {};
+  const formColumns = ensureIsArray(
+    queryMode === QueryMode.Raw ? formData.all_columns : formData.groupby,

Review Comment:
   **Suggestion:** `query_mode` is optional in form data, but this logic treats 
anything other than explicit `Raw` as aggregate mode. For legacy slices (or 
payloads where `query_mode` is unset but `all_columns` is populated), the map 
is built from `groupby` instead of `all_columns`, so renamed raw columns are 
never resolved and cross-filtering still breaks. Infer raw mode when 
`all_columns` is present before choosing which column list to map. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Legacy raw table slices emit wrong filter column names.
   - ⚠️ Dashboard cross-filtering silently fails for renamed raw columns.
   ```
   </details>
   
   ```suggestion
     const isRawMode =
       queryMode === QueryMode.Raw ||
       (queryMode == null && ensureIsArray(formData.all_columns).length > 0);
     const formColumns = ensureIsArray(
       isRawMode ? formData.all_columns : formData.groupby,
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Use a Table chart payload where `query_mode` is unset but `all_columns` 
is populated
   (allowed by `query_mode?: QueryMode` in
   `superset-frontend/plugins/plugin-chart-table/src/types.ts:60` and 
`all_columns?: ...` at
   `types.ts:66`).
   
   2. Query execution still runs as Raw mode because `getQueryMode()` in
   `superset-frontend/plugins/plugin-chart-table/src/buildQuery.ts:47-55` infers
   `QueryMode.Raw` when `all_columns` has values.
   
   3. In `transformProps()`
   
(`superset-frontend/plugins/plugin-chart-table/src/transformProps.ts:541-543`), 
mapping
   source is chosen via `queryMode === QueryMode.Raw ? all_columns : groupby`; 
with unset
   `queryMode`, it wrongly selects `groupby`, producing an empty/incorrect
   `columnLabelToNameMap`.
   
   4. During cell click cross-filtering, `getCrossFilterDataMask()` in
   `superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx:69-88` 
resolves
   `resolvedCol = columnLabelToNameMap[col] ?? col`; missing map entry keeps 
renamed label,
   so emitted filter uses label instead of original SQL column name.
   
   5. Result: cross-filter payload emits wrong `col` for renamed adhoc raw 
columns, so
   downstream chart filtering does not apply correctly.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/plugins/plugin-chart-table/src/transformProps.ts
   **Line:** 541:542
   **Comment:**
        *Logic Error: `query_mode` is optional in form data, but this logic 
treats anything other than explicit `Raw` as aggregate mode. For legacy slices 
(or payloads where `query_mode` is unset but `all_columns` is populated), the 
map is built from `groupby` instead of `all_columns`, so renamed raw columns 
are never resolved and cross-filtering still breaks. Infer raw mode when 
`all_columns` is present before choosing which column list to map.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38858&comment_hash=ea1ee8e7de2adeaa039ccf5aa9408f2937073b67eb3274adea629460ff52b85f&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38858&comment_hash=ea1ee8e7de2adeaa039ccf5aa9408f2937073b67eb3274adea629460ff52b85f&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