Skip to content

Commit

Permalink
[sql lab] preserve schema through visualize flow (#4742)
Browse files Browse the repository at this point in the history
* [sql lab] preserve schema through visualize flow

#4696 got tangled
into refactoring views out of views/core.py and onto views/sql_lab.py

This is the same PR without the refactoring.

* Fix lint
  • Loading branch information
mistercrunch authored Apr 4, 2018
1 parent 9a79d33 commit 3b7e0a9
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const $ = window.$ = require('jquery');

const propTypes = {
actions: PropTypes.object.isRequired,
height: PropTypes.number.isRequired,
height: PropTypes.string.isRequired,
};

class QuerySearch extends React.PureComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const propTypes = {
onHide: PropTypes.func,
query: PropTypes.object,
show: PropTypes.bool,
schema: PropTypes.string,
datasource: PropTypes.string,
errorMessage: PropTypes.string,
timeout: PropTypes.number,
Expand All @@ -48,6 +49,7 @@ class VisualizeModal extends React.PureComponent {
chartType: CHART_TYPES[0],
datasourceName: this.datasourceName(),
columns: this.getColumnFromProps(),
schema: props.query ? props.query.schema : null,
hints: [],
};
}
Expand Down Expand Up @@ -126,6 +128,7 @@ class VisualizeModal extends React.PureComponent {
buildVizOptions() {
return {
chartType: this.state.chartType.value,
schema: this.state.schema,
datasourceName: this.state.datasourceName,
columns: this.state.columns,
sql: this.props.query.sql,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ describe('VisualizeModal', () => {
chartType: wrapper.state().chartType.value,
datasourceName: wrapper.state().datasourceName,
columns: wrapper.state().columns,
schema: 'test_schema',
sql: wrapper.instance().props.query.sql,
dbId: wrapper.instance().props.query.dbId,
});
Expand Down
2 changes: 1 addition & 1 deletion superset/assets/spec/javascripts/sqllab/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export const queries = [
rows: 42,
endDttm: 1476910566798,
limit_reached: false,
schema: null,
schema: 'test_schema',
errorMessage: null,
db: 'main',
user: 'admin',
Expand Down
1 change: 1 addition & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2160,6 +2160,7 @@ def sqllab_viz(self):
if not table:
table = SqlaTable(table_name=table_name)
table.database_id = data.get('dbId')
table.schema = data.get('schema')
q = SupersetQuery(data.get('sql'))
table.sql = q.stripped()
db.session.add(table)
Expand Down
31 changes: 31 additions & 0 deletions tests/sqllab_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,37 @@ def test_df_conversion_dict(self):
self.assertEquals(len(data), cdf.size)
self.assertEquals(len(cols), len(cdf.columns))

def test_sqllab_viz(self):
payload = {
'chartType': 'dist_bar',
'datasourceName': 'test_viz_flow_table',
'schema': 'superset',
'columns': {
'viz_type': {
'is_date': False,
'type': 'STRING',
'nam:qe': 'viz_type',
'is_dim': True,
},
'ccount': {
'is_date': False,
'type': 'OBJECT',
'name': 'ccount',
'is_dim': True,
'agg': 'sum',
},
},
'sql': """\
SELECT viz_type, count(1) as ccount
FROM slices
WHERE viz_type LIKE '%%a%%'
GROUP BY viz_type""",
'dbId': 1,
}
data = {'data': json.dumps(payload)}
resp = self.get_json_resp('/superset/sqllab_viz/', data=data)
self.assertIn('table_id', resp)


if __name__ == '__main__':
unittest.main()

0 comments on commit 3b7e0a9

Please sign in to comment.