diff --git a/pyhive/common.py b/pyhive/common.py index 99fe55c8..f75950c2 100644 --- a/pyhive/common.py +++ b/pyhive/common.py @@ -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)): @@ -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) diff --git a/pyhive/tests/test_common.py b/pyhive/tests/test_common.py index 8642610f..99fd0080 100644 --- a/pyhive/tests/test_common.py +++ b/pyhive/tests/test_common.py @@ -4,6 +4,7 @@ from pyhive import common import datetime import unittest +import decimal class TestCommon(unittest.TestCase): @@ -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')}),