This is an automated email from the ASF dual-hosted git repository.
bkyryliuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 72fc581 added explore database for ctas/cvas (#10174)
72fc581 is described below
commit 72fc581b1559e7ce08b11c481b88eaa01b2d17de
Author: Jason Davis <[email protected]>
AuthorDate: Mon Jun 29 11:13:54 2020 -0700
added explore database for ctas/cvas (#10174)
Co-authored-by: Jason Davis <@dropbox.com>
---
superset-frontend/src/SqlLab/components/ResultSet.jsx | 6 +++++-
superset/models/core.py | 5 +++++
superset/views/database/api.py | 1 +
superset/views/database/views.py | 2 +-
tests/core_tests.py | 14 ++++++++++++++
tests/database_api_tests.py | 1 +
6 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/superset-frontend/src/SqlLab/components/ResultSet.jsx
b/superset-frontend/src/SqlLab/components/ResultSet.jsx
index 71f3f46..5dd3469 100644
--- a/superset-frontend/src/SqlLab/components/ResultSet.jsx
+++ b/superset-frontend/src/SqlLab/components/ResultSet.jsx
@@ -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} />;
@@ -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}
/>
diff --git a/superset/models/core.py b/superset/models/core.py
index 25922ac..595cbc7 100755
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -196,6 +196,10 @@ class Database(
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 {
"id": self.id,
@@ -205,6 +209,7 @@ class Database(
"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
diff --git a/superset/views/database/api.py b/superset/views/database/api.py
index 212dc8b..2caed02 100644
--- a/superset/views/database/api.py
+++ b/superset/views/database/api.py
@@ -137,6 +137,7 @@ class DatabaseRestApi(DatabaseMixin,
BaseSupersetModelRestApi):
"allows_subquery",
"allows_cost_estimate",
"allows_virtual_table_explore",
+ "explore_database_id",
"backend",
"function_names",
]
diff --git a/superset/views/database/views.py b/superset/views/database/views.py
index ae4b3bc..8865270 100644
--- a/superset/views/database/views.py
+++ b/superset/views/database/views.py
@@ -187,7 +187,7 @@ class CsvToDatabaseView(SimpleFormView):
# 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)
diff --git a/tests/core_tests.py b/tests/core_tests.py
index bb26a85..fde253e 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -1307,6 +1307,20 @@ class CoreTests(SupersetTestCase):
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()
diff --git a/tests/database_api_tests.py b/tests/database_api_tests.py
index 1b9e1ca..d0e9ecf 100644
--- a/tests/database_api_tests.py
+++ b/tests/database_api_tests.py
@@ -52,6 +52,7 @@ class DatabaseApiTests(SupersetTestCase):
"allows_virtual_table_explore",
"backend",
"database_name",
+ "explore_database_id",
"expose_in_sqllab",
"force_ctas_schema",
"function_names",