Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for decimal type parameters #408 #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -241,7 +242,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