druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

[dbapi] Fixing application of parameters #171

Closed john-bodley closed 5 years ago

john-bodley commented 5 years ago

This PR fixes an issue where the SQL statement contains a % character (possibly in an alias) where and when no parameters are specified the following is problematic,

>>> 'SELECT 100 AS "100%"' % {}
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: unsupported format character '"' (0x22) at index 19

The fix uses the same logic as PyHive and only formats the operation (using the pyformat convention) if parameters exist.

Additionally it resolves an issue which surfaced by adding unit tests caused by the fact that a bool is an instance of int, i.e.,

>>> x = True
>>> isinstance(x, int)
True

and thus booleans weren't being escaped correctly.

to: @betodealmeida @mistercrunch

betodealmeida commented 5 years ago

Additionally it resolves an issue which surfaced by adding unit tests caused by the fact that a bool is an instance of int, i.e.,

WTF, I thought this was fixed a long time ago in Python. (IIRC initially False and True were simply aliases to 0 and 1.)

john-bodley commented 5 years ago

@betodealmeida I also wasn't aware that was the case. The reason is explained here and the solution implemented uses the same logic they suggest.