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

feat: Add Explore Database to CTAS/CVAS visualization flow #10174

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion superset-frontend/src/SqlLab/components/ResultSet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export default class ResultSet extends React.PureComponent {
this.props.search ? this.props.height - SEARCH_HEIGHT : this.props.height,
);
let sql;
let exploreDBId = query.dbId;
if (this.props.database && this.props.database.explore_database_id) {
exploreDBId = this.props.database.explore_database_id;
}

if (this.props.showSql) {
sql = <HighlightedSql sql={query.sql} />;
Expand Down Expand Up @@ -245,7 +249,7 @@ export default class ResultSet extends React.PureComponent {
<ExploreCtasResultsButton
table={tmpTable}
schema={tmpSchema}
dbId={query.dbId}
dbId={exploreDBId}
database={this.props.database}
actions={this.props.actions}
/>
Expand Down
5 changes: 5 additions & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def allows_virtual_table_explore(self) -> bool:

return bool(extra.get("allows_virtual_table_explore", True))

@property
def explore_database_id(self) -> int:
return self.get_extra().get("explore_database_id", self.id)

@property
def data(self) -> Dict[str, Any]:
return {
Expand All @@ -205,6 +209,7 @@ def data(self) -> Dict[str, Any]:
"allows_subquery": self.allows_subquery,
"allows_cost_estimate": self.allows_cost_estimate,
"allows_virtual_table_explore": self.allows_virtual_table_explore,
"explore_database_id": self.explore_database_id,
}

@property
Expand Down
1 change: 1 addition & 0 deletions superset/views/database/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ class DatabaseRestApi(DatabaseMixin, BaseSupersetModelRestApi):
"allows_subquery",
"allows_cost_estimate",
"allows_virtual_table_explore",
"explore_database_id",
"backend",
"function_names",
]
Expand Down
2 changes: 1 addition & 1 deletion superset/views/database/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def form_post(self, form: CsvToDatabaseForm) -> FlaskResponse:
# E.g. if hive was used to upload a csv, presto will be a better option
# to explore the table.
expore_database = database
explore_database_id = database.get_extra().get("explore_database_id", None)
explore_database_id = database.explore_database_id
if explore_database_id:
expore_database = (
db.session.query(models.Database)
Expand Down
14 changes: 14 additions & 0 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,20 @@ def test_virtual_table_explore_visibility(self):
database.extra = json.dumps(extra)
self.assertEqual(database.allows_virtual_table_explore, True)

def test_explore_database_id(self):
database = utils.get_example_database()
explore_database = utils.get_example_database()

# test that explore_database_id is the regular database
# id if none is set in the extra
self.assertEqual(database.explore_database_id, database.id)

# test that explore_database_id is correct if the extra is set
extra = database.get_extra()
extra["explore_database_id"] = explore_database.id
database.extra = json.dumps(extra)
self.assertEqual(database.explore_database_id, explore_database.id)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tests/database_api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_get_items(self):
"allows_virtual_table_explore",
"backend",
"database_name",
"explore_database_id",
"expose_in_sqllab",
"force_ctas_schema",
"function_names",
Expand Down