Skip to content

Commit

Permalink
Add PEP249 required type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
takuti authored and ggreg committed Feb 7, 2019
1 parent 569babd commit 454e77c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions prestodb/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from __future__ import print_function

from typing import Any, List, Optional # NOQA for mypy types
import datetime

from prestodb import constants
import prestodb.exceptions
Expand Down Expand Up @@ -297,3 +298,41 @@ def cancel(self):

def close(self):
self._connection.close()


Date = datetime.date
Time = datetime.time
Timestamp = datetime.datetime
DateFromTicks = datetime.date.fromtimestamp
TimestampFromTicks = datetime.datetime.fromtimestamp


def TimeFromTicks(ticks):
return datetime.time(*datetime.localtime(ticks)[3:6])


def Binary(string):
return string.encode('utf-8')


class DBAPITypeObject:

def __init__(self, *values):
self.values = [v.lower() for v in values]

def __eq__(self, other):
return other.lower() in self.values


STRING = DBAPITypeObject('VARCHAR', 'CHAR', 'VARBINARY', 'JSON', 'IPADDRESS')

BINARY = DBAPITypeObject('ARRAY', 'MAP', 'ROW', 'HyperLogLog', 'P4HyperLogLog', 'QDigest')

NUMBER = DBAPITypeObject('BOOLEAN', 'TINYINT', 'SMALLINT', 'INTEGER', 'BIGINT',
'REAL', 'DOUBLE', 'DECIMAL')

DATETIME = DBAPITypeObject('DATE', 'TIME', 'TIME WITH TIME ZONE', 'TIMESTAMP',
'TIMESTAMP WITH TIME ZONE', 'INTERVAL YEAR TO MONTH',
'INTERVAL DAY TO SECOND')

ROWID = DBAPITypeObject() # nothing indicates row id in Presto

0 comments on commit 454e77c

Please sign in to comment.