You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to you under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */packageorg.apache.wayang.api.sql.calcite.rules;
importorg.apache.calcite.adapter.enumerable.EnumerableConvention;
importorg.apache.calcite.plan.Convention;
importorg.apache.calcite.plan.RelOptRule;
importorg.apache.calcite.plan.RelOptTable;
importorg.apache.calcite.rel.RelNode;
importorg.apache.calcite.rel.convert.ConverterRule;
importorg.apache.calcite.rel.core.TableScan;
importorg.apache.calcite.rel.logical.LogicalFilter;
importorg.apache.calcite.rel.logical.LogicalJoin;
importorg.apache.calcite.rel.logical.LogicalProject;
importorg.apache.calcite.rel.logical.LogicalTableScan;
importorg.apache.wayang.api.sql.calcite.convention.WayangConvention;
importorg.apache.wayang.api.sql.calcite.rel.WayangFilter;
importorg.apache.wayang.api.sql.calcite.rel.WayangJoin;
importorg.apache.wayang.api.sql.calcite.rel.WayangProject;
importorg.apache.wayang.api.sql.calcite.rel.WayangTableScan;
importorg.checkerframework.checker.nullness.qual.Nullable;
importjava.util.ArrayList;
importjava.util.List;
//TODO: split into multiple classespublicclassWayangRules {
privateWayangRules(){
}
publicstaticfinalRelOptRuleWAYANG_JOIN_RULE = newWayangJoinRule(WayangJoinRule.DEFAULT_CONFIG);
publicstaticfinalRelOptRuleWAYANG_PROJECT_RULE = newWayangProjectRule(WayangProjectRule.DEFAULT_CONFIG);
publicstaticfinalRelOptRuleWAYANG_FILTER_RULE = newWayangFilterRule(WayangFilterRule.DEFAULT_CONFIG);
publicstaticfinalRelOptRuleWAYANG_TABLESCAN_RULE = newWayangTableScanRule(WayangTableScanRule.DEFAULT_CONFIG);
publicstaticfinalRelOptRuleWAYANG_TABLESCAN_ENUMERABLE_RULE =
newWayangTableScanRule(WayangTableScanRule.ENUMERABLE_CONFIG);
privatestaticclassWayangProjectRuleextendsConverterRule {
publicstaticfinalConfigDEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalProject.class,
Convention.NONE, WayangConvention.INSTANCE,
"WayangProjectRule")
.withRuleFactory(WayangProjectRule::new);
protectedWayangProjectRule(Configconfig) {
super(config);
}
publicRelNodeconvert(RelNoderel) {
finalLogicalProjectproject = (LogicalProject) rel;
returnnewWayangProject(
project.getCluster(),
project.getTraitSet().replace(WayangConvention.INSTANCE),
convert(project.getInput(), project.getInput().getTraitSet()
.replace(WayangConvention.INSTANCE)),
project.getProjects(),
project.getRowType());
}
}
privatestaticclassWayangFilterRuleextendsConverterRule {
publicstaticfinalConfigDEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalFilter.class,
Convention.NONE, WayangConvention.INSTANCE,
"WayangFilterRule")
.withRuleFactory(WayangFilterRule::new);
protectedWayangFilterRule(Configconfig) {
super(config);
}
@OverridepublicRelNodeconvert(RelNoderel) {
finalLogicalFilterfilter = (LogicalFilter) rel;
returnnewWayangFilter(
rel.getCluster(),
rel.getTraitSet().replace(WayangConvention.INSTANCE),
convert(filter.getInput(), filter.getInput().getTraitSet().
replace(WayangConvention.INSTANCE)),
filter.getCondition());
}
}
privatestaticclassWayangTableScanRuleextendsConverterRule {
publicstaticfinalConfigDEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalTableScan.class,
Convention.NONE, WayangConvention.INSTANCE,
"WayangTableScanRule")
.withRuleFactory(WayangTableScanRule::new);
publicstaticfinalConfigENUMERABLE_CONFIG = Config.INSTANCE
.withConversion(TableScan.class,
EnumerableConvention.INSTANCE, WayangConvention.INSTANCE,
"WayangTableScanRule1")
.withRuleFactory(WayangTableScanRule::new);
protectedWayangTableScanRule(Configconfig) {
super(config);
}
@Overridepublic@NullableRelNodeconvert(RelNoderelNode) {
TableScanscan = (TableScan) relNode;
finalRelOptTablerelOptTable = scan.getTable();
/** * This is quick hack to prevent volcano from merging projects on to TableScans * TODO: a cleaner way to handle this */if(relOptTable.getRowType() == scan.getRowType()) {
returnWayangTableScan.create(scan.getCluster(), relOptTable);
}
returnnull;
}
}
privatestaticclassWayangJoinRuleextendsConverterRule {
publicstaticfinalConfigDEFAULT_CONFIG = Config.INSTANCE
.withConversion(LogicalJoin.class, Convention.NONE,
WayangConvention.INSTANCE, "WayangJoinRule")
.withRuleFactory(WayangJoinRule::new);
protectedWayangJoinRule(Configconfig) {
super(config);
}
@Overridepublic@NullableRelNodeconvert(RelNoderelNode) {
LogicalJoinjoin = (LogicalJoin) relNode;
List<RelNode> newInputs = newArrayList<>();
for(RelNodeinput : join.getInputs()) {
if(!(input.getConvention() instanceofWayangConvention)) {
input = convert(input, input.getTraitSet().replace(WayangConvention.INSTANCE));
}
newInputs.add(input);
}
returnnewWayangJoin(
join.getCluster(),
join.getTraitSet().replace(WayangConvention.INSTANCE),
newInputs.get(0),
newInputs.get(1),
join.getCondition(),
join.getVariablesSet(),
join.getJoinType()
);
}
}
}
6499c73ac9cff2e0a2343561de8915eebfacfe34
The text was updated successfully, but these errors were encountered:
split into multiple classes
https://github.com/databloom-ai/incubator-wayang/blob/c51b95e414816ed2b6ac7f8f3cad5857b40fea3b/wayang-api/wayang-api-sql/src/main/java/org/apache/wayang/api/sql/calcite/rules/WayangRules.java#L41
6499c73ac9cff2e0a2343561de8915eebfacfe34
The text was updated successfully, but these errors were encountered: