Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save columns reference from sqllab save datasets flow #24248

Merged
merged 61 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
41a0312
fix save columns refernece
hughhhh May 30, 2023
844fbe9
ok
hughhhh May 30, 2023
02c01c2
allow schema to be null
hughhhh May 30, 2023
ef6cead
add support for legacy payload
hughhhh May 30, 2023
b257562
Merge branch 'master' into fix-save-ds-in-sqllab
hughhhh May 30, 2023
8769d6e
set default
hughhhh May 30, 2023
f0e3734
fix expression
hughhhh May 30, 2023
22223a7
ok
hughhhh May 30, 2023
84e307b
remove core change
hughhhh May 30, 2023
32920fd
update reference from API for column.column_name to match python column
hughhhh May 31, 2023
a107cee
ok
hughhhh May 31, 2023
fc741fa
ok
hughhhh May 31, 2023
49e10d2
ok
hughhhh May 31, 2023
29a224f
remove unneeded test
hughhhh Jun 1, 2023
510cd29
refactor on removing columns being sent on ds creation
hughhhh Jun 1, 2023
e69c1a0
revert test
hughhhh Jun 1, 2023
f95da35
lets see
hughhhh Jun 1, 2023
278bde6
lintint
hughhhh Jun 1, 2023
8fa92fd
update test
hughhhh Jun 1, 2023
51a0a38
ok
hughhhh Jun 1, 2023
4d62632
added test to verify name change
hughhhh Jun 1, 2023
d866479
console
hughhhh Jun 1, 2023
484c5f6
fix test
hughhhh Jun 2, 2023
dfc0b96
catch new sqllab endpoint
hughhhh Jun 2, 2023
5732bc4
Merge branch 'master' into fix-save-ds-in-sqllab
hughhhh Jun 5, 2023
7ab451a
oops
hughhhh Jun 5, 2023
bc60498
ok
hughhhh Jun 5, 2023
53d7cce
ok
hughhhh Jun 6, 2023
8506bb5
update another test
hughhhh Jun 6, 2023
f2b7040
ok
hughhhh Jun 6, 2023
93e2569
lit
hughhhh Jun 6, 2023
85f1e06
update inspector functions
hughhhh Jun 6, 2023
b7502f5
oops
hughhhh Jun 6, 2023
45d23ff
1 more
hughhhh Jun 6, 2023
7b17569
ok
hughhhh Jun 6, 2023
fe57567
fix integration config
hughhhh Jun 6, 2023
34b1f17
fix integration config
hughhhh Jun 6, 2023
c73464d
ok
hughhhh Jun 6, 2023
7317396
ok
hughhhh Jun 6, 2023
bb042b0
change name for column infor
hughhhh Jun 6, 2023
de8c023
preseto
hughhhh Jun 6, 2023
657c7cf
more
hughhhh Jun 6, 2023
4465785
1 more
hughhhh Jun 6, 2023
3f82bab
fixing more test
hughhhh Jun 6, 2023
d00e204
presto fix
hughhhh Jun 6, 2023
d4175a0
update spec
hughhhh Jun 7, 2023
78cd4e7
fix sync logic on the frontend
hughhhh Jun 7, 2023
bec68d0
fix merge conflict
hughhhh Jun 13, 2023
ed9728b
fix
hughhhh Jun 14, 2023
0d47277
linting
hughhhh Jun 14, 2023
8189c93
linting
hughhhh Jun 14, 2023
8895cff
oops
hughhhh Jun 14, 2023
4454cf3
1 more
hughhhh Jun 14, 2023
d96fbfd
fix more presto test
hughhhh Jun 14, 2023
bb8921a
ok
hughhhh Jun 14, 2023
cb6677d
ok fix
hughhhh Jun 14, 2023
6d3d955
omg
hughhhh Jun 14, 2023
a15cead
reference grandparent
hughhhh Jun 15, 2023
eeec51f
make schema backwards compatible
hughhhh Jun 15, 2023
743746e
Merge branch 'master' of https://github.com/preset-io/superset into f…
hughhhh Jun 20, 2023
2a1f09e
change refernce
hughhhh Jun 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const DATASET_TIME_COLUMN_OPTION: ColumnMeta = {
};

export const QUERY_TIME_COLUMN_OPTION: QueryColumn = {
name: DTTM_ALIAS,
column_name: DTTM_ALIAS,
type: DatasourceType.Query,
is_dttm: false,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import { ensureIsArray, QueryResponse } from '@superset-ui/core';
import { Dataset, isColumnMeta, isDataset, isQueryResponse } from '../types';
import { QueryResponse } from '@superset-ui/core';
import { Dataset, isColumnMeta, isDataset } from '../types';

/**
* Convert Datasource columns to column choices
Expand All @@ -35,14 +35,5 @@ export default function columnChoices(
opt1[1].toLowerCase() > opt2[1].toLowerCase() ? 1 : -1,
);
}

if (isQueryResponse(datasource)) {
return ensureIsArray(datasource.columns)
.map((col): [string, string] => [col.name, col.name])
.sort((opt1, opt2) =>
opt1[1].toLowerCase() > opt2[1].toLowerCase() ? 1 : -1,
);
}

return [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('get temporal columns from a QueryResponse', () => {
expect(getTemporalColumns(testQueryResponse)).toEqual({
temporalColumns: [
{
name: 'Column 2',
column_name: 'Column 2',
type: 'TIMESTAMP',
is_dttm: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ export const CtasEnum = {
};

export type QueryColumn = {
name: string;
column_name?: string;
name?: string;
column_name: string;
type: string | null;
is_dttm: boolean;
};
Expand Down Expand Up @@ -380,17 +380,17 @@ export const testQuery: Query = {
type: DatasourceType.Query,
columns: [
{
name: 'Column 1',
column_name: 'Column 1',
type: 'STRING',
is_dttm: false,
},
{
name: 'Column 3',
column_name: 'Column 3',
type: 'STRING',
is_dttm: false,
},
{
name: 'Column 2',
column_name: 'Column 2',
type: 'TIMESTAMP',
is_dttm: true,
},
Expand All @@ -402,17 +402,17 @@ export const testQueryResults = {
displayLimitReached: false,
columns: [
{
name: 'Column 1',
column_name: 'Column 1',
type: 'STRING',
is_dttm: false,
},
{
name: 'Column 3',
column_name: 'Column 3',
type: 'STRING',
is_dttm: false,
},
{
name: 'Column 2',
column_name: 'Column 2',
type: 'TIMESTAMP',
is_dttm: true,
},
Expand All @@ -423,17 +423,17 @@ export const testQueryResults = {
expanded_columns: [],
selected_columns: [
{
name: 'Column 1',
column_name: 'Column 1',
type: 'STRING',
is_dttm: false,
},
{
name: 'Column 3',
column_name: 'Column 3',
type: 'STRING',
is_dttm: false,
},
{
name: 'Column 2',
column_name: 'Column 2',
type: 'TIMESTAMP',
is_dttm: true,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ describe('ResultSet', () => {
expect(table).toBeInTheDocument();

const firstColumn = queryAllByText(
mockedProps.query.results?.columns[0].name ?? '',
mockedProps.query.results?.columns[0].column_name ?? '',
)[0];
const secondColumn = queryAllByText(
mockedProps.query.results?.columns[1].name ?? '',
mockedProps.query.results?.columns[1].column_name ?? '',
)[0];
expect(firstColumn).toBeInTheDocument();
expect(secondColumn).toBeInTheDocument();
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/SqlLab/components/ResultSet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const ResultSet = ({
...EXPLORE_CHART_DEFAULT,
datasource: `${results.query_id}__query`,
...{
all_columns: results.columns.map(column => column.name),
all_columns: results.columns.map(column => column.column_name),
},
});
const url = mountExploreUrl(null, {
Expand Down Expand Up @@ -491,7 +491,7 @@ const ResultSet = ({
}
if (data && data.length > 0) {
const expandedColumns = results.expanded_columns
? results.expanded_columns.map(col => col.name)
? results.expanded_columns.map(col => col.column_name)
: [];
return (
<>
Expand All @@ -500,7 +500,7 @@ const ResultSet = ({
{sql}
<FilterableTable
data={data}
orderedColumnKeys={results.columns.map(col => col.name)}
orderedColumnKeys={results.columns.map(col => col.column_name)}
height={rowsHeight}
filterText={searchText}
expandedColumns={expandedColumns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type ExploreQuery = QueryResponse & {

export interface ISimpleColumn {
column_name?: string | null;
name?: string | null;
type?: string | null;
is_dttm?: boolean | null;
}
Expand Down Expand Up @@ -199,14 +200,15 @@ export const SaveDatasetModal = ({
return;
}
setLoading(true);

const [, key] = await Promise.all([
updateDataset(
datasource?.dbId,
datasetToOverwrite?.datasetid,
datasource?.sql,
datasource?.columns?.map(
(d: { name: string; type: string; is_dttm: boolean }) => ({
column_name: d.name,
(d: { column_name: string; type: string; is_dttm: boolean }) => ({
column_name: d.column_name,
type: d.type,
is_dttm: d.is_dttm,
}),
Expand Down Expand Up @@ -292,12 +294,10 @@ export const SaveDatasetModal = ({

dispatch(
createDatasource({
schema: datasource.schema,
sql: datasource.sql,
dbId: datasource.dbId || datasource?.database?.id,
templateParams,
datasourceName: datasetName,
columns: selectedColumns,
}),
)
.then((data: { id: number }) =>
Expand Down
46 changes: 23 additions & 23 deletions superset-frontend/src/SqlLab/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,24 +236,24 @@ export const queries = [
columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
{
is_dttm: false,
name: 'gender',
column_name: 'gender',
type: 'STRING',
},
],
selected_columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
{
is_dttm: false,
name: 'gender',
column_name: 'gender',
type: 'STRING',
},
],
Expand Down Expand Up @@ -326,7 +326,7 @@ export const queryWithNoQueryLimit = {
columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
{
Expand All @@ -338,12 +338,12 @@ export const queryWithNoQueryLimit = {
selected_columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
{
is_dttm: false,
name: 'gender',
column_name: 'gender',
type: 'STRING',
},
],
Expand All @@ -364,57 +364,57 @@ export const queryWithBadColumns = {
selected_columns: [
{
is_dttm: true,
name: 'COUNT(*)',
column_name: 'COUNT(*)',
type: 'STRING',
},
{
is_dttm: false,
name: 'this_col_is_ok',
column_name: 'this_col_is_ok',
type: 'STRING',
},
{
is_dttm: false,
name: 'a',
column_name: 'a',
type: 'STRING',
},
{
is_dttm: false,
name: '1',
column_name: '1',
type: 'STRING',
},
{
is_dttm: false,
name: '123',
column_name: '123',
type: 'STRING',
},
{
is_dttm: false,
name: 'CASE WHEN 1=1 THEN 1 ELSE 0 END',
column_name: 'CASE WHEN 1=1 THEN 1 ELSE 0 END',
type: 'STRING',
},
{
is_dttm: true,
name: '_TIMESTAMP',
column_name: '_TIMESTAMP',
type: 'TIMESTAMP',
},
{
is_dttm: true,
name: '__TIME',
column_name: '__TIME',
type: 'TIMESTAMP',
},
{
is_dttm: false,
name: 'my_dupe_col__2',
column_name: 'my_dupe_col__2',
type: 'STRING',
},
{
is_dttm: true,
name: '__timestamp',
column_name: '__timestamp',
type: 'TIMESTAMP',
},
{
is_dttm: true,
name: '__TIMESTAMP',
column_name: '__TIMESTAMP',
type: 'TIMESTAMP',
},
],
Expand Down Expand Up @@ -572,31 +572,31 @@ const baseQuery: QueryResponse = {
columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
{
is_dttm: false,
name: 'gender',
column_name: 'gender',
type: 'STRING',
},
],
selected_columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
{
is_dttm: false,
name: 'gender',
column_name: 'gender',
type: 'STRING',
},
],
expanded_columns: [
{
is_dttm: true,
name: 'ds',
column_name: 'ds',
type: 'STRING',
},
],
Expand Down
11 changes: 6 additions & 5 deletions superset-frontend/src/components/Datasource/DatasourceEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,9 @@ class DatasourceEditor extends React.PureComponent {
}

updateColumns(cols) {
// cols: Array<{column_name: string; is_dttm: boolean; type: string;}>
const { databaseColumns } = this.state;
const databaseColumnNames = cols.map(col => col.name);
const databaseColumnNames = cols.map(col => col.column_name);
const currentCols = databaseColumns.reduce(
(agg, col) => ({
...agg,
Expand All @@ -706,18 +707,18 @@ class DatasourceEditor extends React.PureComponent {
.filter(col => !databaseColumnNames.includes(col)),
};
cols.forEach(col => {
const currentCol = currentCols[col.name];
const currentCol = currentCols[col.column_name];
if (!currentCol) {
// new column
finalColumns.push({
id: shortid.generate(),
column_name: col.name,
column_name: col.column_name,
type: col.type,
groupby: true,
filterable: true,
is_dttm: col.is_dttm,
});
results.added.push(col.name);
results.added.push(col.column_name);
} else if (
currentCol.type !== col.type ||
(!currentCol.is_dttm && col.is_dttm)
Expand All @@ -728,7 +729,7 @@ class DatasourceEditor extends React.PureComponent {
type: col.type,
is_dttm: currentCol.is_dttm || col.is_dttm,
});
results.modified.push(col.name);
results.modified.push(col.column_name);
} else {
// unchanged
finalColumns.push(currentCol);
Expand Down
Loading