Skip to content

Commit

Permalink
Add support for decimal type parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kotofos committed Aug 27, 2021
1 parent fd86c72 commit d96cb72
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyhive/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import datetime
from future.utils import with_metaclass
from itertools import islice
from decimal import Decimal


class DBAPICursor(with_metaclass(abc.ABCMeta, object)):
Expand Down Expand Up @@ -248,7 +249,7 @@ def escape_datetime(self, item, format, cutoff=0):
def escape_item(self, item):
if item is None:
return 'NULL'
elif isinstance(item, (int, float)):
elif isinstance(item, (int, float, Decimal)):
return self.escape_number(item)
elif isinstance(item, basestring):
return self.escape_string(item)
Expand Down
3 changes: 3 additions & 0 deletions pyhive/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pyhive import common
import datetime
import unittest
import decimal


class TestCommon(unittest.TestCase):
Expand All @@ -15,6 +16,8 @@ def test_escape_args(self):
{'foo': 123})
self.assertEqual(escaper.escape_args({'foo': 123.456}),
{'foo': 123.456})
self.assertEqual(escaper.escape_args({'foo': decimal.Decimal('123.456')}),
{'foo': decimal.Decimal('123.456')})
self.assertEqual(escaper.escape_args({'foo': ['a', 'b', 'c']}),
{'foo': "('a','b','c')"})
self.assertEqual(escaper.escape_args({'foo': ('a', 'b', 'c')}),
Expand Down

0 comments on commit d96cb72

Please sign in to comment.