Repository: vxquery
Updated Branches:
  refs/heads/master de30584ab -> ee7a56934


Merged Shivani's fixes for doc and algebricks conversions.


Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/ee7a5693
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/ee7a5693
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/ee7a5693

Branch: refs/heads/master
Commit: ee7a56934f8c163ada5f9fc27a150e98e46a752e
Parents: de30584
Author: Preston Carman <[email protected]>
Authored: Tue Jun 30 18:58:00 2015 -0700
Committer: Preston Carman <[email protected]>
Committed: Tue Jun 30 18:58:00 2015 -0700

----------------------------------------------------------------------
 .../ConvertFromAlgebricksExpressionsRule.java   | 61 +++++++++++++-------
 .../ConvertToAlgebricksExpressionsRule.java     | 15 ++---
 .../rules/ReplaceSourceMapInDocExpression.java  |  3 +
 .../rewriter/rules/util/ExpressionToolbox.java  | 16 ++---
 .../vxquery/xtest/AbstractTestCaseFactory.java  |  7 +++
 .../src/test/resources/cat/SingleQuery.xml      | 26 +++++++++
 6 files changed, 94 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/ee7a5693/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 41ceff6..f77b93b 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
@@ -53,13 +53,16 @@ import 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
  *   %OPERATOR( $v1 : algebricks_function( \@input_expression ) )
  *   plan__child
  *   
- *   Where xquery_function creates an atomic value.
+ *   where the function annotation contains a hint on which xquery expression 
is represented by the algebricks function.
  *   
  * After 
  * 
  *   plan__parent
- *   %OPERATOR( $v1 : boolean(xquery_function( \@input_expression ) ) )
+ *   %OPERATOR( $v1 :xquery_expression( \@input_expression ) ) )
  *   plan__child
+ *   
+ *   note the xquery_expression may include the boolean function to ensure 
only a true or false result.
+ * 
  * </pre>
  * 
  * @author prestonc, shivanim
@@ -67,9 +70,11 @@ import 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 public class ConvertFromAlgebricksExpressionsRule implements 
IAlgebraicRewriteRule {
     final List<Mutable<ILogicalExpression>> functionList = new 
ArrayList<Mutable<ILogicalExpression>>();
     final static Map<FunctionIdentifier, Pair<IFunctionInfo, IFunctionInfo>> 
ALGEBRICKS_MAP = new HashMap<FunctionIdentifier, Pair<IFunctionInfo, 
IFunctionInfo>>();
-    final static String CONVERSION_TO_FR_ALGEBRICKS = 
"ConversionToAndFromAlgebrics";
+    final static String ALGEBRICKS_CONVERSION_ANNOTATION = 
"ConversionToAndFromAlgebricks";
     AbstractFunctionCallExpression searchFunction;
+    boolean isBoolean = false;
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
     public ConvertFromAlgebricksExpressionsRule() {
         ALGEBRICKS_MAP.put(AlgebricksBuiltinFunctions.AND, new 
Pair(BuiltinOperators.AND, null));
         ALGEBRICKS_MAP.put(AlgebricksBuiltinFunctions.EQ, new 
Pair(BuiltinOperators.VALUE_EQ,
@@ -107,34 +112,50 @@ public class ConvertFromAlgebricksExpressionsRule 
implements IAlgebraicRewriteRu
         return modified;
     }
 
-    @SuppressWarnings("unchecked")
     private boolean processExpression(Mutable<ILogicalOperator> opRef, 
Mutable<ILogicalExpression> search) {
         boolean modified = false;
         functionList.clear();
         ExpressionToolbox.findAllFunctionExpressions(search, functionList);
         for (Mutable<ILogicalExpression> searchM : functionList) {
             searchFunction = (AbstractFunctionCallExpression) 
searchM.getValue();
+
             if 
(ALGEBRICKS_MAP.containsKey(searchFunction.getFunctionIdentifier())) {
-                ScalarFunctionCallExpression booleanFunctionCallExp = null;
-                IExpressionAnnotation annotate = 
searchFunction.getAnnotations().get(CONVERSION_TO_FR_ALGEBRICKS);
                 FunctionIdentifier fid = 
searchFunction.getFunctionIdentifier();
-                if (((FunctionIdentifier) 
annotate.getObject()).equals(ALGEBRICKS_MAP.get(fid).first
-                        .getFunctionIdentifier())) {
-                    
searchFunction.setFunctionInfo(ALGEBRICKS_MAP.get(fid).first);
-                    booleanFunctionCallExp = new 
ScalarFunctionCallExpression(BuiltinFunctions.FN_BOOLEAN_1,
-                            new 
MutableObject<ILogicalExpression>(searchM.getValue()));
-                    searchM.setValue(booleanFunctionCallExp);
-                    modified = true;
-                } else if (((FunctionIdentifier) 
annotate.getObject()).equals(ALGEBRICKS_MAP.get(fid).second
-                        .getFunctionIdentifier())) {
-                    
searchFunction.setFunctionInfo(ALGEBRICKS_MAP.get(fid).second);
-                    booleanFunctionCallExp = new 
ScalarFunctionCallExpression(ALGEBRICKS_MAP.get(fid).second,
-                            searchFunction.getArguments());
-                    searchM.setValue(booleanFunctionCallExp);
-                    modified = true;
+
+                if (ALGEBRICKS_MAP.get(fid).first == null) {
+                    modified = convertAlgebricksExpression(searchM, 
ALGEBRICKS_MAP.get(fid).second, false);
+                } else if (ALGEBRICKS_MAP.get(fid).second == null) {
+                    modified = convertAlgebricksExpression(searchM, 
ALGEBRICKS_MAP.get(fid).first, true);
+                } else {
+                    IExpressionAnnotation annotate = 
searchFunction.getAnnotations().get(
+                            ALGEBRICKS_CONVERSION_ANNOTATION);
+
+                    if (((FunctionIdentifier) 
annotate.getObject()).equals(ALGEBRICKS_MAP.get(fid).first
+                            .getFunctionIdentifier())) {
+
+                        modified = convertAlgebricksExpression(searchM, 
ALGEBRICKS_MAP.get(fid).first, true);
+                    } else if (((FunctionIdentifier) 
annotate.getObject()).equals(ALGEBRICKS_MAP.get(fid).second
+                            .getFunctionIdentifier())) {
+
+                        modified = convertAlgebricksExpression(searchM, 
ALGEBRICKS_MAP.get(fid).second, false);
+                    }
                 }
             }
         }
         return modified;
     }
+
+    @SuppressWarnings("unchecked")
+    private boolean convertAlgebricksExpression(Mutable<ILogicalExpression> 
searchM, IFunctionInfo funcInfo,
+            boolean isBoolean) {
+        AbstractFunctionCallExpression searchFunction = 
(AbstractFunctionCallExpression) searchM.getValue();
+        searchFunction.setFunctionInfo(funcInfo);
+
+        if (isBoolean) {
+            ScalarFunctionCallExpression functionCallExp = new 
ScalarFunctionCallExpression(
+                    BuiltinFunctions.FN_BOOLEAN_1, new 
MutableObject<ILogicalExpression>(searchM.getValue()));
+            searchM.setValue(functionCallExp);
+        }
+        return true;
+    }
 }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ee7a5693/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 3c36f03..f1747fc 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
@@ -47,11 +47,13 @@ import 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
  * Before
  * 
  *   plan__parent
- *   %OPERATOR( $v1 : xquery_function( \@input_expression ) )
+ *   %OPERATOR( $v1 : xquery_expression( \@input_expression ) )
  *   plan__child
  * 
- *   where xquery_function has a known equivalent in Algebricks, 
- *   such as conditional expressions and a check for null
+ *   where xquery_expression has a known equivalent in Algebricks, 
+ *     such as conditional expressions and a check for null.
+ *     The expression may include the boolean function to ensure only
+ *     a true or false result.
  *   
  * After 
  * 
@@ -65,10 +67,9 @@ import 
edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 public class ConvertToAlgebricksExpressionsRule implements 
IAlgebraicRewriteRule {
     final Map<FunctionIdentifier, FunctionIdentifier> ALGEBRICKS_MAP = new 
HashMap<FunctionIdentifier, FunctionIdentifier>();
     final Map<FunctionIdentifier, FunctionIdentifier> ALGEBRICKS_BOOL_MAP = 
new HashMap<FunctionIdentifier, FunctionIdentifier>();
-    final static String CONVERSION_TO_FR_ALGEBRICKS = 
"ConversionToAndFromAlgebrics";
+    final static String ALGEBRICKS_CONVERSION_ANNOTATION = 
"ConversionToAndFromAlgebricks";
 
     public ConvertToAlgebricksExpressionsRule() {
-
         ALGEBRICKS_BOOL_MAP.put(BuiltinOperators.AND.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.AND);
         ALGEBRICKS_BOOL_MAP.put(BuiltinOperators.OR.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.OR);
         
ALGEBRICKS_BOOL_MAP.put(BuiltinOperators.VALUE_EQ.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.EQ);
@@ -77,7 +78,7 @@ public class ConvertToAlgebricksExpressionsRule implements 
IAlgebraicRewriteRule
         
ALGEBRICKS_BOOL_MAP.put(BuiltinOperators.VALUE_LE.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.LE);
         
ALGEBRICKS_BOOL_MAP.put(BuiltinOperators.VALUE_LT.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.LT);
         
ALGEBRICKS_BOOL_MAP.put(BuiltinOperators.VALUE_NE.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.NEQ);
-        
+
         
ALGEBRICKS_MAP.put(BuiltinFunctions.FN_EMPTY_1.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.IS_NULL);
         ALGEBRICKS_MAP.put(BuiltinFunctions.FN_NOT_1.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.NOT);
         
ALGEBRICKS_MAP.put(BuiltinOperators.GENERAL_EQ.getFunctionIdentifier(), 
AlgebricksBuiltinFunctions.EQ);
@@ -120,7 +121,7 @@ public class ConvertToAlgebricksExpressionsRule implements 
IAlgebraicRewriteRule
             FunctionIdentifier algebricksFid = 
map.get(functionCall.getFunctionIdentifier());
             IFunctionInfo algebricksFunction = 
context.getMetadataProvider().lookupFunction(algebricksFid);
             functionCall.setFunctionInfo(algebricksFunction);
-            functionCall.getAnnotations().put(CONVERSION_TO_FR_ALGEBRICKS, 
annotate);
+            
functionCall.getAnnotations().put(ALGEBRICKS_CONVERSION_ANNOTATION, annotate);
             searchM.setValue(functionCall);
             return true;
         }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ee7a5693/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ReplaceSourceMapInDocExpression.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ReplaceSourceMapInDocExpression.java
 
b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ReplaceSourceMapInDocExpression.java
index 29e0def..ba6c2c0 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ReplaceSourceMapInDocExpression.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/ReplaceSourceMapInDocExpression.java
@@ -144,6 +144,9 @@ public class ReplaceSourceMapInDocExpression implements 
IAlgebraicRewriteRule {
         docArg = toStr.toString();
 
         VXQueryMetadataProvider mdp = (VXQueryMetadataProvider) 
context.getMetadataProvider();
+        if (mdp.getSourceFileMap() == null) {
+            return false;
+        }
         if (!mdp.getSourceFileMap().containsKey(docArg)) {
             return false;
         }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ee7a5693/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 9374cc3..7e916d7 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
@@ -37,8 +37,8 @@ import 
edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionC
 import 
edu.uci.ics.hyracks.algebricks.core.algebra.expressions.ConstantExpression;
 import 
edu.uci.ics.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression;
 import 
edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import 
edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractAssignOperator;
 import 
edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator;
-import 
edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
 import 
edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
 import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
 
@@ -237,19 +237,21 @@ public class ExpressionToolbox {
                 }
                 AbstractLogicalOperator variableOp = (AbstractLogicalOperator) 
variableProducer.getValue();
                 switch (variableOp.getOperatorTag()) {
-                    case DATASOURCESCAN:
-                        return SequenceType.create(AnyNodeType.INSTANCE, 
Quantifier.QUANT_ONE);
-                    case UNNEST:
-                        UnnestOperator unnest = (UnnestOperator) variableOp;
-                        return getOutputSequenceType(variableProducer, 
unnest.getExpressionRef(), dCtx);
                     case ASSIGN:
-                        AssignOperator assign = (AssignOperator) variableOp;
+                    case AGGREGATE:
+                    case RUNNINGAGGREGATE:
+                        AbstractAssignOperator assign = 
(AbstractAssignOperator) variableOp;
                         for (int i = 0; i < assign.getVariables().size(); ++i) 
{
                             if 
(variableId.equals(assign.getVariables().get(i))) {
                                 return getOutputSequenceType(variableProducer, 
assign.getExpressions().get(i), dCtx);
                             }
                         }
                         return null;
+                    case DATASOURCESCAN:
+                        return SequenceType.create(AnyNodeType.INSTANCE, 
Quantifier.QUANT_ONE);
+                    case UNNEST:
+                        UnnestOperator unnest = (UnnestOperator) variableOp;
+                        return getOutputSequenceType(variableProducer, 
unnest.getExpressionRef(), dCtx);
                     default:
                         // TODO Consider support for other operators. i.e. 
Assign.
                         break;

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ee7a5693/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
 
b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
index 5bcfd6b..dea6b8d 100644
--- 
a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
+++ 
b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
@@ -121,8 +121,15 @@ public abstract class AbstractTestCaseFactory {
             FileReader characterStream = new FileReader(catalog);
             parser.parse(new InputSource(characterStream));
             characterStream.close();
+        } catch (SAXException e) {
+            System.err.println("Unable to parse file: " + 
catalog.getAbsolutePath());
+            e.printStackTrace();
         } catch (FileNotFoundException e) {
             System.err.println("Test Catalog has not been found: " + 
catalog.getAbsolutePath());
+            e.printStackTrace();
+        } catch (IOException e) {
+            System.err.println("I: " + catalog.getAbsolutePath());
+            e.printStackTrace();
         }
         return count;
     }

http://git-wip-us.apache.org/repos/asf/vxquery/blob/ee7a5693/vxquery-xtest/src/test/resources/cat/SingleQuery.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/cat/SingleQuery.xml 
b/vxquery-xtest/src/test/resources/cat/SingleQuery.xml
new file mode 100644
index 0000000..add4fab
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/cat/SingleQuery.xml
@@ -0,0 +1,26 @@
+<!--
+  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.
+-->
+
+<test-group xmlns="http://www.w3.org/2005/02/query-test-XQTSCatalog"; 
name="AggregatePartition1Queries" featureOwner="VXQuery">
+   <GroupInfo>
+      <title>Single Test</title>
+      <description/>
+   </GroupInfo>
+   <test-case name="simple-add" FilePath="Simple/" Creator="Preston Carman">
+      <description>Adds two numbers.</description>
+      <query name="add" date="2014-08-18"/>
+      <output-file compare="Text">add.txt</output-file>
+   </test-case>
+</test-group>
\ No newline at end of file

Reply via email to