8 ctypes._dlopen(
'libDBEngine.so', ctypes.RTLD_GLOBAL)
13 engine = dbe.PyDbEngine(
15 enable_columnar_output=1,
19 assert bool(engine.closed) ==
False
25 pa.array([1, 1, 2, 2, 3]),
26 pa.array([
None,
None, 2, 1, 3]),
27 pa.array([3,
None,
None, 2, 1])
29 table = pa.Table.from_arrays(data, [
'F_a',
'F_b',
'F_c'])
30 engine.importArrowTable(
'test', table)
31 assert engine.get_tables() == [
'test']
35 ra =
"""execute calcite {"rels": [
36 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
37 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
38 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
39 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
40 {"op": "=", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
41 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
42 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}, {"input": 3}]}]}
44 target = {
'F___index__': [0, 1],
'F_a': [1, 1],
'F_b': [
None,
None],
'F_c': [3,
None]}
45 cursor = engine.executeRA(ra)
46 batch = cursor.getArrowRecordBatch()
47 assert batch.to_pydict() == target
50 ra =
"""execute calcite {"rels": [
51 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
52 {"id": "1", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
53 {"id": "2", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
54 {"id": "3", "relOp": "LogicalAggregate", "fields": ["F_a", "F_b", "F_c"], "group": [0], "aggs": [{"agg": "SUM", "operands": [1],
55 "distinct": false, "type": {"type": "DOUBLE", "nullable": true}}, {"agg": "SUM", "operands": [2], "distinct": false, "type": {"type": "DOUBLE", "nullable": true}}]},
56 {"id": "4", "relOp": "LogicalSort", "collation": [{"field": 0, "direction": "ASCENDING", "nulls": "LAST"}]},
57 {"id": "5", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
58 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
59 {"op": ">", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
60 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}}, {"id": "6", "relOp": "LogicalProject",
61 "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]}]}
63 target = {
'F_a': [2, 3],
'$f1': [3, 3],
'$f2': [2, 1]}
64 cursor = engine.executeRA(ra)
65 batch = cursor.getArrowRecordBatch()
66 assert batch.to_pydict() == target
69 ra =
"""execute calcite {"rels": [
70 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
71 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
72 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"op": "+", "operands": [{"input": 1},
73 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
74 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}},
75 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
76 {"op": ">", "operands": [{"op": "+", "operands": [{"input": 1},
77 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
78 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}},
79 {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
80 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
81 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0},
82 {"op": "+", "operands": [{"input": 1}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
83 "type": {"type": "BIGINT", "nullable": true}},
84 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
85 "type": {"type": "DOUBLE", "nullable": true}},
86 {"op": "+", "operands": [{"input": 3}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
87 "type": {"type": "DOUBLE", "nullable": true}}]}]}
89 target = {
'F___index__': [2, 3, 4],
'F_a': [4, 4, 5],
'F_b': [4, 3, 5],
'F_c': [
None, 4, 3]}
90 cursor = engine.executeRA(ra)
91 batch = cursor.getArrowRecordBatch()
92 assert batch.to_pydict() == target
95 ra =
"""execute calcite {"rels": [
96 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
97 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
98 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
99 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
100 {"op": "=", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
101 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
102 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}, {"input": 3}]}]}
104 target = {
'F___index__': [0, 1],
'F_a': [1, 1],
'F_b': [
None,
None],
'F_c': [3,
None]}
105 cursor = engine.executeRA(ra)
106 batch = cursor.getArrowRecordBatch()
107 assert batch.to_pydict() == target
110 ra =
"""execute calcite {"rels": [
111 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
112 {"id": "1", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
113 {"id": "2", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]},
114 {"id": "3", "relOp": "LogicalAggregate", "fields": ["F_a", "F_b", "F_c"], "group": [0], "aggs": [
115 {"agg": "SUM", "operands": [1], "distinct": false, "type": {"type": "DOUBLE", "nullable": true}},
116 {"agg": "SUM", "operands": [2], "distinct": false, "type": {"type": "DOUBLE", "nullable": true}}]},
117 {"id": "4", "relOp": "LogicalSort", "collation": [{"field": 0, "direction": "ASCENDING", "nulls": "LAST"}]},
118 {"id": "5", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
119 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
120 {"op": ">", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
121 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
122 {"id": "6", "relOp": "LogicalProject", "fields": ["F_a", "F_b", "F_c"], "exprs": [{"input": 0}, {"input": 1}, {"input": 2}]}]}
124 target = {
'F_a': [2, 3],
'$f1': [3, 3],
'$f2': [2, 1]}
125 cursor = engine.executeRA(ra)
126 batch = cursor.getArrowRecordBatch()
127 assert batch.to_pydict() == target
130 ra =
"""execute calcite {"rels": [
131 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
132 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
133 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"op": "+", "operands": [{"input": 1},
134 {"op": "+", "operands": [{"input": 2}, {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
135 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}},
136 {"literal": false, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
137 {"op": ">", "operands": [{"op": "+", "operands": [{"input": 1}, {"op": "+", "operands": [{"input": 2},
138 {"literal": 2, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
139 "type": {"type": "DOUBLE", "nullable": true}}], "type": {"type": "DOUBLE", "nullable": true}},
140 {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
141 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
142 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 0},
143 {"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}},
144 {"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}},
145 {"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 target = {
'F___index__': [2, 3, 4],
'F_a': [4, 4, 5],
'F_b': [4, 3, 5],
'F_c': [
None, 4, 3]}
148 cursor = engine.executeRA(ra)
149 batch = cursor.getArrowRecordBatch()
150 assert batch.to_pydict() == target
153 ra =
"""execute calcite {"rels": [
154 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
155 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
156 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
157 {"literal": true, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
158 {"op": "<>", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
159 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
160 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b"],
161 "exprs": [{"input": 0}, {"op": "*", "operands": [{"input": 1}, {"input": 2}], "type": {"type": "DOUBLE", "nullable": true}}, {"input": 2}]}]}
163 target = {
'F___index__': [2, 3, 4],
'F_a': [4, 2, 9],
'F_b': [2, 1, 3]}
164 cursor = engine.executeRA(ra)
165 batch = cursor.getArrowRecordBatch()
166 assert batch.to_pydict() == target
169 ra =
"""execute calcite {"rels": [
170 {"id": "0", "relOp": "EnumerableTableScan", "table": ["omnisci", "test"], "fieldNames": ["F_a", "F_b", "F_c", "rowid"], "inputs": []},
171 {"id": "1", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b", "F_c"], "exprs": [{"input": 3}, {"input": 0}, {"input": 1}, {"input": 2}]},
172 {"id": "2", "relOp": "LogicalFilter", "condition": {"op": "CASE", "operands": [{"op": "IS NULL", "operands": [{"input": 1}], "type": {"type": "BOOLEAN", "nullable": true}},
173 {"literal": true, "type": "BOOLEAN", "target_type": "BOOLEAN", "scale": -2147483648, "precision": 1, "type_scale": -2147483648, "type_precision": 1},
174 {"op": "<>", "operands": [{"input": 1}, {"literal": 1, "type": "DECIMAL", "target_type": "BIGINT", "scale": 0, "precision": 1, "type_scale": 0, "type_precision": 19}],
175 "type": {"type": "BOOLEAN", "nullable": true}}], "type": {"type": "BOOLEAN", "nullable": true}}},
176 {"id": "3", "relOp": "LogicalProject", "fields": ["F___index__", "F_a", "F_b"], "exprs": [{"input": 0},
177 {"op": "*", "operands": [{"input": 1}, {"input": 2}], "type": {"type": "DOUBLE", "nullable": true}}, {"input": 2}]}]}
179 target = {
'F___index__': [2, 3, 4],
'F_a': [4, 2, 9],
'F_b': [2, 1, 3]}
180 cursor = engine.executeRA(ra)
181 batch = cursor.getArrowRecordBatch()
182 assert batch.to_pydict() == target
184 if __name__ ==
"__main__":
185 pytest.main([
"-v", __file__])
def test_filter_with_index