Skip to content

Commit a1261d7

Browse files
authored
Bump sqlparse to 0.3.0 (apache#7973)
* Black * Bump sqlparse to 0.3.0 * Convert str.format() to f-string
1 parent b8ca078 commit a1261d7

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ simplejson==3.16.0
7575
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
7676
sqlalchemy-utils==0.34.1
7777
sqlalchemy==1.3.6
78-
sqlparse==0.2.4
78+
sqlparse==0.3.0
7979
urllib3==1.25.3 # via requests, selenium
8080
vine==1.3.0 # via amqp, celery
8181
webencodings==0.5.1 # via bleach

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def get_git_sha():
9898
"simplejson>=3.15.0",
9999
"sqlalchemy>=1.3.5,<2.0",
100100
"sqlalchemy-utils>=0.33.2",
101-
"sqlparse<0.3",
101+
"sqlparse>=0.3.0,<0.4",
102102
"wtforms-json",
103103
],
104104
extras_require={

superset/sql_parse.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,19 @@ def get_query_with_new_limit(self, new_limit):
195195
if not self._limit:
196196
return f"{self.stripped()}\nLIMIT {new_limit}"
197197
limit_pos = None
198-
tokens = self._parsed[0].tokens
198+
statement = self._parsed[0]
199199
# Add all items to before_str until there is a limit
200-
for pos, item in enumerate(tokens):
200+
for pos, item in enumerate(statement.tokens):
201201
if item.ttype in Keyword and item.value.lower() == "limit":
202202
limit_pos = pos
203203
break
204-
limit = tokens[limit_pos + 2]
204+
_, limit = statement.token_next(idx=limit_pos)
205205
if limit.ttype == sqlparse.tokens.Literal.Number.Integer:
206-
tokens[limit_pos + 2].value = new_limit
206+
limit.value = new_limit
207207
elif limit.is_group:
208-
tokens[limit_pos + 2].value = "{}, {}".format(
209-
next(limit.get_identifiers()), new_limit
210-
)
208+
limit.value = f"{next(limit.get_identifiers())}, {new_limit}"
211209

212210
str_res = ""
213-
for i in tokens:
211+
for i in statement.tokens:
214212
str_res += str(i.value)
215213
return str_res

0 commit comments

Comments
 (0)