greggailly commented on code in PR #42483:
URL: https://github.com/apache/superset/pull/42483#discussion_r3659429526


##########
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:
   Happy to set a default here, any suggestion on what it should be ?



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