john-bodley opened a new pull request #5178: John bodley sql percent sign URL: https://github.com/apache/incubator-superset/pull/5178 This PR came about due to an error when exporting a SQL Lab result to CSV. For example in Presto one can successfully run the following query: ``` SELECT '%' ``` which executes directly via the SQLAlchemy engine, however an error was thrown when trying to export to CSV which uses the Pandas interface where as `parameters` = `{}` which causes an exception in [PyHive](https://github.com/dropbox/PyHive/blob/master/pyhive/presto.py#L172) which uses the `pyformat` SQL [parameterstyle](https://www.python.org/dev/peps/pep-0249/#paramstyle). In essence, ``` SELECT '%' % {} ``` is invalid and thus one would need to escape the `%` character, i.e., ``` SELECT '%%' % {} ``` The reason for the error is the Pandas SQL interface neglects engine specific configuration of the DBAPI `execute` method. The fix is simply to bypass the Pandas API for querying and mimic the logic that SQL Lab uses which ensures that for presto `parameters` is `None` and thus it will not re-format the string. Note this PR also fixes the Hive and MySQL engine specs inline with their API, i.e., both [Hive](https://github.com/dropbox/PyHive/blob/master/pyhive/hive.py#L337) and [MySQL](https://github.com/PyMySQL/mysqlclient-python/blob/master/MySQLdb/cursors.py#L204) explicitly test whether the `parameters` and `args` respectively are `None` (rather than doing a boolean check). This means for MySQL in SQL Lab one can run queries of the form, ``` SELECT * FROM table WHERE column LIKE '%foo%' ``` as opposed to: ``` SELECT * FROM table WHERE column LIKE '%%foo%%' ``` since previously the MySQL engine spec defined `args` to `{}` causing the string to be formatted with the empty dictionary args. to: @betodealmeida @michellethomas @mistercrunch cc: @graceguo-supercat @timifasubaa
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org