[sqllab] add support for results backends (#1377)

* [sqllab] add support for results backends

Long running SQL queries (beyond the scope of a web request) can now use
a k/v store to hold their result sets.

* Addressing comments, fixed js tests

* Fixing mysql has gone away

* Adressing more comments

* Touchups
This commit is contained in:
Maxime Beauchemin
2016-10-20 23:40:24 -07:00
committed by GitHub
parent 7dfe891cc1
commit 6fb3b305ad
27 changed files with 788 additions and 365 deletions

View File

@@ -13,9 +13,10 @@ const defaultQueryEditor = {
dbId: null,
};
// TODO(bkyryliuk): document the object schemas
export const initialState = {
alerts: [],
showDataPreviewModal: false,
dataPreviewQueryId: null,
networkOn: true,
queries: {},
databases: {},
@@ -93,6 +94,12 @@ export const sqlLabReducer = function (state, action) {
[actions.EXPAND_TABLE]() {
return alterInArr(state, 'tables', action.table, { expanded: true });
},
[actions.HIDE_DATA_PREVIEW]() {
const queries = Object.assign({}, state.queries);
delete queries[state.dataPreviewQueryId];
return Object.assign(
{}, state, { showDataPreviewModal: false, queries, dataPreviewQueryId: null });
},
[actions.COLLAPSE_TABLE]() {
return alterInArr(state, 'tables', action.table, { expanded: false });
},
@@ -100,12 +107,17 @@ export const sqlLabReducer = function (state, action) {
return removeFromArr(state, 'tables', action.table);
},
[actions.START_QUERY]() {
const qe = getFromArr(state.queryEditors, action.query.sqlEditorId);
let newState = Object.assign({}, state);
if (qe.latestQueryId) {
const q = Object.assign({}, state.queries[qe.latestQueryId], { results: null });
const queries = Object.assign({}, state.queries, { [q.id]: q });
newState = Object.assign({}, state, { queries });
if (action.query.sqlEditorId) {
const qe = getFromArr(state.queryEditors, action.query.sqlEditorId);
if (qe.latestQueryId) {
const q = Object.assign({}, state.queries[qe.latestQueryId], { results: null });
const queries = Object.assign({}, state.queries, { [q.id]: q });
newState = Object.assign({}, state, { queries });
}
} else {
newState.dataPreviewQueryId = action.query.id;
newState.showDataPreviewModal = true;
}
newState = addToObject(newState, 'queries', action.query);
const sqlEditor = { id: action.query.sqlEditorId };
@@ -114,6 +126,12 @@ export const sqlLabReducer = function (state, action) {
[actions.STOP_QUERY]() {
return alterInObject(state, 'queries', action.query, { state: 'stopped' });
},
[actions.CLEAR_QUERY_RESULTS]() {
return alterInObject(state, 'queries', action.query, { results: [] });
},
[actions.REQUEST_QUERY_RESULTS]() {
return alterInObject(state, 'queries', action.query, { state: 'fetching' });
},
[actions.QUERY_SUCCESS]() {
let rows;
if (action.results.data) {
@@ -125,6 +143,7 @@ export const sqlLabReducer = function (state, action) {
results: action.results,
rows,
state: 'success',
errorMessage: null,
};
return alterInObject(state, 'queries', action.query, alts);
},