SBIN2010 commented on code in PR #45680:
URL: https://github.com/apache/superset/pull/45680#discussion_r4417760652


##########
superset-frontend/src/utils/simpleFilterToAdhoc.ts:
##########
@@ -75,16 +75,36 @@ export const simpleFilterToAdhoc = (
 
   let result: AdhocFilter;
   if (isAdhocColumn(filterClause.col)) {
-    result = {
-      expressionType: 'SQL',
-      clause,
-      sqlExpression: translateToSql({
-        expressionType: ExpressionTypes.Simple,
-        subject: `(${filterClause.col.sqlExpression})`,
+    // A grain on an adhoc expression has to stay on the column. Compiling it
+    // to raw SQL drops the grain, so the bucket is no longer truncated.
+    if (filterClause.grain) {
+      result = {
+        expressionType: 'SIMPLE',
+        clause,
         operator: filterClause.op,
+        operatorId: Object.entries(OPERATOR_ENUM_TO_OPERATOR_TYPE).find(
+          operatorEntry => operatorEntry[1].operation === filterClause.op,
+        )?.[0],
+        subject: {
+          ...filterClause.col,
+          columnType: 'BASE_AXIS',
+          timeGrain: filterClause.col.timeGrain || filterClause.grain,

Review Comment:
   Good catch. Now, if the value, operator, or subject changes, `duplicateWith` 
strips both the `timeGrain` and `columnType` from an ad-hoc column—not just the 
external `timeGrain`. After changing a value (e.g., from `2021-01-01` to 
`2021-01-15`), `convertFilter` sends the original column without any grain, 
which prevents the backend from attempting to compare a "month" grain against 
the 15th day of the month. Filters that remain unchanged retain their grain.



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