Added comments and reverted a previous change.
Project: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/commit/3239dc3e Tree: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/tree/3239dc3e Diff: http://git-wip-us.apache.org/repos/asf/incubator-vxquery/diff/3239dc3e Branch: refs/heads/prestonc/hash_join Commit: 3239dc3e4717be35d1188a4ae9bfe86e8061e39c Parents: 0aa0e7c Author: Preston Carman <[email protected]> Authored: Mon Mar 17 23:22:45 2014 -0700 Committer: Preston Carman <[email protected]> Committed: Mon Mar 17 23:22:45 2014 -0700 ---------------------------------------------------------------------- .../ConvertFromAlgebricksExpressionsRule.java | 27 +++++++++++++++++++- .../ConvertToAlgebricksExpressionsRule.java | 23 +++++++++++++++++ .../rewriter/rules/util/ExpressionToolbox.java | 16 +++++------- 3 files changed, 55 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/3239dc3e/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertFromAlgebricksExpressionsRule.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertFromAlgebricksExpressionsRule.java b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertFromAlgebricksExpressionsRule.java index 482f05d..1bc2bd6 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertFromAlgebricksExpressionsRule.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertFromAlgebricksExpressionsRule.java @@ -39,6 +39,29 @@ import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; import edu.uci.ics.hyracks.algebricks.core.algebra.functions.IFunctionInfo; import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule; +/** + * The rule searches for where the Algebricks builtin function are temporarly in the plan in place of XQuery function. + * The combination the Algebricks builtin function are replace with boolean XQuery function and the XQuery equivalent + * function. + * + * <pre> + * Before + * + * plan__parent + * %OPERATOR( $v1 : algebricks_function( \@input_expression ) ) + * plan__child + * + * Where xquery_function creates an atomic value. + * + * After + * + * plan__parent + * %OPERATOR( $v1 : boolean(xquery_function( \@input_expression ) ) ) + * plan__child + * </pre> + * + * @author prestonc + */ public class ConvertFromAlgebricksExpressionsRule implements IAlgebraicRewriteRule { final List<Mutable<ILogicalExpression>> functionList = new ArrayList<Mutable<ILogicalExpression>>(); @@ -74,6 +97,7 @@ public class ConvertFromAlgebricksExpressionsRule implements IAlgebraicRewriteRu return modified; } + @SuppressWarnings("unchecked") private boolean processExpression(Mutable<ILogicalOperator> opRef, Mutable<ILogicalExpression> search) { boolean modified = false; for (FunctionIdentifier fid : ALGEBRICKS_MAP.keySet()) { @@ -83,7 +107,8 @@ public class ConvertFromAlgebricksExpressionsRule implements IAlgebraicRewriteRu AbstractFunctionCallExpression searchFunction = (AbstractFunctionCallExpression) searchM.getValue(); searchFunction.setFunctionInfo(ALGEBRICKS_MAP.get(fid)); // Add boolean function before vxquery expression. - ScalarFunctionCallExpression booleanExp = new ScalarFunctionCallExpression(BuiltinFunctions.FN_BOOLEAN_1, new MutableObject<ILogicalExpression>(searchM.getValue())); + ScalarFunctionCallExpression booleanExp = new ScalarFunctionCallExpression( + BuiltinFunctions.FN_BOOLEAN_1, new MutableObject<ILogicalExpression>(searchM.getValue())); searchM.setValue(booleanExp); modified = true; } http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/3239dc3e/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertToAlgebricksExpressionsRule.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertToAlgebricksExpressionsRule.java b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertToAlgebricksExpressionsRule.java index ebe265e..943d630 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertToAlgebricksExpressionsRule.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ConvertToAlgebricksExpressionsRule.java @@ -38,6 +38,29 @@ import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; import edu.uci.ics.hyracks.algebricks.core.algebra.functions.IFunctionInfo; import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule; +/** + * The rule searches for where the XQuery function are used in place of Algebricks builtin function. + * The combination the boolean XQuery function and the XQuery equivalent function are replace with + * the Algebricks builtin function . + * + * <pre> + * Before + * + * plan__parent + * %OPERATOR( $v1 : boolean(xquery_function( \@input_expression ) ) ) + * plan__child + * + * Where xquery_function creates an atomic value. + * + * After + * + * plan__parent + * %OPERATOR( $v1 : algebricks_function( \@input_expression ) ) + * plan__child + * </pre> + * + * @author prestonc + */ public class ConvertToAlgebricksExpressionsRule implements IAlgebraicRewriteRule { final List<Mutable<ILogicalExpression>> functionList = new ArrayList<Mutable<ILogicalExpression>>(); http://git-wip-us.apache.org/repos/asf/incubator-vxquery/blob/3239dc3e/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/ExpressionToolbox.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/ExpressionToolbox.java b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/ExpressionToolbox.java index d674f76..34efdd8 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/ExpressionToolbox.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/util/ExpressionToolbox.java @@ -18,12 +18,9 @@ package org.apache.vxquery.compiler.rewriter.rules.util; import java.util.List; -import javax.xml.namespace.QName; - import org.apache.commons.lang3.mutable.Mutable; import org.apache.vxquery.compiler.algebricks.VXQueryConstantValue; import org.apache.vxquery.context.StaticContext; -import org.apache.vxquery.context.StaticContextImpl; import org.apache.vxquery.datamodel.accessors.TaggedValuePointable; import org.apache.vxquery.functions.BuiltinFunctions; import org.apache.vxquery.functions.BuiltinOperators; @@ -148,15 +145,14 @@ public class ExpressionToolbox { } } - public static Function getBuiltIn(Mutable<ILogicalExpression> mutableLe, StaticContext rootContext) { + public static Function getBuiltIn(Mutable<ILogicalExpression> mutableLe) { ILogicalExpression le = mutableLe.getValue(); if (le.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression afce = (AbstractFunctionCallExpression) le; - FunctionIdentifier fid = afce.getFunctionIdentifier(); - QName functionName = new QName(fid.getNamespace(), fid.getName()); - Function found = rootContext.lookupFunction(functionName, fid.getArity()); - if (found != null) { - return found; + for (Function function : BuiltinFunctions.FUNCTION_COLLECTION) { + if (function.getFunctionIdentifier().equals(afce.getFunctionIdentifier())) { + return function; + } } for (Function function : BuiltinOperators.OPERATOR_COLLECTION) { if (function.getFunctionIdentifier().equals(afce.getFunctionIdentifier())) { @@ -202,7 +198,7 @@ public class ExpressionToolbox { switch (argFirstLe.getExpressionTag()) { case FUNCTION_CALL: // Only process defined functions. - Function function = ExpressionToolbox.getBuiltIn(argFirstM, dCtx); + Function function = ExpressionToolbox.getBuiltIn(argFirstM); if (function == null) { return null; } else if (function.getFunctionIdentifier().equals(BuiltinOperators.CAST.getFunctionIdentifier())) {
