PyHive
PyHive copied to clipboard
Fix queries with wildcards
This patch fixes queries that use wildcards (%) in SQLAlchemy. The params argument is an empty dict if no extra parameters are provided. This causes line 256 of presto.py to always branch to the else case, which causes an error (see the bottom).
Here is a minimal example to trigger the bug:
from sqlalchemy.engine import create_engine
engine = create_engine('presto://localhost:8080/hive/importdemo4')
engine.execute("CREATE TABLE demo_table (X VARCHAR)")
resultProxy = engine.execute("SELECT * FROM demo_table where x like 'a%'")
print(resultProxy.fetchone())
Resulting error:
Traceback (most recent call last):
File "/Users/e.semeniuc/dev/SDB-Health-Report/prestodemo.py", line 31, in <module>
resultProxy = engine.execute("SELECT * FROM demo_table where x like 'a%'")
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2238, in execute
return connection.execute(statement, *multiparams, **params)
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1006, in execute
return self._execute_text(object_, multiparams, params)
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1175, in _execute_text
ret = self._execute_context(
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1317, in _execute_context
self._handle_dbapi_exception(
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1515, in _handle_dbapi_exception
util.raise_(exc_info[1], with_traceback=exc_info[2])
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
raise exception
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1277, in _execute_context
self.dialect.do_execute(
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
cursor.execute(statement, parameters)
File "/Users/e.semeniuc/dev/SDB-Health-Report/venv/lib/python3.8/site-packages/pyhive/presto.py", line 249, in execute
sql = operation % _escaper.escape_args(parameters)
ValueError: unsupported format character ''' (0x27) at index 41
Codecov Report
Merging #351 (6ef94d1) into master (1548ecc) will decrease coverage by
0.12%. The diff coverage is100.00%.
:exclamation: Current head 6ef94d1 differs from pull request most recent head 80691ff. Consider uploading reports for the commit 80691ff to get more accurate results
@@ Coverage Diff @@
## master #351 +/- ##
==========================================
- Coverage 93.36% 93.23% -0.13%
==========================================
Files 14 14
Lines 1553 1553
Branches 167 167
==========================================
- Hits 1450 1448 -2
- Misses 75 77 +2
Partials 28 28
| Impacted Files | Coverage Ξ | |
|---|---|---|
| pyhive/presto.py | 85.27% <100.00%> (-1.23%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Ξ = absolute <relative> (impact),ΓΈ = not affected,? = missing dataPowered by Codecov. Last update b21c507...80691ff. Read the comment docs.
Could I get a review?
Follow up if this can be merged
We are also affected by this issue. Is there any way to merge/release this PR?
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.