Taewoo Kim has uploaded a new change for review. https://asterix-gerrit.ics.uci.edu/1432
Change subject: AQLPlus Refactoring 1: add a new rule controller ...................................................................... AQLPlus Refactoring 1: add a new rule controller - Add a new rule controller that is to be used for FuzzyJoinRuleCollection. If the first rule is not fired in the first iteration, no additional rules in the given collection will be checked. If the first rule is fired, then it behaves like SequentialFixpointRuleController - run rules sequentially until one iteration over all rules produces no change. - This rule controller is added to make sure that fuzzy-join framework does not interfere with non-fuzzy-join queries. Change-Id: I2742e891339e5aba37a00f77d7f18cb3c09bcfe2 --- M hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java A hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java M hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java 3 files changed, 97 insertions(+), 1 deletion(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/32/1432/1 diff --git a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java index 6e53e2a..477efc7 100644 --- a/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java +++ b/hyracks-fullstack/algebricks/algebricks-common/src/main/java/org/apache/hyracks/algebricks/common/exceptions/AlgebricksException.java @@ -20,6 +20,7 @@ import java.io.Serializable; +import org.apache.hyracks.api.exceptions.ErrorCode; import org.apache.hyracks.api.util.ErrorMessageUtil; public class AlgebricksException extends Exception { @@ -41,6 +42,10 @@ this.params = params; } + public static AlgebricksException create(int code, Serializable... params) { + return new AlgebricksException(ErrorCode.HYRACKS, code, ErrorCode.getErrorMessage(code), params); + } + public AlgebricksException(String message) { this(ErrorMessageUtil.NONE, UNKNOWN, message, null, null); } diff --git a/hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java b/hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java new file mode 100644 index 0000000..4dd6b64 --- /dev/null +++ b/hyracks-fullstack/algebricks/algebricks-compiler/src/main/java/org/apache/hyracks/algebricks/compiler/rewriter/rulecontrollers/SequentialFirstRuleCheckFixpointRuleController.java @@ -0,0 +1,90 @@ +/* + * 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. + */ +package org.apache.hyracks.algebricks.compiler.rewriter.rulecontrollers; + +import java.util.Collection; +import java.util.List; + +import org.apache.commons.lang3.mutable.Mutable; +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator; +import org.apache.hyracks.algebricks.core.rewriter.base.AbstractRuleController; +import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule; +import org.apache.hyracks.api.exceptions.ErrorCode; + +/** + * If the first rule in the given collection is fired during the first iteration, it also runs the other rules + * sequentially (round-robin) until one iteration over all rules produces no change. Except the case where the first + * rule in the first iteration fails, all rules will be checked for each iteration. + * An example scenario: + * Suppose there are three rules - R1, R2, and R3. + * During the first iteration, if R1, the first rule, is not fired, then R2 and R3 will not be checked. + * If R1, the first rule, is fired, then R2 and R3 will be checked. Since the first iteration returns at least one true + * (the first rule), there will be an another iteration. In the second iteration, we don't care whether R1 if fired or + * not. This enforcement of 'first rule returns true' check is only executed in the first iteration. + * So, if any of rules among R1, R2, and R3 is fired, then there will be another iteration(s) until + * an iteration doesn't produce any change. + */ +public class SequentialFirstRuleCheckFixpointRuleController extends AbstractRuleController { + + private boolean fullDfs; + + public SequentialFirstRuleCheckFixpointRuleController(boolean fullDfs) { + super(); + this.fullDfs = fullDfs; + } + + @Override + public boolean rewriteWithRuleCollection(Mutable<ILogicalOperator> root, + Collection<IAlgebraicRewriteRule> ruleCollection) throws AlgebricksException { + boolean anyRuleFired; + boolean anyChange; + List<IAlgebraicRewriteRule> rules; + + // This rule controller can only be applied for a list. + if (ruleCollection instanceof List) { + rules = (List<IAlgebraicRewriteRule>) ruleCollection; + } else { + throw AlgebricksException.create(ErrorCode.COMPILATION_RULECOLLECTION_NOT_INSTANCE_OF_LIST, + this.getClass().getName()); + } + + // Checks whether the first rule returns true. + anyRuleFired = rewriteOperatorRef(root, rules.get(0), true, fullDfs); + if (!anyRuleFired) { + return anyRuleFired; + } + // First iteration: goes through the rest of rules. + for (int i = 1; i < rules.size(); i++) { + rewriteOperatorRef(root, rules.get(i), true, fullDfs); + } + + // The second iteration and so on... This continues until there is no single fired rule in one iteration. + do { + anyChange = false; + for (IAlgebraicRewriteRule rule : ruleCollection) { + boolean ruleFired = rewriteOperatorRef(root, rule, true, fullDfs); + if (ruleFired) { + anyChange = true; + } + } + } while (anyChange); + return anyRuleFired; + } +} diff --git a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java index 888f82a..5bdabcc 100644 --- a/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java +++ b/hyracks-fullstack/hyracks/hyracks-api/src/main/java/org/apache/hyracks/api/exceptions/ErrorCode.java @@ -25,7 +25,7 @@ import org.apache.hyracks.api.util.ErrorMessageUtil; /** - * A registry of runtime error codes + * A registry of runtime/compile error codes */ public class ErrorCode { private static final String RESOURCE_PATH = "errormsg" + File.separator + "en.properties"; @@ -36,6 +36,7 @@ public static final int FAILURE_ON_NODE = 3; public static final int RUNTIME_FILE_WITH_ABSOULTE_PATH_NOT_WITHIN_ANY_IO_DEVICE = 4; public static final int RUNTIME_FULLTEXT_PHRASE_FOUND = 5; + public static final int COMPILATION_RULECOLLECTION_NOT_INSTANCE_OF_LIST = 1001; // Loads the map that maps error codes to error message templates. private static Map<Integer, String> errorMessageMap = null; -- To view, visit https://asterix-gerrit.ics.uci.edu/1432 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2742e891339e5aba37a00f77d7f18cb3c09bcfe2 Gerrit-PatchSet: 1 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Taewoo Kim <wangs...@yahoo.com>