From bfffd0f4bee77ddd43a41b2601bfc19b3728a354 Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Thu, 24 Mar 2022 17:09:42 -0300 Subject: [PATCH 1/2] fix(sql lab): display the 'View Results' button in the history tab when running sync queries --- .../src/SqlLab/components/ResultSet/index.tsx | 7 +++++-- superset-frontend/src/SqlLab/reducers/sqlLab.js | 2 ++ superset/sql_lab.py | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx index 4d8818b1d9747..8c6610191ebbe 100644 --- a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx +++ b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx @@ -247,9 +247,12 @@ export default class ResultSet extends React.PureComponent< this.clearQueryResults(nextProps.query), ); } + if ( - nextProps.query.resultsKey && - nextProps.query.resultsKey !== this.props.query.resultsKey + (this.props.query.resultsKey && + nextProps.query.resultsKey && + nextProps.query.resultsKey !== this.props.query.resultsKey) || + (nextProps.query.id !== this.props.query.id && nextProps.query.resultsKey) ) { this.fetchResults(nextProps.query); } diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js index 923caaf96152d..1c417af8b871c 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js @@ -328,8 +328,10 @@ export default function sqlLabReducer(state = {}, action) { if (action.query.state === 'stopped') { return state; } + const alts = { endDttm: now(), + resultsKey: action?.results?.query?.resultsKey, progress: 100, results: action.results, rows: action?.results?.query?.rows || 0, diff --git a/superset/sql_lab.py b/superset/sql_lab.py index 613db963e31c1..d3e08de92a9cf 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -528,6 +528,8 @@ def execute_sql_statements( # pylint: disable=too-many-arguments, too-many-loca if store_results and results_backend: key = str(uuid.uuid4()) + payload["query"]["resultsKey"] = key + logger.info( "Query %s: Storing results in results backend, key: %s", str(query_id), key ) From abff7162ae88348fc187458070fbe4938f1b786c Mon Sep 17 00:00:00 2001 From: Diego Medina Date: Fri, 1 Apr 2022 14:24:59 -0300 Subject: [PATCH 2/2] pr comment --- superset-frontend/src/SqlLab/components/ResultSet/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx index 8c6610191ebbe..83b6bb3f55b88 100644 --- a/superset-frontend/src/SqlLab/components/ResultSet/index.tsx +++ b/superset-frontend/src/SqlLab/components/ResultSet/index.tsx @@ -248,6 +248,10 @@ export default class ResultSet extends React.PureComponent< ); } + // Only fetch results if the result key change + // If we didn't have a result key before, then the results are loaded elsewhere + // so we can skip it, unless the query id changed, in that case we should + // refetch regardless. if ( (this.props.query.resultsKey && nextProps.query.resultsKey &&