You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by wa...@apache.org on 2015/10/28 17:42:28 UTC

incubator-asterixdb git commit: ASTERIXDB-1155: NULL handling of LimitClause in CloneAndSubstituteVariablesVisitor fixed.

Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master 971923d96 -> 1eeb3d29c


ASTERIXDB-1155: NULL handling of LimitClause in CloneAndSubstituteVariablesVisitor fixed.

Change-Id: Idd932f2b783454b0216a947bdb4ff35a6b101cd0
Reviewed-on: https://asterix-gerrit.ics.uci.edu/472
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>
Reviewed-by: Steven Jacobs <sj...@ucr.edu>


Project: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/commit/1eeb3d29
Tree: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/tree/1eeb3d29
Diff: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/diff/1eeb3d29

Branch: refs/heads/master
Commit: 1eeb3d29ccb7ee81c32a7b365db4c5e3ee0705cc
Parents: 971923d
Author: Taewoo Kim <wa...@yahoo.com>
Authored: Tue Oct 27 23:42:30 2015 -0700
Committer: Taewoo Kim <wa...@gmail.com>
Committed: Wed Oct 28 09:39:18 2015 -0700

----------------------------------------------------------------------
 .../udf31/udf31.1.ddl.aql                       | 47 ++++++++++++++++++++
 .../udf31/udf31.2.update.aql                    | 40 +++++++++++++++++
 .../udf31/udf31.3.query.aql                     | 30 +++++++++++++
 .../user-defined-functions/udf31/udf31.1.adm    |  2 +
 .../src/test/resources/runtimets/testsuite.xml  |  7 ++-
 .../CloneAndSubstituteVariablesVisitor.java     | 14 ++++--
 6 files changed, 135 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/1eeb3d29/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql
new file mode 100644
index 0000000..4f8521c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.1.ddl.aql
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Declare a UDF that has a LIMIT in it and try to execute that function.
+ * Expected Res : Success
+ */
+
+drop dataverse emergencyTest if exists;
+create dataverse emergencyTest;
+use dataverse emergencyTest;
+
+create type EmergencyReport as
+{
+  "id": int,
+  "intensity": int,
+  "message": string
+}
+
+create dataset EmergencyReports(EmergencyReport)
+primary key id;
+
+create function mostIntenseEarthquakeNearLocation()
+{
+  for $emergency in dataset EmergencyReports
+  order by $emergency.id
+  limit 1
+  return $emergency.message
+}
+
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/1eeb3d29/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql
new file mode 100644
index 0000000..d9db485
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.2.update.aql
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Declare a UDF that has a LIMIT in it and try to execute that function.
+ * Expected Res : Success
+ */
+
+use dataverse emergencyTest;
+
+insert into dataset EmergencyReports({
+  "id":1,"intensity":1,"message":"emergency1"
+});
+
+insert into dataset EmergencyReports({
+  "id":2,"intensity":2,"message":"emergency2"
+});
+
+insert into dataset EmergencyReports({
+  "id":3,"intensity":3,"message":"emergency3"
+});
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/1eeb3d29/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql
new file mode 100644
index 0000000..877a8be
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/user-defined-functions/udf31/udf31.3.query.aql
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+/*
+ * Description  : Declare a UDF that has a LIMIT in it and try to execute that function.
+ * Expected Res : Success
+ */
+
+use dataverse emergencyTest;
+
+for $result in mostIntenseEarthquakeNearLocation()
+return $result;
+
+

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/1eeb3d29/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm
new file mode 100644
index 0000000..b6ac4e0
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/user-defined-functions/udf31/udf31.1.adm
@@ -0,0 +1,2 @@
+[ "emergency1"
+ ]

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/1eeb3d29/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index aef2b54..b6417bc 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -5932,6 +5932,11 @@
             </compilation-unit>
         </test-case>
         <test-case FilePath="user-defined-functions">
+            <compilation-unit name="udf31">
+                <output-dir compare="Text">udf31</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="user-defined-functions">
             <compilation-unit name="f01">
                 <output-dir compare="Text">f01</output-dir>
                 <expected-error>org.apache.asterix.common.exceptions.AsterixException</expected-error>
@@ -6159,7 +6164,7 @@
 
     </test-group>
     <test-group name="hdfs">
-    	<test-case FilePath="hdfs">
+      <test-case FilePath="hdfs">
             <compilation-unit name="hdfs_shortcircuit">
                 <output-dir compare="Text">hdfs_shortcircuit</output-dir>
             </compilation-unit>

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/1eeb3d29/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java b/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
index b6223cb..adca38c 100644
--- a/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
+++ b/asterix-aql/src/main/java/org/apache/asterix/aql/rewrites/CloneAndSubstituteVariablesVisitor.java
@@ -87,8 +87,8 @@ import org.apache.asterix.aql.expression.visitor.IAqlExpressionVisitor;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.hyracks.algebricks.common.utils.Pair;
 
-public class CloneAndSubstituteVariablesVisitor implements
-        IAqlExpressionVisitor<Pair<IAqlExpression, List<VariableSubstitution>>, List<VariableSubstitution>> {
+public class CloneAndSubstituteVariablesVisitor
+        implements IAqlExpressionVisitor<Pair<IAqlExpression, List<VariableSubstitution>>, List<VariableSubstitution>> {
 
     private AqlRewritingContext context;
 
@@ -278,7 +278,14 @@ public class CloneAndSubstituteVariablesVisitor implements
     public Pair<IAqlExpression, List<VariableSubstitution>> visitLimitClause(LimitClause lc,
             List<VariableSubstitution> arg) throws AsterixException {
         Pair<IAqlExpression, List<VariableSubstitution>> p1 = lc.getLimitExpr().accept(this, arg);
-        Pair<IAqlExpression, List<VariableSubstitution>> p2 = lc.getOffset().accept(this, arg);
+        Pair<IAqlExpression, List<VariableSubstitution>> p2 = null;
+        // The offset expression can be null.
+        Expression lcOffsetExpr = lc.getOffset();
+        if (lcOffsetExpr != null) {
+            p2 = lcOffsetExpr.accept(this, arg);
+        } else {
+            p2 = new Pair<IAqlExpression, List<VariableSubstitution>>(null, null);
+        }
         LimitClause c = new LimitClause((Expression) p1.first, (Expression) p2.first);
         return new Pair<IAqlExpression, List<VariableSubstitution>>(c, arg);
     }
@@ -628,7 +635,6 @@ public class CloneAndSubstituteVariablesVisitor implements
         // TODO Auto-generated method stub
         return null;
     }
-    
 
     @Override
     public Pair<IAqlExpression, List<VariableSubstitution>> visitCreateFeedPolicyStatement(