You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "kgabryje (via GitHub)" <gi...@apache.org> on 2023/02/28 18:03:30 UTC

[GitHub] [superset] kgabryje opened a new pull request, #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

kgabryje opened a new pull request, #23239:
URL: https://github.com/apache/superset/pull/23239

   
   ### SUMMARY
   When user applied a cross filter on an adhoc column and then tried to explore a chart targeted by that cross filter, the adhoc filter control would be display as `[Object object]`. This PR implements a proper translation of a filter based on adhoc column to an SQL adhoc filter
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   Before:
   
   <img width="360" alt="image" src="https://user-images.githubusercontent.com/15073128/221939470-ff5593b4-0e80-4569-8a43-83512e835d38.png">
   
   <img width="439" alt="image" src="https://user-images.githubusercontent.com/15073128/221939505-6a127826-640c-4564-afa3-0d463fedd93b.png">
   
   After:
   
   <img width="359" alt="image" src="https://user-images.githubusercontent.com/15073128/221939673-c0f3eb85-4559-49b3-96fd-75af04595ad0.png">
   
   <img width="445" alt="image" src="https://user-images.githubusercontent.com/15073128/221939747-66303873-3be3-4e31-b3af-a059c82cfc64.png">
   
   
   ### TESTING INSTRUCTIONS
   1. Add a chart with grouping based on an adhoc column to a dashboard
   2. Add another chart that uses the same dataset to the dashboard
   3. Apply cross-filtering by clicking on a series related to the adhoc column in the first chart
   4. Open the second chart in Explore by clicking on the chart's title in dashboard
   5. Verify that the adhoc filter based on the cross-filter from the dashboard is displayed properly
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] kgabryje commented on a diff in pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on code in PR #23239:
URL: https://github.com/apache/superset/pull/23239#discussion_r1121561880


##########
superset-frontend/src/explore/components/controls/FilterControl/AdhocFilter/index.js:
##########
@@ -33,44 +34,24 @@ export const CLAUSES = {
   WHERE: 'WHERE',
 };
 
-const OPERATORS_TO_SQL = {
-  '==': '=',
-  '!=': '<>',
-  '>': '>',
-  '<': '<',
-  '>=': '>=',
-  '<=': '<=',
-  IN: 'IN',
-  'NOT IN': 'NOT IN',
-  LIKE: 'LIKE',
-  ILIKE: 'ILIKE',
-  REGEX: 'REGEX',
-  'IS NOT NULL': 'IS NOT NULL',
-  'IS NULL': 'IS NULL',
-  'IS TRUE': 'IS TRUE',
-  'IS FALSE': 'IS FALSE',
-  'LATEST PARTITION': ({ datasource }) =>
-    `= '{{ presto.latest_partition('${datasource.schema}.${datasource.datasource_name}') }}'`,
-};
-
 const CUSTOM_OPERATIONS = [...CUSTOM_OPERATORS].map(
   op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation,
 );
 
-function translateToSql(adhocMetric, { useSimple } = {}) {
-  if (adhocMetric.expressionType === EXPRESSION_TYPES.SIMPLE || useSimple) {
-    const { subject, comparator } = adhocMetric;
+export function translateToSql(adhocFilter, { useSimple } = {}) {

Review Comment:
   I was 100% sure that I deleted it :P thanks for spotting!



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] kgabryje merged pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje merged PR #23239:
URL: https://github.com/apache/superset/pull/23239


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] kgabryje commented on a diff in pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on code in PR #23239:
URL: https://github.com/apache/superset/pull/23239#discussion_r1121680294


##########
superset-frontend/src/explore/controlUtils/getFormDataFromDashboardContext.test.ts:
##########
@@ -129,6 +129,15 @@ const getDashboardFormData = (overrides: JsonObject = {}) => ({
         op: '<=',
         val: 10000,
       },
+      {
+        col: {
+          sqlExpression: 'totally viable sql expression',

Review Comment:
   :trollface: 



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] kgabryje commented on a diff in pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on code in PR #23239:
URL: https://github.com/apache/superset/pull/23239#discussion_r1121581048


##########
superset-frontend/src/explore/controlUtils/getFormDataWithDashboardContext.ts:
##########
@@ -30,19 +30,40 @@ import {
   isFreeFormAdhocFilter,
   isSimpleAdhocFilter,
   NO_TIME_RANGE,
+  isAdhocColumn,
 } from '@superset-ui/core';
+import { Operators } from '../constants';
+import {
+  EXPRESSION_TYPES,
+  translateToSql,
+} from '../components/controls/FilterControl/AdhocFilter';
 
 const simpleFilterToAdhoc = (
   filterClause: QueryObjectFilterClause,
-  clause = 'where',
+  clause: 'WHERE' | 'HAVING' = 'WHERE',

Review Comment:
   👍 



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #23239:
URL: https://github.com/apache/superset/pull/23239#discussion_r1121613695


##########
superset-frontend/src/explore/controlUtils/getFormDataFromDashboardContext.test.ts:
##########
@@ -129,6 +129,15 @@ const getDashboardFormData = (overrides: JsonObject = {}) => ({
         op: '<=',
         val: 10000,
       },
+      {
+        col: {
+          sqlExpression: 'totally viable sql expression',

Review Comment:
   🤣 



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] kgabryje commented on pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "kgabryje (via GitHub)" <gi...@apache.org>.
kgabryje commented on PR #23239:
URL: https://github.com/apache/superset/pull/23239#issuecomment-1449974036

   Thanks for comments! Added a test + refactored hardcoded `'WHERE'` and `'HAVING'` strings


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #23239: fix(explore): Dashboard filters on adhoc cols not working in Explore

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #23239:
URL: https://github.com/apache/superset/pull/23239#discussion_r1121259227


##########
superset-frontend/src/explore/components/controls/FilterControl/AdhocFilter/index.js:
##########
@@ -33,44 +34,24 @@ export const CLAUSES = {
   WHERE: 'WHERE',
 };
 
-const OPERATORS_TO_SQL = {
-  '==': '=',
-  '!=': '<>',
-  '>': '>',
-  '<': '<',
-  '>=': '>=',
-  '<=': '<=',
-  IN: 'IN',
-  'NOT IN': 'NOT IN',
-  LIKE: 'LIKE',
-  ILIKE: 'ILIKE',
-  REGEX: 'REGEX',
-  'IS NOT NULL': 'IS NOT NULL',
-  'IS NULL': 'IS NULL',
-  'IS TRUE': 'IS TRUE',
-  'IS FALSE': 'IS FALSE',
-  'LATEST PARTITION': ({ datasource }) =>
-    `= '{{ presto.latest_partition('${datasource.schema}.${datasource.datasource_name}') }}'`,
-};
-
 const CUSTOM_OPERATIONS = [...CUSTOM_OPERATORS].map(
   op => OPERATOR_ENUM_TO_OPERATOR_TYPE[op].operation,
 );
 
-function translateToSql(adhocMetric, { useSimple } = {}) {
-  if (adhocMetric.expressionType === EXPRESSION_TYPES.SIMPLE || useSimple) {
-    const { subject, comparator } = adhocMetric;
+export function translateToSql(adhocFilter, { useSimple } = {}) {

Review Comment:
   Is this code still needed if we're introducing a new util `translateToSQL.ts` with a similar (identical?) function?



##########
superset-frontend/src/explore/controlUtils/getFormDataWithDashboardContext.ts:
##########
@@ -30,19 +30,40 @@ import {
   isFreeFormAdhocFilter,
   isSimpleAdhocFilter,
   NO_TIME_RANGE,
+  isAdhocColumn,
 } from '@superset-ui/core';
+import { Operators } from '../constants';
+import {
+  EXPRESSION_TYPES,
+  translateToSql,
+} from '../components/controls/FilterControl/AdhocFilter';
 
 const simpleFilterToAdhoc = (
   filterClause: QueryObjectFilterClause,
-  clause = 'where',
+  clause: 'WHERE' | 'HAVING' = 'WHERE',

Review Comment:
   I noticed we have this `'WHERE' | 'HAVING'` in a few places. It could be nice to bundle them up into a `type AdhocFilterClause = 'WHERE' | 'HAVING'` or similar.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org