Skip to content

Commit c2bb03c

Browse files
authored
Merge pull request #671 from mspruc/restructure-rules
move rules to their own classes
2 parents bdf5bd9 + 3aeb1e1 commit c2bb03c

File tree

6 files changed

+298
-172
lines changed

6 files changed

+298
-172
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.wayang.api.sql.calcite.rules;
19+
20+
import org.apache.calcite.plan.Convention;
21+
import org.apache.calcite.rel.RelNode;
22+
import org.apache.calcite.rel.convert.ConverterRule;
23+
import org.apache.calcite.rel.logical.LogicalAggregate;
24+
25+
import org.apache.wayang.api.sql.calcite.convention.WayangConvention;
26+
import org.apache.wayang.api.sql.calcite.rel.WayangAggregate;
27+
28+
/**
29+
* Rule that converts {@link LogicalAggregate} to Wayang convention
30+
* {@link WayangAggregate}
31+
*/
32+
public class WayangAggregateRule extends ConverterRule {
33+
34+
public static final Config DEFAULT_CONFIG = Config.INSTANCE
35+
.withConversion(LogicalAggregate.class,
36+
Convention.NONE, WayangConvention.INSTANCE,
37+
"WayangAggregateRule")
38+
.withRuleFactory(WayangAggregateRule::new);
39+
40+
protected WayangAggregateRule(final Config config) {
41+
super(config);
42+
}
43+
44+
@Override
45+
public RelNode convert(final RelNode relNode) {
46+
final LogicalAggregate aggregate = (LogicalAggregate) relNode;
47+
final RelNode input = convert(aggregate.getInput(),
48+
aggregate.getInput().getTraitSet().replace(WayangConvention.INSTANCE));
49+
50+
return new WayangAggregate(
51+
aggregate.getCluster(),
52+
aggregate.getTraitSet().replace(WayangConvention.INSTANCE),
53+
aggregate.getHints(),
54+
input,
55+
aggregate.getGroupSet(),
56+
aggregate.getGroupSets(),
57+
aggregate.getAggCallList());
58+
}
59+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.wayang.api.sql.calcite.rules;
19+
20+
import org.apache.calcite.plan.Convention;
21+
import org.apache.calcite.rel.RelNode;
22+
import org.apache.calcite.rel.convert.ConverterRule;
23+
import org.apache.calcite.rel.logical.LogicalFilter;
24+
25+
import org.apache.wayang.api.sql.calcite.convention.WayangConvention;
26+
import org.apache.wayang.api.sql.calcite.rel.WayangFilter;
27+
28+
/**
29+
* Rule that converts {@link LogicalFilter} to Wayang convention
30+
* {@link WayangFilter}
31+
*/
32+
public class WayangFilterRule extends ConverterRule {
33+
public static final Config DEFAULT_CONFIG = Config.INSTANCE
34+
.withConversion(LogicalFilter.class,
35+
Convention.NONE, WayangConvention.INSTANCE,
36+
"WayangFilterRule")
37+
.withRuleFactory(WayangFilterRule::new);
38+
39+
protected WayangFilterRule(final Config config) {
40+
super(config);
41+
}
42+
43+
@Override
44+
public RelNode convert(final RelNode rel) {
45+
final LogicalFilter filter = (LogicalFilter) rel;
46+
return new WayangFilter(
47+
rel.getCluster(),
48+
rel.getTraitSet().replace(WayangConvention.INSTANCE),
49+
convert(filter.getInput(), filter.getInput().getTraitSet().replace(WayangConvention.INSTANCE)),
50+
filter.getCondition());
51+
}
52+
53+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.wayang.api.sql.calcite.rules;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
import org.apache.calcite.plan.Convention;
24+
import org.apache.calcite.rel.RelNode;
25+
import org.apache.calcite.rel.convert.ConverterRule;
26+
import org.apache.calcite.rel.logical.LogicalJoin;
27+
28+
import org.apache.wayang.api.sql.calcite.convention.WayangConvention;
29+
import org.apache.wayang.api.sql.calcite.rel.WayangJoin;
30+
31+
32+
/**
33+
* Rule that converts {@link LogicalJoin} to Wayang convention
34+
* {@link WayangJoin}
35+
*/
36+
public class WayangJoinRule extends ConverterRule {
37+
38+
public static final Config DEFAULT_CONFIG = Config.INSTANCE
39+
.withConversion(LogicalJoin.class, Convention.NONE,
40+
WayangConvention.INSTANCE, "WayangJoinRule")
41+
.withRuleFactory(WayangJoinRule::new);
42+
43+
protected WayangJoinRule(final Config config) {
44+
super(config);
45+
}
46+
47+
@Override
48+
public RelNode convert(final RelNode relNode) {
49+
final LogicalJoin join = (LogicalJoin) relNode;
50+
final List<RelNode> newInputs = new ArrayList<>();
51+
for (final RelNode input : join.getInputs()) {
52+
final RelNode convertedNode = !(input.getConvention() instanceof WayangConvention)
53+
? convert(input, input.getTraitSet().replace(WayangConvention.INSTANCE))
54+
: input;
55+
56+
newInputs.add(convertedNode);
57+
}
58+
59+
return new WayangJoin(
60+
join.getCluster(),
61+
join.getTraitSet().replace(WayangConvention.INSTANCE),
62+
newInputs.get(0),
63+
newInputs.get(1),
64+
join.getCondition(),
65+
join.getVariablesSet(),
66+
join.getJoinType());
67+
}
68+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.wayang.api.sql.calcite.rules;
19+
20+
import org.apache.calcite.plan.Convention;
21+
import org.apache.calcite.rel.RelNode;
22+
import org.apache.calcite.rel.convert.ConverterRule;
23+
import org.apache.calcite.rel.logical.LogicalProject;
24+
25+
import org.apache.wayang.api.sql.calcite.convention.WayangConvention;
26+
import org.apache.wayang.api.sql.calcite.rel.WayangProject;
27+
28+
/**
29+
* Rule that converts {@link LogicalProject} to Wayang convention
30+
* {@link WayangProject}
31+
*/
32+
public class WayangProjectRule extends ConverterRule {
33+
public static final Config DEFAULT_CONFIG = Config.INSTANCE
34+
.withConversion(LogicalProject.class,
35+
Convention.NONE, WayangConvention.INSTANCE,
36+
"WayangProjectRule")
37+
.withRuleFactory(WayangProjectRule::new);
38+
39+
protected WayangProjectRule(final Config config) {
40+
super(config);
41+
}
42+
43+
public RelNode convert(final RelNode rel) {
44+
final LogicalProject project = (LogicalProject) rel;
45+
return new WayangProject(
46+
project.getCluster(),
47+
project.getTraitSet().replace(WayangConvention.INSTANCE),
48+
convert(project.getInput(), project.getInput().getTraitSet()
49+
.replace(WayangConvention.INSTANCE)),
50+
project.getProjects(),
51+
project.getRowType());
52+
}
53+
}

0 commit comments

Comments
 (0)