From ceb2572d92ec3c6e1b4037175002929fabe3952f Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Thu, 1 Dec 2022 11:00:47 +0100 Subject: [PATCH] support precision and scale for DECIMAL/NUMERIC #439 --- pyhive/sqlalchemy_hive.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyhive/sqlalchemy_hive.py b/pyhive/sqlalchemy_hive.py index 2ef49652..642f5286 100644 --- a/pyhive/sqlalchemy_hive.py +++ b/pyhive/sqlalchemy_hive.py @@ -174,7 +174,15 @@ def visit_INTEGER(self, type_): return 'INT' def visit_NUMERIC(self, type_): - return 'DECIMAL' + precision = getattr(type_, "precision", None) + if precision is None: + return "DECIMAL" + else: + scale = getattr(type_, "scale", None) + if scale is None: + return "DECIMAL(%(precision)s)" % {"precision": precision} + else: + return "DECIMAL(%(precision)s, %(scale)s)" % {"precision": precision, "scale": scale} def visit_CHAR(self, type_): return 'STRING'