[sql lab] reduce the number of metadata calls when loading a table (#4593)

This commit is contained in:
Maxime Beauchemin
2018-03-15 17:53:34 -07:00
committed by GitHub
parent da842f113a
commit 93ec76f757
4 changed files with 46 additions and 17 deletions

View File

@@ -4,14 +4,16 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import unittest
import textwrap
from sqlalchemy.engine.url import make_url
from tests.base_tests import SupersetTestCase
from superset import db
from superset.models.core import Database
class DatabaseModelTestCase(unittest.TestCase):
class DatabaseModelTestCase(SupersetTestCase):
def test_database_schema_presto(self):
sqlalchemy_uri = 'presto://presto.airbnb.io:8080/hive/default'
@@ -73,3 +75,25 @@ class DatabaseModelTestCase(unittest.TestCase):
model.impersonate_user = False
user_name = make_url(model.get_sqla_engine(user_name=example_user).url).username
self.assertNotEquals(example_user, user_name)
def test_select_star(self):
main_db = self.get_main_database(db.session)
table_name = 'bart_lines'
sql = main_db.select_star(
table_name, show_cols=False, latest_partition=False)
expected = textwrap.dedent("""\
SELECT *
FROM {table_name}
LIMIT 100""".format(**locals()))
assert sql.startswith(expected)
sql = main_db.select_star(
table_name, show_cols=True, latest_partition=False)
expected = textwrap.dedent("""\
SELECT color,
name,
path_json,
polyline
FROM bart_lines
LIMIT 100""".format(**locals()))
assert sql.startswith(expected)