OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test_ra Namespace Reference

Functions

def test_init
 
def test_import_table
 
def test_projection
 
def test_drop
 
def test_iloc
 
def test_empty
 
def test_filter
 
def test_filter_with_index
 
def test_filter_proj
 
def test_filter_drop
 

Variables

 engine = None
 

Function Documentation

def test_ra.test_drop ( )

Definition at line 49 of file test_ra.py.

49 
50 def test_drop():
51  ra = """execute calcite {"rels": [
52 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
53 {"id": "1", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
54 {"id": "2", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
55 {"id": "3", "relOp": "LogicalAggregate", "fields": ["F_a", "F_b", "F_c"], "group": [0], "aggs": [{"agg": "SUM", "operands": [1],
56 "distinct": false, "type": {"type": "DOUBLE", "nullable": true}}, {"agg": "SUM", "operands": [2], "distinct": false, "type": {"type": "DOUBLE", "nullable": true}}]},
57 {"id": "4", "relOp": "LogicalSort", "collation": [{"field": 0, "direction": "ASCENDING", "nulls": "LAST"}]},
58 {"id": "5", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
59 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
60 {"op": ">", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
61 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}}, {"id": "6", "relOp": "LogicalProject",
62 "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]}]}
63 """
64  target = {'F_a': [2, 3], '$f1': [3, 3], '$f2': [2, 1]}
65  cursor = engine.executeRA(ra)
66  batch = cursor.getArrowRecordBatch()
67  assert batch.to_pydict() == target
def test_drop
Definition: test_ra.py:49
def test_ra.test_empty ( )

Definition at line 94 of file test_ra.py.

94 
95 def test_empty():
96  ra = """execute calcite {"rels": [
97 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
98 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
99 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
100 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
101 {"op": "=", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
102 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
103 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}, {"input": 3}]}]}
104 """
105  target = {'F___index__': [0, 1], 'F_a': [1, 1], 'F_b': [None, None], 'F_c': [3, None]}
106  cursor = engine.executeRA(ra)
107  batch = cursor.getArrowRecordBatch()
108  assert batch.to_pydict() == target
def test_empty
Definition: test_ra.py:94
def test_ra.test_filter ( )

Definition at line 109 of file test_ra.py.

110 def test_filter():
111  ra = """execute calcite {"rels": [
112 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
113 {"id": "1", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
114 {"id": "2", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
115 {"id": "3", "relOp": "LogicalAggregate", "fields": ["F_a", "F_b", "F_c"], "group": [0], "aggs": [
116 {"agg": "SUM", "operands": [1], "distinct": false, "type": {"type": "DOUBLE", "nullable": true}},
117 {"agg": "SUM", "operands": [2], "distinct": false, "type": {"type": "DOUBLE", "nullable": true}}]},
118 {"id": "4", "relOp": "LogicalSort", "collation": [{"field": 0, "direction": "ASCENDING", "nulls": "LAST"}]},
119 {"id": "5", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
120 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
121 {"op": ">", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
122 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
123 {"id": "6", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]}]}
124 """
125  target = {'F_a': [2, 3], '$f1': [3, 3], '$f2': [2, 1]}
126  cursor = engine.executeRA(ra)
127  batch = cursor.getArrowRecordBatch()
128  assert batch.to_pydict() == target
def test_filter
Definition: test_ra.py:109
def test_ra.test_filter_drop ( )

Definition at line 168 of file test_ra.py.

169 def test_filter_drop():
170  ra = """execute calcite {"rels": [
171 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
172 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
173 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
174 {"literal": true, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
175 {"op": "<>", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
176 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
177 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b"], "exprs": [{"input": 0},
178 {"op": "*", "operands": [{"input": 1}, {"input": 2}], "type": {"type": "DOUBLE", "nullable": true}}, {"input": 2}]}]}
179 """
180  target = {'F___index__': [2, 3, 4], 'F_a': [4, 2, 9], 'F_b': [2, 1, 3]}
181  cursor = engine.executeRA(ra)
182  batch = cursor.getArrowRecordBatch()
183  assert batch.to_pydict() == target
def test_filter_drop
Definition: test_ra.py:168
def test_ra.test_filter_proj ( )

Definition at line 152 of file test_ra.py.

153 def test_filter_proj():
154  ra = """execute calcite {"rels": [
155 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
156 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
157 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
158 {"literal": true, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
159 {"op": "<>", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
160 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
161 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b"],
162 "exprs": [{"input": 0}, {"op": "*", "operands": [{"input": 1}, {"input": 2}], "type": {"type": "DOUBLE", "nullable": true}}, {"input": 2}]}]}
163 """
164  target = {'F___index__': [2, 3, 4], 'F_a': [4, 2, 9], 'F_b': [2, 1, 3]}
165  cursor = engine.executeRA(ra)
166  batch = cursor.getArrowRecordBatch()
167  assert batch.to_pydict() == target
def test_filter_proj
Definition: test_ra.py:152
def test_ra.test_filter_with_index ( )

Definition at line 129 of file test_ra.py.

131  ra = """execute calcite {"rels": [
132 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
133 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
134 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"op": "+", "operands": [{"input": 1},
135 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
136 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}},
137 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
138 {"op": ">", "operands": [{"op": "+", "operands": [{"input": 1}, {"op": "+", "operands": [{"input": 2},
139 {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
140 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}},
141 {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
142 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
143 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0},
144 {"op": "+", "operands": [{"input": 1}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}], "type": {"type": "BIGINT", "nullable": true}},
145 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}], "type": {"type": "DOUBLE", "nullable": true}},
146 {"op": "+", "operands": [{"input": 3}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}], "type": {"type": "DOUBLE", "nullable": true}}]}]}
147 """
148  target = {'F___index__': [2, 3, 4], 'F_a': [4, 4, 5], 'F_b': [4, 3, 5], 'F_c': [None, 4, 3]}
149  cursor = engine.executeRA(ra)
150  batch = cursor.getArrowRecordBatch()
151  assert batch.to_pydict() == target
def test_filter_with_index
Definition: test_ra.py:129
def test_ra.test_iloc ( )

Definition at line 68 of file test_ra.py.

68 
69 def test_iloc():
70  ra = """execute calcite {"rels": [
71 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
72 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
73 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"op": "+", "operands": [{"input": 1},
74 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
75 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}},
76 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
77 {"op": ">", "operands": [{"op": "+", "operands": [{"input": 1},
78 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
79 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}},
80 {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
81 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
82 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0},
83 {"op": "+", "operands": [{"input": 1}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
84 "type": {"type": "BIGINT", "nullable": true}},
85 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
86 "type": {"type": "DOUBLE", "nullable": true}},
87 {"op": "+", "operands": [{"input": 3}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
88 "type": {"type": "DOUBLE", "nullable": true}}]}]}
89 """
90  target = {'F___index__': [2, 3, 4], 'F_a': [4, 4, 5], 'F_b': [4, 3, 5], 'F_c': [None, 4, 3]}
91  cursor = engine.executeRA(ra)
92  batch = cursor.getArrowRecordBatch()
93  assert batch.to_pydict() == target
def test_iloc
Definition: test_ra.py:68
def test_ra.test_import_table ( )

Definition at line 23 of file test_ra.py.

23 
24 def test_import_table():
25  data = [
26  pa.array([1, 1, 2, 2, 3]),
27  pa.array([None, None, 2, 1, 3]),
28  pa.array([3, None, None, 2, 1])
29  ]
30  table = pa.Table.from_arrays(data, ['F_a', 'F_b', 'F_c'])
31  engine.importArrowTable('test', table)
32  assert engine.get_tables() == ['test']
33 
def test_import_table
Definition: test_ra.py:23
def test_ra.test_init ( )

Definition at line 11 of file test_ra.py.

11 
12 def test_init():
13  global engine
14  engine = dbe.PyDbEngine(
15  enable_union=1,
16  enable_columnar_output=1,
17  enable_lazy_fetch=0,
18  null_div_by_zero=1,
19  )
20  assert bool(engine.closed) == False
def test_init
Definition: test_ra.py:11
def test_ra.test_projection ( )

Definition at line 34 of file test_ra.py.

34 
35 def test_projection():
36  ra = """execute calcite {"rels": [
37 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
38 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
39 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
40 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
41 {"op": "=", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
42 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
43 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}, {"input": 3}]}]}
44 """
45  target = {'F___index__': [0, 1], 'F_a': [1, 1], 'F_b': [None, None], 'F_c': [3, None]}
46  cursor = engine.executeRA(ra)
47  batch = cursor.getArrowRecordBatch()
48  assert batch.to_pydict() == target
def test_projection
Definition: test_ra.py:34

Variable Documentation

test_ra.engine = None

Definition at line 21 of file test_ra.py.