Skip to content

Commit

Permalink
Fixing build
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 10, 2018
1 parent be9084a commit 08ff644
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 56 deletions.
2 changes: 1 addition & 1 deletion superset/db_engine_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
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
from sqlalchemy.orm import relationship, subqueryload
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
Expand Down
1 change: 0 additions & 1 deletion superset/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 0 additions & 32 deletions tests/celery_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions tests/db_engine_specs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

0 comments on commit 08ff644

Please sign in to comment.