-
-
Save kokosing/7ec809a63441bdb4a49505b82e8aa085 to your computer and use it in GitHub Desktop.
Abstract expression rewrite rule set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanOptimizers.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanOptimizers.java | |
index 37e31f3..65bd8ef 100644 | |
--- a/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanOptimizers.java | |
+++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanOptimizers.java | |
@@ -163,7 +163,10 @@ public class PlanOptimizers | |
new PushProjectionThroughExchange())); | |
builder.add( | |
- new DesugaringOptimizer(metadata, sqlParser), // Clean up all the sugar in expressions, e.g. AtTimeZone, must be run before all the other optimizers | |
+ new IterativeOptimizer( | |
+ stats, | |
+ ImmutableList.of(new DesugaringOptimizer(metadata, sqlParser)), // Clean up all the sugar in expressions, e.g. AtTimeZone, must be run before all the other optimizers | |
+ ImmutableSet.copyOf(new DesugSthRuleSet().getRules())), | |
new IterativeOptimizer( | |
stats, | |
ImmutableList.of(new CanonicalizeExpressions()), | |
diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/RuleSet.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/RuleSet.java | |
index 7f3c78f..521e2ed 100644 | |
--- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/RuleSet.java | |
+++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/RuleSet.java | |
@@ -1,8 +1,22 @@ | |
+/* | |
+ * Licensed 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. | |
+ */ | |
+ | |
package com.facebook.presto.sql.planner.iterative; | |
-/** | |
- * Created by cox on 12.07.17. | |
- */ | |
-public class RuleSet | |
+import java.util.Set; | |
+ | |
+public interface RuleSet | |
{ | |
+ Set<Rule> getRules(); | |
} | |
diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/AbstractExpressionRewriteRuleSet.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/AbstractExpressionRewriteRuleSet.java | |
index a09eecb..0b17ac8 100644 | |
--- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/AbstractExpressionRewriteRuleSet.java | |
+++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/AbstractExpressionRewriteRuleSet.java | |
@@ -12,10 +12,30 @@ | |
* limitations under the License. | |
*/ | |
-package com.facebook.presto.sql.planner.iterative; | |
+/* | |
+ * Licensed 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. | |
+ */ | |
+package com.facebook.presto.sql.planner.iterative.rule; | |
+ | |
+import com.facebook.presto.sql.planner.iterative.Rule; | |
+import com.facebook.presto.sql.planner.iterative.RuleSet; | |
+import com.facebook.presto.sql.planner.plan.PlanNode; | |
import com.facebook.presto.sql.tree.Expression; | |
+import com.google.common.collect.ImmutableSet; | |
+import java.util.Optional; | |
+import java.util.Set; | |
import java.util.function.Function; | |
public class AbstractExpressionRewriteRuleSet implements RuleSet | |
@@ -27,8 +47,22 @@ public class AbstractExpressionRewriteRuleSet implements RuleSet | |
this.rewrite = rewrite; | |
} | |
- private static final class ProjectExpressionRewriteRule implements Rule | |
+ @Override | |
+ public Set<Rule> getRules() | |
+ { | |
+ return ImmutableSet.of( | |
+ new ProjectExpressionRewriteRule() | |
+ // TODO add more | |
+ ); | |
+ } | |
+ | |
+ private final class ProjectExpressionRewriteRule implements Rule | |
{ | |
+ @Override | |
+ public Optional<PlanNode> apply(PlanNode node, Context context) | |
+ { | |
+ return ...; | |
+ } | |
} | |
} | |
diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/DesugarSthRuleSet.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/DesugarSthRuleSet.java | |
index 3e4ec2e..f6edd10 100644 | |
--- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/DesugarSthRuleSet.java | |
+++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/DesugarSthRuleSet.java | |
@@ -1,8 +1,27 @@ | |
+/* | |
+ * Licensed 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. | |
+ */ | |
+ | |
package com.facebook.presto.sql.planner.iterative.rule; | |
-/** | |
- * Created by cox on 12.07.17. | |
- */ | |
-public class DesugarSthRuleSet | |
+import com.facebook.presto.sql.tree.Expression; | |
+ | |
+import java.util.function.Function; | |
+ | |
+public class DesugarSthRuleSet extends AbstractExpressionRewriteRuleSet | |
{ | |
+ public DesugarSthRuleSet(Function<Expression, Expression> rewrite) | |
+ { | |
+ super(this::desugar); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment