2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2016-10-29 10:48:17 -04:00
|
|
|
import sinon from 'sinon';
|
2020-05-07 17:18:10 -04:00
|
|
|
import * as actions from 'src/SqlLab/actions/sqlLab';
|
2016-10-29 10:48:17 -04:00
|
|
|
|
2020-04-03 20:05:16 -04:00
|
|
|
export const mockedActions = sinon.stub({ ...actions });
|
2016-10-29 10:48:17 -04:00
|
|
|
|
2016-10-25 19:44:32 -04:00
|
|
|
export const alert = { bsStyle: 'danger', msg: 'Ooops', id: 'lksvmcx32' };
|
|
|
|
export const table = {
|
|
|
|
dbId: 1,
|
|
|
|
selectStar: 'SELECT * FROM ab_user',
|
|
|
|
queryEditorId: 'rJ-KP47a',
|
2016-11-10 02:08:22 -05:00
|
|
|
schema: 'superset',
|
2016-10-25 19:44:32 -04:00
|
|
|
name: 'ab_user',
|
|
|
|
id: 'r11Vgt60',
|
2016-11-04 17:21:51 -04:00
|
|
|
dataPreviewQueryId: null,
|
2016-10-29 10:48:17 -04:00
|
|
|
partitions: {
|
|
|
|
cols: ['username'],
|
|
|
|
latest: 'bob',
|
|
|
|
partitionQuery: 'SHOW PARTITIONS FROM ab_user',
|
|
|
|
},
|
2016-10-25 19:44:32 -04:00
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
unique: true,
|
2018-10-18 13:40:30 -04:00
|
|
|
column_names: ['username'],
|
2016-10-25 19:44:32 -04:00
|
|
|
type: 'UNIQUE',
|
|
|
|
name: 'username',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
unique: true,
|
2018-10-18 13:40:30 -04:00
|
|
|
column_names: ['email'],
|
2016-10-25 19:44:32 -04:00
|
|
|
type: 'UNIQUE',
|
|
|
|
name: 'email',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
unique: false,
|
2018-10-18 13:40:30 -04:00
|
|
|
column_names: ['created_by_fk'],
|
2016-10-25 19:44:32 -04:00
|
|
|
name: 'created_by_fk',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
unique: false,
|
2018-10-18 13:40:30 -04:00
|
|
|
column_names: ['changed_by_fk'],
|
2016-10-25 19:44:32 -04:00
|
|
|
name: 'changed_by_fk',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'INTEGER(11)',
|
|
|
|
type: 'INTEGER',
|
|
|
|
name: 'id',
|
2016-11-01 02:52:37 -04:00
|
|
|
keys: [
|
|
|
|
{
|
|
|
|
column_names: ['id'],
|
|
|
|
type: 'pk',
|
|
|
|
name: null,
|
|
|
|
},
|
|
|
|
],
|
2016-10-25 19:44:32 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'VARCHAR(64)',
|
|
|
|
type: 'VARCHAR',
|
|
|
|
name: 'first_name',
|
2016-11-01 02:52:37 -04:00
|
|
|
keys: [
|
|
|
|
{
|
2018-10-18 13:40:30 -04:00
|
|
|
column_names: ['first_name'],
|
2016-11-01 02:52:37 -04:00
|
|
|
name: 'slices_ibfk_1',
|
2018-10-18 13:40:30 -04:00
|
|
|
referred_columns: ['id'],
|
2016-11-01 02:52:37 -04:00
|
|
|
referred_table: 'datasources',
|
|
|
|
type: 'fk',
|
|
|
|
referred_schema: 'carapal',
|
|
|
|
options: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
unique: false,
|
2018-10-18 13:40:30 -04:00
|
|
|
column_names: ['druid_datasource_id'],
|
2016-11-01 02:52:37 -04:00
|
|
|
type: 'index',
|
|
|
|
name: 'druid_datasource_id',
|
|
|
|
},
|
|
|
|
],
|
2016-10-25 19:44:32 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'VARCHAR(64)',
|
|
|
|
type: 'VARCHAR',
|
|
|
|
name: 'last_name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
longType: 'VARCHAR(64)',
|
|
|
|
type: 'VARCHAR',
|
|
|
|
name: 'username',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'VARCHAR(256)',
|
|
|
|
type: 'VARCHAR',
|
|
|
|
name: 'password',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'TINYINT(1)',
|
|
|
|
type: 'TINYINT',
|
|
|
|
name: 'active',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
longType: 'VARCHAR(64)',
|
|
|
|
type: 'VARCHAR',
|
|
|
|
name: 'email',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'DATETIME',
|
|
|
|
type: 'DATETIME',
|
|
|
|
name: 'last_login',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'INTEGER(11)',
|
|
|
|
type: 'INTEGER',
|
|
|
|
name: 'login_count',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'INTEGER(11)',
|
|
|
|
type: 'INTEGER',
|
|
|
|
name: 'fail_login_count',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'DATETIME',
|
|
|
|
type: 'DATETIME',
|
|
|
|
name: 'created_on',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: false,
|
|
|
|
longType: 'DATETIME',
|
|
|
|
type: 'DATETIME',
|
|
|
|
name: 'changed_on',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
longType: 'INTEGER(11)',
|
|
|
|
type: 'INTEGER',
|
|
|
|
name: 'created_by_fk',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
indexed: true,
|
|
|
|
longType: 'INTEGER(11)',
|
|
|
|
type: 'INTEGER',
|
|
|
|
name: 'changed_by_fk',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
expanded: true,
|
|
|
|
};
|
|
|
|
export const defaultQueryEditor = {
|
|
|
|
id: 'dfsadfs',
|
|
|
|
autorun: false,
|
|
|
|
dbId: null,
|
2016-11-01 00:07:46 -04:00
|
|
|
latestQueryId: null,
|
|
|
|
selectedText: null,
|
|
|
|
sql: 'SELECT *\nFROM\nWHERE',
|
|
|
|
title: 'Untitled Query',
|
2019-08-07 00:23:40 -04:00
|
|
|
schemaOptions: [
|
|
|
|
{
|
|
|
|
value: 'main',
|
|
|
|
label: 'main',
|
|
|
|
title: 'main',
|
|
|
|
},
|
|
|
|
],
|
2016-10-25 19:44:32 -04:00
|
|
|
};
|
|
|
|
export const queries = [
|
|
|
|
{
|
|
|
|
dbId: 1,
|
2018-08-09 16:04:09 -04:00
|
|
|
sql: 'SELECT * FROM superset.slices',
|
2016-10-25 19:44:32 -04:00
|
|
|
sqlEditorId: 'SJ8YO72R',
|
|
|
|
tab: 'Demo',
|
|
|
|
runAsync: false,
|
|
|
|
ctas: false,
|
2016-11-04 17:21:51 -04:00
|
|
|
cached: false,
|
2016-10-25 19:44:32 -04:00
|
|
|
id: 'BkA1CLrJg',
|
|
|
|
progress: 100,
|
|
|
|
startDttm: 1476910566092.96,
|
|
|
|
state: 'success',
|
|
|
|
changedOn: 1476910566000,
|
|
|
|
tempTable: null,
|
|
|
|
userId: 1,
|
|
|
|
executedSql: null,
|
|
|
|
changed_on: '2016-10-19T20:56:06',
|
|
|
|
rows: 42,
|
|
|
|
endDttm: 1476910566798,
|
|
|
|
limit_reached: false,
|
2018-04-04 16:38:37 -04:00
|
|
|
schema: 'test_schema',
|
2016-10-25 19:44:32 -04:00
|
|
|
errorMessage: null,
|
|
|
|
db: 'main',
|
|
|
|
user: 'admin',
|
|
|
|
limit: 1000,
|
|
|
|
serverId: 141,
|
|
|
|
resultsKey: null,
|
|
|
|
results: {
|
2018-10-18 13:40:30 -04:00
|
|
|
columns: [
|
|
|
|
{
|
|
|
|
is_date: true,
|
|
|
|
name: 'ds',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: 'gender',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
2016-10-25 19:44:32 -04:00
|
|
|
],
|
2019-05-31 14:25:07 -04:00
|
|
|
selected_columns: [
|
|
|
|
{
|
|
|
|
is_date: true,
|
|
|
|
name: 'ds',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: 'gender',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
],
|
2019-11-27 17:02:48 -05:00
|
|
|
data: [
|
|
|
|
{ col1: 0, col2: 1 },
|
|
|
|
{ col1: 2, col2: 3 },
|
|
|
|
],
|
2016-10-25 19:44:32 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
dbId: 1,
|
2016-11-10 02:08:22 -05:00
|
|
|
sql: 'SELECT *FROM superset.slices',
|
2016-10-25 19:44:32 -04:00
|
|
|
sqlEditorId: 'SJ8YO72R',
|
|
|
|
tab: 'Demo',
|
|
|
|
runAsync: true,
|
|
|
|
ctas: false,
|
2016-11-04 17:21:51 -04:00
|
|
|
cached: false,
|
2016-10-25 19:44:32 -04:00
|
|
|
id: 'S1zeAISkx',
|
|
|
|
progress: 100,
|
|
|
|
startDttm: 1476910570802.2,
|
|
|
|
state: 'success',
|
|
|
|
changedOn: 1476910572000,
|
|
|
|
tempTable: null,
|
|
|
|
userId: 1,
|
2018-10-18 13:40:30 -04:00
|
|
|
executedSql:
|
2016-10-25 19:44:32 -04:00
|
|
|
'SELECT * \nFROM (SELECT created_on, changed_on, id, slice_name, ' +
|
|
|
|
'druid_datasource_id, table_id, datasource_type, datasource_name, ' +
|
|
|
|
'viz_type, params, created_by_fk, changed_by_fk, description, ' +
|
2018-10-18 13:40:30 -04:00
|
|
|
'cache_timeout, perm\nFROM superset.slices) AS inner_qry \n LIMIT 1000',
|
2016-10-25 19:44:32 -04:00
|
|
|
changed_on: '2016-10-19T20:56:12',
|
|
|
|
rows: 42,
|
|
|
|
endDttm: 1476910579693,
|
|
|
|
limit_reached: false,
|
|
|
|
schema: null,
|
|
|
|
errorMessage: null,
|
|
|
|
db: 'main',
|
|
|
|
user: 'admin',
|
|
|
|
limit: 1000,
|
|
|
|
serverId: 142,
|
|
|
|
resultsKey: '417149f4-cd27-4f80-91f3-c45c871003f7',
|
|
|
|
results: null,
|
|
|
|
},
|
|
|
|
];
|
2018-08-09 16:04:09 -04:00
|
|
|
export const queryWithBadColumns = {
|
|
|
|
...queries[0],
|
|
|
|
results: {
|
|
|
|
data: queries[0].results.data,
|
2019-05-31 14:25:07 -04:00
|
|
|
selected_columns: [
|
2018-10-18 13:40:30 -04:00
|
|
|
{
|
|
|
|
is_date: true,
|
|
|
|
name: 'COUNT(*)',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: 'this_col_is_ok',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: 'a',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: '1',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: '123',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
is_date: false,
|
|
|
|
name: 'CASE WHEN 1=1 THEN 1 ELSE 0 END',
|
|
|
|
type: 'STRING',
|
|
|
|
},
|
|
|
|
],
|
2018-08-09 16:04:09 -04:00
|
|
|
},
|
|
|
|
};
|
2017-06-19 14:39:32 -04:00
|
|
|
export const databases = {
|
2018-10-18 13:40:30 -04:00
|
|
|
result: [
|
|
|
|
{
|
|
|
|
allow_ctas: true,
|
|
|
|
allow_dml: true,
|
|
|
|
allow_run_async: false,
|
|
|
|
database_name: 'main',
|
|
|
|
expose_in_sqllab: true,
|
|
|
|
force_ctas_schema: '',
|
|
|
|
id: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
allow_ctas: true,
|
|
|
|
allow_dml: false,
|
|
|
|
allow_run_async: true,
|
|
|
|
database_name: 'Presto - Gold',
|
|
|
|
expose_in_sqllab: true,
|
|
|
|
force_ctas_schema: 'tmp',
|
|
|
|
id: 208,
|
|
|
|
},
|
|
|
|
],
|
2017-06-19 14:39:32 -04:00
|
|
|
};
|
|
|
|
export const tables = {
|
2018-10-18 13:40:30 -04:00
|
|
|
options: [
|
|
|
|
{
|
2019-07-01 15:44:46 -04:00
|
|
|
value: 'birth_names',
|
|
|
|
schema: 'main',
|
2018-10-18 13:40:30 -04:00
|
|
|
label: 'birth_names',
|
2019-07-01 15:44:46 -04:00
|
|
|
title: 'birth_names',
|
2018-10-18 13:40:30 -04:00
|
|
|
},
|
|
|
|
{
|
2019-07-01 15:44:46 -04:00
|
|
|
value: 'energy_usage',
|
|
|
|
schema: 'main',
|
2018-10-18 13:40:30 -04:00
|
|
|
label: 'energy_usage',
|
2019-07-01 15:44:46 -04:00
|
|
|
title: 'energy_usage',
|
2018-10-18 13:40:30 -04:00
|
|
|
},
|
|
|
|
{
|
2019-07-01 15:44:46 -04:00
|
|
|
value: 'wb_health_population',
|
|
|
|
schema: 'main',
|
2018-10-18 13:40:30 -04:00
|
|
|
label: 'wb_health_population',
|
2019-07-01 15:44:46 -04:00
|
|
|
title: 'wb_health_population',
|
2018-10-18 13:40:30 -04:00
|
|
|
},
|
|
|
|
],
|
2017-06-19 14:39:32 -04:00
|
|
|
};
|
2016-10-25 19:44:32 -04:00
|
|
|
|
2017-06-15 16:51:09 -04:00
|
|
|
export const stoppedQuery = {
|
|
|
|
dbId: 1,
|
|
|
|
cached: false,
|
|
|
|
ctas: false,
|
|
|
|
id: 'ryhMUZCGb',
|
|
|
|
progress: 0,
|
|
|
|
results: [],
|
|
|
|
runAsync: false,
|
|
|
|
schema: 'main',
|
|
|
|
sql: 'SELECT ...',
|
|
|
|
sqlEditorId: 'rJaf5u9WZ',
|
|
|
|
startDttm: 1497400851936,
|
|
|
|
state: 'stopped',
|
|
|
|
tab: 'Untitled Query 2',
|
|
|
|
tempTableName: '',
|
|
|
|
};
|
|
|
|
export const runningQuery = {
|
|
|
|
dbId: 1,
|
|
|
|
cached: false,
|
|
|
|
ctas: false,
|
|
|
|
id: 'ryhMUZCGb',
|
|
|
|
progress: 90,
|
|
|
|
state: 'running',
|
2019-05-30 13:38:49 -04:00
|
|
|
startDttm: Date.now() - 500,
|
2017-06-15 16:51:09 -04:00
|
|
|
};
|
2020-04-03 20:05:16 -04:00
|
|
|
export const cachedQuery = { ...queries[0], cached: true };
|
2017-06-15 16:51:09 -04:00
|
|
|
|
2016-10-25 19:44:32 -04:00
|
|
|
export const initialState = {
|
2018-07-12 14:50:25 -04:00
|
|
|
sqlLab: {
|
2019-05-30 13:38:49 -04:00
|
|
|
offline: false,
|
2018-07-12 14:50:25 -04:00
|
|
|
alerts: [],
|
|
|
|
queries: {},
|
|
|
|
databases: {},
|
|
|
|
queryEditors: [defaultQueryEditor],
|
|
|
|
tabHistory: [defaultQueryEditor.id],
|
|
|
|
tables: [],
|
|
|
|
workspaceQueries: [],
|
|
|
|
queriesLastUpdate: 0,
|
|
|
|
activeSouthPaneTab: 'Results',
|
|
|
|
},
|
|
|
|
messageToasts: [],
|
2018-11-07 18:57:44 -05:00
|
|
|
common: {
|
|
|
|
conf: {
|
|
|
|
DEFAULT_SQLLAB_LIMIT: 1000,
|
|
|
|
SQL_MAX_ROW: 100000,
|
|
|
|
},
|
|
|
|
},
|
2016-10-25 19:44:32 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
export const query = {
|
2018-10-18 13:40:30 -04:00
|
|
|
id: 'clientId2353',
|
2016-10-25 19:44:32 -04:00
|
|
|
dbId: 1,
|
|
|
|
sql: 'SELECT * FROM something',
|
|
|
|
sqlEditorId: defaultQueryEditor.id,
|
|
|
|
tab: 'unimportant',
|
|
|
|
tempTableName: null,
|
|
|
|
runAsync: false,
|
|
|
|
ctas: false,
|
2016-11-04 17:21:51 -04:00
|
|
|
cached: false,
|
2016-10-25 19:44:32 -04:00
|
|
|
};
|