This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
CalciteJoinTests.java
61 lines (47 loc) · 1.96 KB
/
CalciteJoinTests.java
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package net.sansa_stack.query.flink.playground;
import org.apache.calcite.adapter.java.ReflectiveSchema;
import org.apache.calcite.plan.RelOptUtil;
import org.apache.calcite.rel.RelNode;
import org.apache.calcite.rel.RelRoot;
import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.parser.SqlParser;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.Frameworks;
import org.apache.calcite.tools.Planner;
import org.junit.Test;
public class CalciteJoinTests {
public static class Triple {
public String s;
public String p;
public String o;
public Triple(String s, String p, String o) {
super();
this.s = s;
this.p = p;
this.o = o;
}
}
public static class TestSchema {
public final Triple[] rdf = {new Triple("s", "p", "o")};
}
@Test
public void testCalciteJoin() throws Exception {
SchemaPlus rootSchema = Frameworks.createRootSchema(true);
rootSchema.add("s", new ReflectiveSchema(new TestSchema()));
Frameworks.ConfigBuilder configBuilder = Frameworks.newConfigBuilder();
configBuilder.defaultSchema(rootSchema);
FrameworkConfig frameworkConfig = configBuilder.build();
SqlParser.ConfigBuilder parserConfig = SqlParser.configBuilder(frameworkConfig.getParserConfig());
parserConfig
.setCaseSensitive(false)
.setConfig(parserConfig.build());
Planner planner = Frameworks.getPlanner(frameworkConfig);
// SELECT s.rdf a, s.rdf b WHERE a.s = 5 AND b.s = 5
SqlNode sqlNode = planner.parse("SELECT * FROM \"s\".\"rdf\" \"a\", \"s\".\"rdf\" \"b\" WHERE \"a\".\"s\" = 5 AND \"b\".\"s\" = 5");
planner.validate(sqlNode);
RelRoot relRoot = planner.rel(sqlNode);
RelNode relNode = relRoot.project();
System.out.println(RelOptUtil.toString(relNode));
}
}