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


##########
superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.tsx:
##########
@@ -46,7 +46,35 @@ import { AGGREGATES } from 'src/explore/constants';
 import { datasetLabelLower } from 'src/features/semanticLayers/label';
 
 const EMPTY_OBJECT = {};
-const DND_ACCEPTED_TYPES = [DndItemType.Column, DndItemType.Metric];
+const DND_ACCEPTED_TYPES = [
+  DndItemType.Column,
+  DndItemType.Metric,
+  DndItemType.Folder,
+];
+
+/**
+ * Build an adhoc metric from a dropped column, picking a sensible default
+ * aggregation from the column's data type: SUM for numeric columns,
+ * COUNT_DISTINCT for string/boolean/temporal ones.
+ */
+export const createAdhocMetricFromColumn = (
+  column: ColumnMeta,
+): AdhocMetric => {
+  // Cast config to handle ColumnMeta/ColumnType mismatch
+  const config = {
+    column,
+  } as Partial<AdhocMetric>;
+  if (column.type_generic === GenericDataType.Numeric) {
+    config.aggregate = AGGREGATES.SUM;
+  } else if (
+    column.type_generic === GenericDataType.String ||
+    column.type_generic === GenericDataType.Boolean ||
+    column.type_generic === GenericDataType.Temporal
+  ) {
+    config.aggregate = AGGREGATES.COUNT_DISTINCT;
+  }
+  return new AdhocMetric(config);

Review Comment:
   Use `COUNT_DISTINCT` as the fallback. It is safer than `SUM` for unknown 
types because it does not assume the column is numeric, and it matches the 
existing behavior for string, boolean, and temporal columns.
   
   ```typescript
   if (column.type_generic === GenericDataType.Numeric) {
     config.aggregate = AGGREGATES.SUM;
   } else {
     config.aggregate = AGGREGATES.COUNT_DISTINCT;
   }
   ```
   
   This ensures folder drops always create a complete adhoc metric and avoids 
bypassing the aggregation popover with an invalid configuration. The existing 
test for unknown types should also be updated to expect 
`AGGREGATES.COUNT_DISTINCT`.



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