Skip to content

Commit b12b2ab

Browse files
authored
feat: add plan builders (#73)
- add plan builders for read, project, filter, etc - add simple builders for types
1 parent 4aae404 commit b12b2ab

File tree

14 files changed

+1019
-1
lines changed

14 files changed

+1019
-1
lines changed

examples/builder_example.py

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
from substrait.builders.plan import read_named_table, project, filter
2+
from substrait.builders.extended_expression import column, scalar_function, literal
3+
from substrait.builders.type import i64, boolean, struct, named_struct
4+
from substrait.extension_registry import ExtensionRegistry
5+
6+
registry = ExtensionRegistry(load_default_extensions=True)
7+
8+
ns = named_struct(
9+
names=["id", "is_applicable"],
10+
struct=struct(
11+
types=[
12+
i64(nullable=False),
13+
boolean()
14+
]
15+
)
16+
)
17+
18+
table = read_named_table('example_table', ns)
19+
table = filter(table, expression=column('is_applicable'))
20+
table = filter(table, expression=scalar_function('functions_comparison.yaml', 'lt', column('id'), literal(100, i64())))
21+
table = project(table, expressions=[column('id')])
22+
23+
print(table(registry))
24+
25+
"""
26+
extension_uris {
27+
extension_uri_anchor: 13
28+
uri: "functions_comparison.yaml"
29+
}
30+
extensions {
31+
extension_function {
32+
extension_uri_reference: 13
33+
function_anchor: 495
34+
name: "lt"
35+
}
36+
}
37+
relations {
38+
root {
39+
input {
40+
project {
41+
common {
42+
emit {
43+
output_mapping: 2
44+
}
45+
}
46+
input {
47+
filter {
48+
input {
49+
filter {
50+
input {
51+
read {
52+
common {
53+
direct {
54+
}
55+
}
56+
base_schema {
57+
names: "id"
58+
names: "is_applicable"
59+
struct {
60+
types {
61+
i64 {
62+
nullability: NULLABILITY_REQUIRED
63+
}
64+
}
65+
types {
66+
bool {
67+
nullability: NULLABILITY_NULLABLE
68+
}
69+
}
70+
nullability: NULLABILITY_NULLABLE
71+
}
72+
}
73+
named_table {
74+
names: "example_table"
75+
}
76+
}
77+
}
78+
condition {
79+
selection {
80+
direct_reference {
81+
struct_field {
82+
field: 1
83+
}
84+
}
85+
root_reference {
86+
}
87+
}
88+
}
89+
}
90+
}
91+
condition {
92+
scalar_function {
93+
function_reference: 495
94+
output_type {
95+
bool {
96+
nullability: NULLABILITY_NULLABLE
97+
}
98+
}
99+
arguments {
100+
value {
101+
selection {
102+
direct_reference {
103+
struct_field {
104+
}
105+
}
106+
root_reference {
107+
}
108+
}
109+
}
110+
}
111+
arguments {
112+
value {
113+
literal {
114+
i64: 100
115+
nullable: true
116+
}
117+
}
118+
}
119+
}
120+
}
121+
}
122+
}
123+
expressions {
124+
selection {
125+
direct_reference {
126+
struct_field {
127+
}
128+
}
129+
root_reference {
130+
}
131+
}
132+
}
133+
}
134+
}
135+
names: "id"
136+
}
137+
}
138+
"""

0 commit comments

Comments
 (0)