From 08ff644539139b625149a72b19ef12a982fff88b Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Thu, 10 May 2018 13:58:31 -0700 Subject: [PATCH] Fixing build --- superset/db_engine_specs.py | 2 +- superset/models/core.py | 4 +--- superset/sql_lab.py | 1 - tests/celery_tests.py | 32 ---------------------------- tests/db_engine_specs_test.py | 39 ++++++++++++++++++----------------- 5 files changed, 22 insertions(+), 56 deletions(-) diff --git a/superset/db_engine_specs.py b/superset/db_engine_specs.py index 189fb713db36d..2cf4891d73cf8 100644 --- a/superset/db_engine_specs.py +++ b/superset/db_engine_specs.py @@ -103,7 +103,7 @@ def apply_limit_to_sql(cls, sql, limit, database): ) return database.compile_sqla_query(qry) elif LimitMethod.FORCE_LIMIT: - no_limit = re.sub(r"(?i)\s+LIMIT\s+\d+;?(\s|;)*$", '', sql) + no_limit = re.sub(r'(?i)\s+LIMIT\s+\d+;?(\s|;)*$', '', sql) return "{no_limit} LIMIT {limit}".format(**locals()) return sql diff --git a/superset/models/core.py b/superset/models/core.py index 2187b0540bd6b..ed33461f23c5e 100644 --- a/superset/models/core.py +++ b/superset/models/core.py @@ -22,7 +22,7 @@ import sqlalchemy as sqla from sqlalchemy import ( Boolean, Column, create_engine, DateTime, ForeignKey, Integer, - MetaData, select, String, Table, Text, + MetaData, String, Table, Text, ) from sqlalchemy.engine import url from sqlalchemy.engine.url import make_url @@ -30,8 +30,6 @@ from sqlalchemy.orm.session import make_transient from sqlalchemy.pool import NullPool from sqlalchemy.schema import UniqueConstraint -from sqlalchemy.sql import text -from sqlalchemy.sql.expression import TextAsFrom from sqlalchemy_utils import EncryptedType from superset import app, db, db_engine_specs, security_manager, utils diff --git a/superset/sql_lab.py b/superset/sql_lab.py index 99ec957d80d1c..881271a2281f9 100644 --- a/superset/sql_lab.py +++ b/superset/sql_lab.py @@ -17,7 +17,6 @@ from sqlalchemy.pool import NullPool from superset import app, dataframe, db, results_backend, security_manager, utils -from superset.db_engine_specs import LimitMethod from superset.models.sql_lab import Query from superset.sql_parse import SupersetQuery from superset.utils import get_celery_app, QueryStatus diff --git a/tests/celery_tests.py b/tests/celery_tests.py index 79b71e986e2aa..f6d1a2958fd1c 100644 --- a/tests/celery_tests.py +++ b/tests/celery_tests.py @@ -139,38 +139,6 @@ def run_sql(self, db_id, sql, client_id, cta='false', tmp_table='tmp', self.logout() return json.loads(resp.data.decode('utf-8')) - def test_add_limit_to_the_query(self): - main_db = self.get_main_database(db.session) - - select_query = 'SELECT * FROM outer_space;' - updated_select_query = main_db.wrap_sql_limit(select_query, 100) - # Different DB engines have their own spacing while compiling - # the queries, that's why ' '.join(query.split()) is used. - # In addition some of the engines do not include OFFSET 0. - self.assertTrue( - 'SELECT * FROM (SELECT * FROM outer_space;) AS inner_qry ' - 'LIMIT 100' in ' '.join(updated_select_query.split()), - ) - - select_query_no_semicolon = 'SELECT * FROM outer_space' - updated_select_query_no_semicolon = main_db.wrap_sql_limit( - select_query_no_semicolon, 100) - self.assertTrue( - 'SELECT * FROM (SELECT * FROM outer_space) AS inner_qry ' - 'LIMIT 100' in - ' '.join(updated_select_query_no_semicolon.split()), - ) - - multi_line_query = ( - "SELECT * FROM planets WHERE\n Luke_Father = 'Darth Vader';" - ) - updated_multi_line_query = main_db.wrap_sql_limit(multi_line_query, 100) - self.assertTrue( - 'SELECT * FROM (SELECT * FROM planets WHERE ' - "Luke_Father = 'Darth Vader';) AS inner_qry LIMIT 100" in - ' '.join(updated_multi_line_query.split()), - ) - def test_run_sync_query_dont_exist(self): main_db = self.get_main_database(db.session) db_id = main_db.id diff --git a/tests/db_engine_specs_test.py b/tests/db_engine_specs_test.py index 71e6bc493bb8b..0726a68fbff0e 100644 --- a/tests/db_engine_specs_test.py +++ b/tests/db_engine_specs_test.py @@ -4,7 +4,8 @@ from __future__ import print_function from __future__ import unicode_literals -from superset.db_engine_specs import MssqlEngineSpec, HiveEngineSpec, MySQLEngineSpec +from superset.db_engine_specs import ( + HiveEngineSpec, MssqlEngineSpec, MySQLEngineSpec) from superset.models.core import Database from .base_tests import SupersetTestCase @@ -82,43 +83,43 @@ def test_job_2_launched_stage_2_stages_progress(self): self.assertEquals(60, HiveEngineSpec.progress(log)) def test_wrapped_query(self): - sql = "SELECT * FROM a" - db = Database(sqlalchemy_uri="mysql://localhost") + sql = 'SELECT * FROM a' + db = Database(sqlalchemy_uri='mysql://localhost') limited = MssqlEngineSpec.apply_limit_to_sql(sql, 1000, db) - expected = """SELECT * \nFROM (SELECT * FROM a) AS inner_qry \n LIMIT 1000""" + expected = 'SELECT * \nFROM (SELECT * FROM a) AS inner_qry \n LIMIT 1000' self.assertEquals(expected, limited) def test_simple_limit_query(self): - sql = "SELECT * FROM a" - db = Database(sqlalchemy_uri="mysql://localhost") + sql = 'SELECT * FROM a' + db = Database(sqlalchemy_uri='mysql://localhost') limited = MySQLEngineSpec.apply_limit_to_sql(sql, 1000, db) - expected = """SELECT * FROM a LIMIT 1000""" + expected = 'SELECT * FROM a LIMIT 1000' self.assertEquals(expected, limited) def test_modify_limit_query(self): - sql = "SELECT * FROM a LIMIT 9999" - db = Database(sqlalchemy_uri="mysql://localhost") + sql = 'SELECT * FROM a LIMIT 9999' + db = Database(sqlalchemy_uri='mysql://localhost') limited = MySQLEngineSpec.apply_limit_to_sql(sql, 1000, db) - expected = """SELECT * FROM a LIMIT 1000""" + expected = 'SELECT * FROM a LIMIT 1000' self.assertEquals(expected, limited) def test_modify_newline_query(self): - sql = "SELECT * FROM a\nLIMIT 9999" - db = Database(sqlalchemy_uri="mysql://localhost") + sql = 'SELECT * FROM a\nLIMIT 9999' + db = Database(sqlalchemy_uri='mysql://localhost') limited = MySQLEngineSpec.apply_limit_to_sql(sql, 1000, db) - expected = """SELECT * FROM a LIMIT 1000""" + expected = 'SELECT * FROM a LIMIT 1000' self.assertEquals(expected, limited) def test_modify_lcase_limit_query(self): - sql = "SELECT * FROM a\tlimit 9999" - db = Database(sqlalchemy_uri="mysql://localhost") + sql = 'SELECT * FROM a\tlimit 9999' + db = Database(sqlalchemy_uri='mysql://localhost') limited = MySQLEngineSpec.apply_limit_to_sql(sql, 1000, db) - expected = """SELECT * FROM a LIMIT 1000""" + expected = 'SELECT * FROM a LIMIT 1000' self.assertEquals(expected, limited) def test_limit_query_with_limit_subquery(self): - sql = "SELECT * FROM (SELECT * FROM a LIMIT 10) LIMIT 9999" - db = Database(sqlalchemy_uri="mysql://localhost") + sql = 'SELECT * FROM (SELECT * FROM a LIMIT 10) LIMIT 9999' + db = Database(sqlalchemy_uri='mysql://localhost') limited = MySQLEngineSpec.apply_limit_to_sql(sql, 1000, db) - expected = "SELECT * FROM (SELECT * FROM a LIMIT 10) LIMIT 1000" + expected = 'SELECT * FROM (SELECT * FROM a LIMIT 10) LIMIT 1000' self.assertEquals(expected, limited)