mirror of
https://github.com/apache/superset.git
synced 2026-04-21 09:04:38 +00:00
feat(trino): support early cancellation of queries (#22498)
This commit is contained in:
@@ -16,8 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { t } from '@superset-ui/core';
|
||||
|
||||
import { QueryState, t } from '@superset-ui/core';
|
||||
import getInitialState from './getInitialState';
|
||||
import * as actions from '../actions/sqlLab';
|
||||
import { now } from '../../utils/dates';
|
||||
@@ -391,7 +390,7 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
},
|
||||
[actions.STOP_QUERY]() {
|
||||
return alterInObject(state, 'queries', action.query, {
|
||||
state: 'stopped',
|
||||
state: QueryState.STOPPED,
|
||||
results: [],
|
||||
});
|
||||
},
|
||||
@@ -405,12 +404,16 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
},
|
||||
[actions.REQUEST_QUERY_RESULTS]() {
|
||||
return alterInObject(state, 'queries', action.query, {
|
||||
state: 'fetching',
|
||||
state: QueryState.FETCHING,
|
||||
});
|
||||
},
|
||||
[actions.QUERY_SUCCESS]() {
|
||||
// prevent race condition were query succeeds shortly after being canceled
|
||||
if (action.query.state === 'stopped') {
|
||||
// prevent race condition where query succeeds shortly after being canceled
|
||||
// or the final result was unsuccessful
|
||||
if (
|
||||
action.query.state === QueryState.STOPPED ||
|
||||
action.results.status !== QueryState.SUCCESS
|
||||
) {
|
||||
return state;
|
||||
}
|
||||
const alts = {
|
||||
@@ -418,7 +421,7 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
progress: 100,
|
||||
results: action.results,
|
||||
rows: action?.results?.query?.rows || 0,
|
||||
state: 'success',
|
||||
state: QueryState.SUCCESS,
|
||||
limitingFactor: action?.results?.query?.limitingFactor,
|
||||
tempSchema: action?.results?.query?.tempSchema,
|
||||
tempTable: action?.results?.query?.tempTable,
|
||||
@@ -434,11 +437,11 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
return alterInObject(state, 'queries', action.query, alts);
|
||||
},
|
||||
[actions.QUERY_FAILED]() {
|
||||
if (action.query.state === 'stopped') {
|
||||
if (action.query.state === QueryState.STOPPED) {
|
||||
return state;
|
||||
}
|
||||
const alts = {
|
||||
state: 'failed',
|
||||
state: QueryState.FAILED,
|
||||
errors: action.errors,
|
||||
errorMessage: action.msg,
|
||||
endDttm: now(),
|
||||
@@ -723,8 +726,8 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
Object.entries(action.alteredQueries).forEach(([id, changedQuery]) => {
|
||||
if (
|
||||
!state.queries.hasOwnProperty(id) ||
|
||||
(state.queries[id].state !== 'stopped' &&
|
||||
state.queries[id].state !== 'failed')
|
||||
(state.queries[id].state !== QueryState.STOPPED &&
|
||||
state.queries[id].state !== QueryState.FAILED)
|
||||
) {
|
||||
if (changedQuery.changedOn > queriesLastUpdate) {
|
||||
queriesLastUpdate = changedQuery.changedOn;
|
||||
@@ -738,8 +741,8 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
// because of async behavior, sql lab may still poll a couple of seconds
|
||||
// when it started fetching or finished rendering results
|
||||
state:
|
||||
currentState === 'success' &&
|
||||
['fetching', 'success'].includes(prevState)
|
||||
currentState === QueryState.SUCCESS &&
|
||||
[QueryState.FETCHING, QueryState.SUCCESS].includes(prevState)
|
||||
? prevState
|
||||
: currentState,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user