You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2019/09/05 19:44:47 UTC

[incubator-superset] branch master updated: [bugfix] Correctly quote table and schema in select_star (#8181)

This is an automated email from the ASF dual-hosted git repository.

villebro 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 4e1e54b  [bugfix] Correctly quote table and schema in select_star (#8181)
4e1e54b is described below

commit 4e1e54b538c935e2d666758341a6dfa00f58e4f3
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Thu Sep 5 22:44:34 2019 +0300

    [bugfix] Correctly quote table and schema in select_star (#8181)
    
    * Fix select_star table quoting bug
    
    * Add unit test for fully qualified names in select_star
    
    * Rename main_db to db
    
    * Rename test function
---
 superset/connectors/sqla/models.py |  2 +-
 tests/model_tests.py               | 28 +++++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 24d1243..3407b76 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -478,7 +478,7 @@ class SqlaTable(Model, BaseDatasource):
         # show_cols and latest_partition set to false to avoid
         # the expensive cost of inspecting the DB
         return self.database.select_star(
-            self.name, show_cols=False, latest_partition=False
+            self.table_name, schema=self.schema, show_cols=False, latest_partition=False
         )
 
     def get_col(self, col_name):
diff --git a/tests/model_tests.py b/tests/model_tests.py
index 55926cf..f65db84 100644
--- a/tests/model_tests.py
+++ b/tests/model_tests.py
@@ -104,9 +104,9 @@ class DatabaseModelTestCase(SupersetTestCase):
         self.assertNotEquals(example_user, user_name)
 
     def test_select_star(self):
-        main_db = get_example_database()
+        db = get_example_database()
         table_name = "energy_usage"
-        sql = main_db.select_star(table_name, show_cols=False, latest_partition=False)
+        sql = db.select_star(table_name, show_cols=False, latest_partition=False)
         expected = textwrap.dedent(
             f"""\
         SELECT *
@@ -115,7 +115,7 @@ class DatabaseModelTestCase(SupersetTestCase):
         )
         assert sql.startswith(expected)
 
-        sql = main_db.select_star(table_name, show_cols=True, latest_partition=False)
+        sql = db.select_star(table_name, show_cols=True, latest_partition=False)
         expected = textwrap.dedent(
             f"""\
         SELECT source,
@@ -126,6 +126,28 @@ class DatabaseModelTestCase(SupersetTestCase):
         )
         assert sql.startswith(expected)
 
+    def test_select_star_fully_qualified_names(self):
+        db = get_example_database()
+        schema = "schema.name"
+        table_name = "table/name"
+        sql = db.select_star(
+            table_name, schema=schema, show_cols=False, latest_partition=False
+        )
+        fully_qualified_names = {
+            "sqlite": '"schema.name"."table/name"',
+            "mysql": "`schema.name`.`table/name`",
+            "postgres": '"schema.name"."table/name"',
+        }
+        fully_qualified_name = fully_qualified_names.get(db.db_engine_spec.engine)
+        if fully_qualified_name:
+            expected = textwrap.dedent(
+                f"""\
+            SELECT *
+            FROM {fully_qualified_name}
+            LIMIT 100"""
+            )
+            assert sql.startswith(expected)
+
     def test_single_statement(self):
         main_db = get_main_database()