mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat(SIP-95): catalogs in SQL Lab and datasets (#28376)
This commit is contained in:
@@ -55,6 +55,7 @@ export const REMOVE_QUERY = 'REMOVE_QUERY';
|
||||
export const EXPAND_TABLE = 'EXPAND_TABLE';
|
||||
export const COLLAPSE_TABLE = 'COLLAPSE_TABLE';
|
||||
export const QUERY_EDITOR_SETDB = 'QUERY_EDITOR_SETDB';
|
||||
export const QUERY_EDITOR_SET_CATALOG = 'QUERY_EDITOR_SET_CATALOG';
|
||||
export const QUERY_EDITOR_SET_SCHEMA = 'QUERY_EDITOR_SET_SCHEMA';
|
||||
export const QUERY_EDITOR_SET_TITLE = 'QUERY_EDITOR_SET_TITLE';
|
||||
export const QUERY_EDITOR_SET_AUTORUN = 'QUERY_EDITOR_SET_AUTORUN';
|
||||
@@ -326,6 +327,7 @@ export function runQuery(query) {
|
||||
database_id: query.dbId,
|
||||
json: true,
|
||||
runAsync: query.runAsync,
|
||||
catalog: query.catalog,
|
||||
schema: query.schema,
|
||||
sql: query.sql,
|
||||
sql_editor_id: query.sqlEditorId,
|
||||
@@ -381,6 +383,7 @@ export function runQueryFromSqlEditor(
|
||||
sql: qe.selectedText || qe.sql,
|
||||
sqlEditorId: qe.id,
|
||||
tab: qe.name,
|
||||
catalog: qe.catalog,
|
||||
schema: qe.schema,
|
||||
tempTable,
|
||||
templateParams: qe.templateParams,
|
||||
@@ -556,7 +559,7 @@ export function addNewQueryEditor() {
|
||||
);
|
||||
const dbIds = Object.values(databases).map(database => database.id);
|
||||
const firstDbId = dbIds.length > 0 ? Math.min(...dbIds) : undefined;
|
||||
const { dbId, schema, queryLimit, autorun } = {
|
||||
const { dbId, catalog, schema, queryLimit, autorun } = {
|
||||
...queryEditors[0],
|
||||
...activeQueryEditor,
|
||||
...(unsavedQueryEditor.id === activeQueryEditor?.id &&
|
||||
@@ -578,6 +581,7 @@ export function addNewQueryEditor() {
|
||||
return dispatch(
|
||||
addQueryEditor({
|
||||
dbId: dbId || defaultDbId || firstDbId,
|
||||
catalog: catalog ?? null,
|
||||
schema: schema ?? null,
|
||||
autorun: autorun ?? false,
|
||||
sql: `${warning}SELECT ...`,
|
||||
@@ -600,6 +604,7 @@ export function cloneQueryToNewTab(query, autorun) {
|
||||
const queryEditor = {
|
||||
name: t('Copy of %s', sourceQueryEditor.name),
|
||||
dbId: query.dbId ? query.dbId : null,
|
||||
catalog: query.catalog ? query.catalog : null,
|
||||
schema: query.schema ? query.schema : null,
|
||||
autorun,
|
||||
sql: query.sql,
|
||||
@@ -656,6 +661,7 @@ export function setTables(tableSchemas) {
|
||||
return {
|
||||
dbId: tableSchema.database_id,
|
||||
queryEditorId: tableSchema.tab_state_id.toString(),
|
||||
catalog: tableSchema.catalog,
|
||||
schema: tableSchema.schema,
|
||||
name: tableSchema.table,
|
||||
expanded: tableSchema.expanded,
|
||||
@@ -694,6 +700,7 @@ export function switchQueryEditor(queryEditor, displayLimit) {
|
||||
autorun: json.autorun,
|
||||
dbId: json.database_id,
|
||||
templateParams: json.template_params,
|
||||
catalog: json.catalog,
|
||||
schema: json.schema,
|
||||
queryLimit: json.query_limit,
|
||||
remoteId: json.saved_query?.id,
|
||||
@@ -797,6 +804,14 @@ export function queryEditorSetDb(queryEditor, dbId) {
|
||||
return { type: QUERY_EDITOR_SETDB, queryEditor, dbId };
|
||||
}
|
||||
|
||||
export function queryEditorSetCatalog(queryEditor, catalog) {
|
||||
return {
|
||||
type: QUERY_EDITOR_SET_CATALOG,
|
||||
queryEditor: queryEditor || {},
|
||||
catalog,
|
||||
};
|
||||
}
|
||||
|
||||
export function queryEditorSetSchema(queryEditor, schema) {
|
||||
return {
|
||||
type: QUERY_EDITOR_SET_SCHEMA,
|
||||
@@ -954,12 +969,13 @@ export function mergeTable(table, query, prepend) {
|
||||
return { type: MERGE_TABLE, table, query, prepend };
|
||||
}
|
||||
|
||||
export function addTable(queryEditor, tableName, schemaName) {
|
||||
export function addTable(queryEditor, tableName, catalogName, schemaName) {
|
||||
return function (dispatch, getState) {
|
||||
const query = getUpToDateQuery(getState(), queryEditor, queryEditor.id);
|
||||
const table = {
|
||||
dbId: query.dbId,
|
||||
queryEditorId: query.id,
|
||||
catalog: catalogName,
|
||||
schema: schemaName,
|
||||
name: tableName,
|
||||
};
|
||||
@@ -983,12 +999,14 @@ export function runTablePreviewQuery(newTable) {
|
||||
sqlLab: { databases },
|
||||
} = getState();
|
||||
const database = databases[newTable.dbId];
|
||||
const { dbId } = newTable;
|
||||
const { dbId, catalog, schema } = newTable;
|
||||
|
||||
if (database && !database.disable_data_preview) {
|
||||
const dataPreviewQuery = {
|
||||
id: shortid.generate(),
|
||||
dbId,
|
||||
catalog,
|
||||
schema,
|
||||
sql: newTable.selectStar,
|
||||
tableName: newTable.name,
|
||||
sqlEditorId: null,
|
||||
@@ -1003,6 +1021,7 @@ export function runTablePreviewQuery(newTable) {
|
||||
{
|
||||
id: newTable.id,
|
||||
dbId: newTable.dbId,
|
||||
catalog: newTable.catalog,
|
||||
schema: newTable.schema,
|
||||
name: newTable.name,
|
||||
queryEditorId: newTable.queryEditorId,
|
||||
@@ -1180,6 +1199,7 @@ export function popStoredQuery(urlId) {
|
||||
addQueryEditor({
|
||||
name: json.name ? json.name : t('Shared query'),
|
||||
dbId: json.dbId ? parseInt(json.dbId, 10) : null,
|
||||
catalog: json.catalog ? json.catalog : null,
|
||||
schema: json.schema ? json.schema : null,
|
||||
autorun: json.autorun ? json.autorun : false,
|
||||
sql: json.sql ? json.sql : 'SELECT ...',
|
||||
@@ -1215,6 +1235,7 @@ export function popQuery(queryId) {
|
||||
const queryData = json.result;
|
||||
const queryEditorProps = {
|
||||
dbId: queryData.database.id,
|
||||
catalog: queryData.catalog,
|
||||
schema: queryData.schema,
|
||||
sql: queryData.sql,
|
||||
name: t('Copy of %s', queryData.tab_name),
|
||||
@@ -1268,12 +1289,13 @@ export function createDatasourceFailed(err) {
|
||||
export function createDatasource(vizOptions) {
|
||||
return dispatch => {
|
||||
dispatch(createDatasourceStarted());
|
||||
const { dbId, schema, datasourceName, sql } = vizOptions;
|
||||
const { dbId, catalog, schema, datasourceName, sql } = vizOptions;
|
||||
return SupersetClient.post({
|
||||
endpoint: '/api/v1/dataset/',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
database: dbId,
|
||||
catalog,
|
||||
schema,
|
||||
sql,
|
||||
table_name: datasourceName,
|
||||
|
||||
Reference in New Issue
Block a user