Skip to content

Commit

Permalink
Bump sqlparse to 0.3.0 (apache#7973)
Browse files Browse the repository at this point in the history
* Black

* Bump sqlparse to 0.3.0

* Convert str.format() to f-string
  • Loading branch information
villebro authored Aug 5, 2019
1 parent b8ca078 commit a1261d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ simplejson==3.16.0
six==1.12.0 # via bleach, cryptography, flask-jwt-extended, flask-talisman, isodate, jsonschema, pathlib2, polyline, prison, pydruid, pyrsistent, python-dateutil, sqlalchemy-utils, wtforms-json
sqlalchemy-utils==0.34.1
sqlalchemy==1.3.6
sqlparse==0.2.4
sqlparse==0.3.0
urllib3==1.25.3 # via requests, selenium
vine==1.3.0 # via amqp, celery
webencodings==0.5.1 # via bleach
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_git_sha():
"simplejson>=3.15.0",
"sqlalchemy>=1.3.5,<2.0",
"sqlalchemy-utils>=0.33.2",
"sqlparse<0.3",
"sqlparse>=0.3.0,<0.4",
"wtforms-json",
],
extras_require={
Expand Down
14 changes: 6 additions & 8 deletions superset/sql_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,19 @@ def get_query_with_new_limit(self, new_limit):
if not self._limit:
return f"{self.stripped()}\nLIMIT {new_limit}"
limit_pos = None
tokens = self._parsed[0].tokens
statement = self._parsed[0]
# Add all items to before_str until there is a limit
for pos, item in enumerate(tokens):
for pos, item in enumerate(statement.tokens):
if item.ttype in Keyword and item.value.lower() == "limit":
limit_pos = pos
break
limit = tokens[limit_pos + 2]
_, limit = statement.token_next(idx=limit_pos)
if limit.ttype == sqlparse.tokens.Literal.Number.Integer:
tokens[limit_pos + 2].value = new_limit
limit.value = new_limit
elif limit.is_group:
tokens[limit_pos + 2].value = "{}, {}".format(
next(limit.get_identifiers()), new_limit
)
limit.value = f"{next(limit.get_identifiers())}, {new_limit}"

str_res = ""
for i in tokens:
for i in statement.tokens:
str_res += str(i.value)
return str_res

0 comments on commit a1261d7

Please sign in to comment.