sadpandajoe commented on code in PR #45680:
URL: https://github.com/apache/superset/pull/45680#discussion_r4417290596
##########
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:
The grain is also stored on `subject` here, but
`AdhocFilter.duplicateWith()` only clears the outer `timeGrain` when the
comparator or operator changes. After Drill by on a monthly Custom SQL axis and
Edit chart, changing the filter from `== 2021-01-01T00:00:00` to `==
2021-01-15T00:00:00` drops the grain from the pill while `convertFilter` still
sends `col: subject` with `timeGrain: P1M` and `BASE_AXIS`, so the backend
compares the month-truncated expression to Jan 15 and returns no rows. Should
an edit that clears the filter's grain also strip `timeGrain`/`columnType` from
the subject, with a test that goes conversion, edit, then `convertFilter`?
##########
superset-frontend/src/explore/exploreUtils/index.ts:
##########
@@ -466,10 +467,10 @@ export const getSimpleSQLExpression = (
);
const showComparator =
disableInputOperatorValues.indexOf(operator ?? '') === -1;
- // If returned value is an object after changing dataset
+ // A dataset column carries column_name. An adhoc column carries label.
let expression: string =
typeof subject === 'object'
- ? (subject?.column_name ?? '')
+ ? (subject?.column_name ?? subject?.label ?? '')
Review Comment:
`getSimpleSQLExpression` also feeds `translateToSql`, which builds the
Custom SQL text when a filter is switched to the SQL tab. With a Custom SQL X
axis such as `CAST(order_date AS TIMESTAMP)` labeled `bucket_date`, falling
back to `label` turns the editor text into `bucket_date =
'2021-01-01T00:00:00'`, and saving it fails because `bucket_date` is an alias,
not a dataset column. Should the label fallback apply only to the pill display,
with the SQL path using the subject's `sqlExpression`?
--
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]