OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
heavydb._parsers Namespace Reference

Functions

def _format_result_timestamp
 
def _format_result_date
 
def _format_result_time
 
def _extract_col_vals
 
def _extract_description
 
def _extract_column_details
 
def _bind_parameters
 

Variables

tuple Description
 
tuple ColumnDetails
 
dictionary _typeattr
 
 _thrift_types_to_values = T.TDatumType._NAMES_TO_VALUES
 
 _thrift_values_to_types = T.TDatumType._VALUES_TO_NAMES
 
 _thrift_encodings_to_values = T.TEncodingType._NAMES_TO_VALUES
 
 _thrift_values_to_encodings = T.TEncodingType._VALUES_TO_NAMES
 

Detailed Description

Utility methods for parsing data returned from HeavyDB

Function Documentation

def heavydb._parsers._bind_parameters (   operation,
  parameters 
)
private

Definition at line 162 of file _parsers.py.

Referenced by tests.test_cursor.TestCursor.test_escape_basic(), and tests.test_cursor.TestCursor.test_escape_malicious().

163 def _bind_parameters(operation, parameters):
164  return (
165  text(operation)
166  .bindparams(**parameters)
167  .compile(compile_kwargs={"literal_binds": True})
168  )
def _bind_parameters
Definition: _parsers.py:162

+ Here is the caller graph for this function:

def heavydb._parsers._extract_col_vals (   desc,
  val 
)
private

Definition at line 89 of file _parsers.py.

References heavydb._parsers._format_result_date(), heavydb._parsers._format_result_time(), and heavydb._parsers._format_result_timestamp().

89 
90 def _extract_col_vals(desc, val):
91 
92  typename = T.TDatumType._VALUES_TO_NAMES[desc.col_type.type]
93  nulls = val.nulls
94 
95  # arr_col has multiple levels to parse, not accounted for in original code
96  # https://github.com/omnisci/pymapd/issues/68
97  if hasattr(val.data, 'arr_col') and val.data.arr_col:
98  vals = [
99  None if null else getattr(v.data, _typeattr[typename] + '_col')
100  for null, v in zip(nulls, val.data.arr_col)
101  ]
102 
103  if typename == 'TIMESTAMP':
104  vals = [_format_result_timestamp(desc, v) for v in vals]
105  elif typename == 'DATE':
106  vals = [_format_result_date(v) for v in vals]
107  elif typename == 'TIME':
108  vals = [_format_result_time(v) for v in vals]
109 
110  # else clause original code path
111  else:
112  vals = getattr(val.data, _typeattr[typename] + '_col')
113  vals = [None if null else v for null, v in zip(nulls, vals)]
114 
115  if typename == 'TIMESTAMP':
116  vals = _format_result_timestamp(desc, vals)
117  elif typename == 'DATE':
118  vals = _format_result_date(vals)
119  elif typename == 'TIME':
120  vals = _format_result_time(vals)
121 
122  return vals
123 
def _format_result_date
Definition: _parsers.py:75
def _format_result_time
Definition: _parsers.py:84
def _extract_col_vals
Definition: _parsers.py:89
def _format_result_timestamp
Definition: _parsers.py:65

+ Here is the call graph for this function:

def heavydb._parsers._extract_column_details (   row_desc)
private

Definition at line 145 of file _parsers.py.

References heavydb._parsers.ColumnDetails.

Referenced by tests.test_connection.TestExtras.test_extract_row_details().

146 def _extract_column_details(row_desc):
147  # For Connection.get_table_details
148  return [
150  x.col_name,
151  _thrift_values_to_types[x.col_type.type],
152  x.col_type.nullable,
153  x.col_type.precision,
154  x.col_type.scale,
155  x.col_type.comp_param,
156  _thrift_values_to_encodings[x.col_type.encoding],
157  x.col_type.is_array,
158  )
159  for x in row_desc
160  ]
161 
def _extract_column_details
Definition: _parsers.py:145
tuple ColumnDetails
Definition: _parsers.py:23

+ Here is the caller graph for this function:

def heavydb._parsers._extract_description (   row_desc)
private
Return a tuple of (name, type_code, display_size, internal_size,
                   precision, scale, null_ok)

https://www.python.org/dev/peps/pep-0249/#description

Definition at line 124 of file _parsers.py.

References heavydb._parsers.Description.

125 def _extract_description(row_desc):
126  """
127  Return a tuple of (name, type_code, display_size, internal_size,
128  precision, scale, null_ok)
129 
130  https://www.python.org/dev/peps/pep-0249/#description
131  """
132  return [
133  Description(
134  col.col_name,
135  col.col_type.type,
136  None,
137  None,
138  None,
139  None,
140  col.col_type.nullable,
141  )
142  for col in row_desc
143  ]
144 
tuple Description
Definition: _parsers.py:11
def _extract_description
Definition: _parsers.py:124
def heavydb._parsers._format_result_date (   arr)
private

Definition at line 75 of file _parsers.py.

Referenced by heavydb._parsers._extract_col_vals().

75 
76 def _format_result_date(arr):
77 
78  base = datetime.datetime(1970, 1, 1)
79  return [
80  None if v is None else (base + datetime.timedelta(seconds=v)).date()
81  for v in arr
82  ]
83 
def _format_result_date
Definition: _parsers.py:75

+ Here is the caller graph for this function:

def heavydb._parsers._format_result_time (   arr)
private

Definition at line 84 of file _parsers.py.

References heavydb._utils.seconds_to_time().

Referenced by heavydb._parsers._extract_col_vals().

84 
85 def _format_result_time(arr):
86 
87  return [None if v is None else seconds_to_time(v) for v in arr]
88 
def _format_result_time
Definition: _parsers.py:84
def seconds_to_time
Definition: _utils.py:5

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

def heavydb._parsers._format_result_timestamp (   desc,
  arr 
)
private

Definition at line 65 of file _parsers.py.

References heavydb._utils.datetime_in_precisions().

Referenced by heavydb._parsers._extract_col_vals().

65 
66 def _format_result_timestamp(desc, arr):
67 
68  return [
69  None
70  if v is None
71  else datetime_in_precisions(v, desc.col_type.precision)
72  for v in arr
73  ]
74 
def datetime_in_precisions
Definition: _utils.py:19
def _format_result_timestamp
Definition: _parsers.py:65

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

heavydb._parsers._thrift_encodings_to_values = T.TEncodingType._NAMES_TO_VALUES

Definition at line 61 of file _parsers.py.

heavydb._parsers._thrift_types_to_values = T.TDatumType._NAMES_TO_VALUES

Definition at line 59 of file _parsers.py.

heavydb._parsers._thrift_values_to_encodings = T.TEncodingType._VALUES_TO_NAMES

Definition at line 62 of file _parsers.py.

heavydb._parsers._thrift_values_to_types = T.TDatumType._VALUES_TO_NAMES

Definition at line 60 of file _parsers.py.

dictionary heavydb._parsers._typeattr
Initial value:
1 = {
2  'SMALLINT': 'int',
3  'INT': 'int',
4  'BIGINT': 'int',
5  'TIME': 'int',
6  'TIMESTAMP': 'int',
7  'DATE': 'int',
8  'BOOL': 'int',
9  'FLOAT': 'real',
10  'DECIMAL': 'real',
11  'DOUBLE': 'real',
12  'STR': 'str',
13  'POINT': 'str',
14  'MULTIPOINT': 'str',
15  'LINESTRING': 'str',
16  'MULTILINESTRING': 'str',
17  'POLYGON': 'str',
18  'MULTIPOLYGON': 'str',
19  'TINYINT': 'int',
20  'GEOMETRY': 'str',
21  'GEOGRAPHY': 'str',
22 }

Definition at line 37 of file _parsers.py.

tuple heavydb._parsers.ColumnDetails
Initial value:
1 = namedtuple(
2  "ColumnDetails",
3  [
4  "name",
5  "type",
6  "nullable",
7  "precision",
8  "scale",
9  "comp_param",
10  "encoding",
11  "is_array",
12  ],
13 )

Definition at line 23 of file _parsers.py.

Referenced by heavydb._parsers._extract_column_details(), and tests.test_connection.TestExtras.test_extract_row_details().

tuple heavydb._parsers.Description
Initial value:
1 = namedtuple(
2  "Description",
3  [
4  "name",
5  "type_code",
6  "display_size",
7  "internal_size",
8  "precision",
9  "scale",
10  "null_ok",
11  ],
12 )

Definition at line 11 of file _parsers.py.

Referenced by heavydb._parsers._extract_description(), and tests.test_integration.TestIntegration.test_select_sets_description().