Skip to content

Commit

Permalink
map hive types properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 committed Jun 30, 2021
1 parent 57eb662 commit 1a1ee73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pyhive/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import absolute_import
from __future__ import unicode_literals
__version__ = '0.6.9'
__version__ = '0.6.10'
15 changes: 9 additions & 6 deletions pyhive/sqlalchemy_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from sqlalchemy import exc
from sqlalchemy import processors
from sqlalchemy import types
from sqlalchemy import sql
from sqlalchemy.sql import sqltypes
from sqlalchemy import util
# TODO shouldn't use mysql type
from sqlalchemy.databases import mysql
Expand Down Expand Up @@ -133,10 +135,10 @@ def __init__(self, dialect):
'date': HiveDate,
'timestamp': HiveTimestamp,
'binary': types.String,
'array': types.String,
'map': types.String,
'struct': types.String,
'uniontype': types.String,
'array': sqltypes.NullType,
'map': sqltypes.NullType,
'struct': sqltypes.NullType,
'uniontype': sqltypes.NullType,
'decimal': HiveDecimal,
}

Expand Down Expand Up @@ -312,13 +314,13 @@ def get_columns(self, connection, table_name, schema=None, **kw):
# Filter out empty rows and comment
rows = [row for row in rows if row[0] and row[0] != '# col_name']
result = []
for (col_name, col_type, comment) in rows:
for (col_name, full_col_type, comment) in rows:
if col_name == '# Partition Information':
break
# Take out the more detailed type information
# e.g. 'map<int,int>' -> 'map'
# 'decimal(10,1)' -> decimal
col_type = re.search(r'^\w+', col_type).group(0)
col_type = re.search(r'^\w+', full_col_type).group(0)
try:
coltype = _type_map[col_type]
except KeyError:
Expand All @@ -328,6 +330,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
result.append({
'name': col_name,
'type': coltype,
'full_type': full_col_type,
'nullable': True,
'default': None,
'comment': comment,
Expand Down

0 comments on commit 1a1ee73

Please sign in to comment.