OmniSciDB  c1a53651b2
 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 160 of file _parsers.py.

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

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

+ Here is the caller graph for this function:

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

Definition at line 87 of file _parsers.py.

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

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

+ Here is the call graph for this function:

def heavydb._parsers._extract_column_details (   row_desc)
private

Definition at line 143 of file _parsers.py.

References heavydb._parsers.ColumnDetails.

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

144 def _extract_column_details(row_desc):
145  # For Connection.get_table_details
146  return [
148  x.col_name,
149  _thrift_values_to_types[x.col_type.type],
150  x.col_type.nullable,
151  x.col_type.precision,
152  x.col_type.scale,
153  x.col_type.comp_param,
154  _thrift_values_to_encodings[x.col_type.encoding],
155  x.col_type.is_array,
156  )
157  for x in row_desc
158  ]
159 
def _extract_column_details
Definition: _parsers.py:143
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 122 of file _parsers.py.

References heavydb._parsers.Description.

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

Definition at line 73 of file _parsers.py.

Referenced by heavydb._parsers._extract_col_vals().

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

+ Here is the caller graph for this function:

def heavydb._parsers._format_result_time (   arr)
private

Definition at line 82 of file _parsers.py.

References heavydb._utils.seconds_to_time().

Referenced by heavydb._parsers._extract_col_vals().

82 
83 def _format_result_time(arr):
84 
85  return [None if v is None else seconds_to_time(v) for v in arr]
86 
def _format_result_time
Definition: _parsers.py:82
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 63 of file _parsers.py.

References heavydb._utils.datetime_in_precisions().

Referenced by heavydb._parsers._extract_col_vals().

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

+ 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 59 of file _parsers.py.

heavydb._parsers._thrift_types_to_values = T.TDatumType._NAMES_TO_VALUES

Definition at line 57 of file _parsers.py.

heavydb._parsers._thrift_values_to_encodings = T.TEncodingType._VALUES_TO_NAMES

Definition at line 60 of file _parsers.py.

heavydb._parsers._thrift_values_to_types = T.TDatumType._VALUES_TO_NAMES

Definition at line 58 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  'LINESTRING': 'str',
15  'POLYGON': 'str',
16  'MULTIPOLYGON': 'str',
17  'TINYINT': 'int',
18  'GEOMETRY': 'str',
19  'GEOGRAPHY': 'str',
20 }

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().