OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dtypes.py
Go to the documentation of this file.
1 """
2 https://www.python.org/dev/peps/pep-0249/#type-objects
3 """
4 import datetime
5 import time
6 from heavydb.common.ttypes import TDatumType
7 
8 T = TDatumType
9 
10 
11 class DataType:
12  def __init__(self, matches):
13  self._matches = set(matches)
14 
15  def __eq__(self, other):
16  return other in self._matches
17 
18  def __ne__(self, other):
19  return not (self == other)
20 
21  def __hash__(self):
22  return hash(tuple(self._matches))
23 
24 
25 Binary = memoryview
26 Date = datetime.date
27 Time = datetime.time
28 Timestamp = datetime.datetime
29 
30 BINARY = DataType([])
31 STRING = DataType(
32  [
33  T.STR,
34  T.POINT,
35  T.MULTIPOINT,
36  T.LINESTRING,
37  T.MULTILINESTRING,
38  T.POLYGON,
39  T.MULTIPOLYGON,
40  T.GEOMETRY,
41  T.GEOGRAPHY,
42  ]
43 )
44 NUMBER = DataType(
45  [
46  T.SMALLINT,
47  T.INT,
48  T.BIGINT,
49  T.FLOAT,
50  T.DECIMAL,
51  T.DOUBLE,
52  T.BOOL,
53  T.TINYINT,
54  ]
55 )
56 DATETIME = DataType([T.DATE, T.TIME, T.TIMESTAMP])
57 ROWID = DataType([])
58 
59 
60 def DateFromTicks(ticks):
61  return Date(*time.localtime(ticks)[:3])
62 
63 
64 def TimeFromTicks(ticks):
65  return Time(*time.localtime(ticks)[3:6])
66 
67 
68 def TimestampFromTicks(ticks):
69  return Timestamp(*time.localtime(ticks)[:6])
def DateFromTicks
Definition: dtypes.py:60
def TimeFromTicks
Definition: dtypes.py:64
def TimestampFromTicks
Definition: dtypes.py:68