forked from substrait-io/substrait-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cross.py
More file actions
47 lines (38 loc) · 1.48 KB
/
test_cross.py
File metadata and controls
47 lines (38 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import substrait.gen.proto.type_pb2 as stt
import substrait.gen.proto.plan_pb2 as stp
import substrait.gen.proto.algebra_pb2 as stalg
from substrait.builders.type import boolean, i64, string
from substrait.builders.plan import read_named_table, cross, default_version
from substrait.extension_registry import ExtensionRegistry
registry = ExtensionRegistry(load_default_extensions=False)
struct = stt.Type.Struct(
types=[i64(nullable=False), boolean()], nullability=stt.Type.NULLABILITY_REQUIRED
)
named_struct = stt.NamedStruct(names=["id", "is_applicable"], struct=struct)
named_struct_2 = stt.NamedStruct(
names=["fk_id", "name"],
struct=stt.Type.Struct(
types=[i64(nullable=False), string()], nullability=stt.Type.NULLABILITY_REQUIRED
),
)
def test_cross_join():
table = read_named_table("table", named_struct)
table2 = read_named_table("table2", named_struct_2)
actual = cross(table, table2)(registry)
expected = stp.Plan(
version=default_version,
relations=[
stp.PlanRel(
root=stalg.RelRoot(
input=stalg.Rel(
cross=stalg.CrossRel(
left=table(None).relations[-1].root.input,
right=table2(None).relations[-1].root.input,
)
),
names=["id", "is_applicable", "fk_id", "name"],
)
)
],
)
assert actual == expected