VXQUERY-226: Fix key listing and array unboxing 143/head
authorriyafa <riyafa.12@cse.mrt.ac.lk>
Fri, 5 Aug 2016 17:19:23 +0000 (22:49 +0530)
committerPreston Carman <prestonc@apache.org>
Mon, 8 Aug 2016 03:44:37 +0000 (20:44 -0700)
vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q07_array_navigation.txt [new file with mode: 0644]
vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/Navigation/q08_object_navigation.txt [new file with mode: 0644]
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q07_array_navigation.xq [new file with mode: 0644]
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/Navigation/q08_object_navigation.xq [new file with mode: 0644]
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-1/q14_parser.xq
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-2/q15_parser.xq
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-4/q16_parser.xq
vxquery-xtest/src/test/resources/cat/JsonArrayNavigationQueries.xml
vxquery-xtest/src/test/resources/cat/JsonObjectNavigationQueries.xml

index bd150e0..ff230d3 100644 (file)
@@ -1565,6 +1565,7 @@ public class XMLQueryTranslator {
                         for (ASTNode an : args) {
                             if (an.getTag() == ASTTag.ARGUMENT_LIST) {
                                 ArgumentListNode argNode = (ArgumentListNode) an;
+                                arguments.clear();
                                 for (ASTNode en : argNode.getArg()) {
                                     ILogicalExpression argument = vre(translateExpression(en, tCtx));
                                     arguments.add(argument);
@@ -1578,7 +1579,11 @@ public class XMLQueryTranslator {
                                     }
                                 }
                                 if (arguments.size() == 0) {
-                                    ctxExpr = sfce(BuiltinOperators.KEYS_OR_MEMBERS, expr);
+                                    if (ctxExpr == null) {
+                                        ctxExpr = sfce(BuiltinOperators.KEYS_OR_MEMBERS, expr);
+                                    } else {
+                                        ctxExpr = sfce(BuiltinOperators.KEYS_OR_MEMBERS, ctxExpr);
+                                    }
                                 }
                             } else {
                                 predicates = postfixNode.getArgs();
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q07_array_navigation.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q07_array_navigation.txt
new file mode 100644 (file)
index 0000000..5f5fbe7
--- /dev/null
@@ -0,0 +1,3 @@
+1
+2
+3
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/Navigation/q08_object_navigation.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/Navigation/q08_object_navigation.txt
new file mode 100644 (file)
index 0000000..c4a4625
--- /dev/null
@@ -0,0 +1,2 @@
+number
+letter
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q07_array_navigation.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q07_array_navigation.xq
new file mode 100644 (file)
index 0000000..cf0fdba
--- /dev/null
@@ -0,0 +1,23 @@
+(: 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. :)
+   
+(: Json Array Navigation Query :)
+let $x := [
+    [ "mercury", [1, 2, 3], "venus", "earth", "mars" ],
+    [ "monday","tuesday", "wednesday", "thursday" ]
+]
+return $x(1)(2)()
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/Navigation/q08_object_navigation.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/Navigation/q08_object_navigation.xq
new file mode 100644 (file)
index 0000000..673e67a
--- /dev/null
@@ -0,0 +1,28 @@
+(: 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. :)
+
+(: Json Object Navigation :)
+let $x := {
+    "name" : {
+        "id" : {
+            "number" : 123,
+            "letter" : "g"
+        },
+        "first" : "Riyafa",
+        "Last" : "Abdul Hameed"}
+}
+return $x("name")("id")()
index 7bc86b6..9fff005 100644 (file)
@@ -20,6 +20,6 @@
 let $x:="jsonCollection"
 for $r in collection($x)
     let $z:=$r("results")()
-    for $i in $z()  
+    for $i in $z
 where $i("date")="2001-01-01T00:00:00.000"
 return $i
index b43ddc3..e6a0acb 100644 (file)
@@ -20,6 +20,6 @@
 let $x:="json_half_1|json_half_2"
 for $r in collection($x)
     let $z:=$r("results")()
-    for $i in $z()  
+    for $i in $z
 where $i("datatype")="TMIN"
 return $i
index 4fabd06..72388e8 100644 (file)
@@ -20,6 +20,6 @@
 let $x:="json_quarter_1|json_quarter_2|json_quarter_3|json_quarter_4"
 for $r in collection($x)
     let $z:=$r("results")()
-    for $i in $z()  
+    for $i in $z
 where $i("station")="GHCND:US000000001"
 return $i
index 808d0fb..44e1f64 100644 (file)
@@ -50,4 +50,9 @@
         <query name="q06_array_navigation" date="2016-07-12"/>
         <output-file compare="Text">q06_array_navigation.txt</output-file>
     </test-case>
+    <test-case name="json-array-navigation-q07" FilePath="Json/Array/Navigation" Creator="Riyafa Abdul Hameed">
+        <description>Navigate through an array</description>
+        <query name="q07_array_navigation" date="2016-08-05"/>
+        <output-file compare="Text">q07_array_navigation.txt</output-file>
+    </test-case>
 </test-group>
index 0fe4447..7313a8c 100644 (file)
         <output-file compare="Text">q02_object_navigation.txt</output-file>
     </test-case>
     <test-case name="json-object-navigation-q03" FilePath="Json/Object/Navigation" Creator="Riyafa Abdul Hameed">
-        <description>Size of an object.</description>
+        <description>Navigate through an object.</description>
         <query name="q03_object_navigation" date="2016-06-25"/>
         <output-file compare="Text">q03_object_navigation.txt</output-file>
     </test-case>
     <test-case name="json-object-navigation-q04" FilePath="Json/Object/Navigation" Creator="Riyafa Abdul Hameed">
-        <description>Navigate through an empty object.</description>
+        <description>List keys of the object.</description>
         <query name="q04_object_navigation" date="2016-06-25"/>
         <output-file compare="Text">q04_object_navigation.txt</output-file>
     </test-case>
     <test-case name="json-object-navigation-q05" FilePath="Json/Object/Navigation" Creator="Riyafa Abdul Hameed">
-        <description>Ask for an index out of the object size.</description>
+        <description>Navigate through an empty object.</description>
         <query name="q05_object_navigation" date="2016-06-25"/>
         <output-file compare="Text">q05_object_navigation.txt</output-file>
     </test-case>
     <test-case name="json-object-navigation-q06" FilePath="Json/Object/Navigation" Creator="Riyafa Abdul Hameed">
-        <description>Ask for an index out of the object size.</description>
+        <description>Navigate through an empty object</description>
         <query name="q06_object_navigation" date="2016-06-25"/>
         <output-file compare="Text">q06_object_navigation.txt</output-file>
     </test-case>
     <test-case name="json-object-navigation-q07" FilePath="Json/Object/Navigation" Creator="Riyafa Abdul Hameed">
-        <description>Ask for an index out of the object size.</description>
+        <description>List non existing key</description>
         <query name="q07_object_navigation" date="2016-06-25"/>
         <output-file compare="Text">q07_object_navigation.txt</output-file>
     </test-case>
+    <test-case name="json-object-navigation-q08" FilePath="Json/Object/Navigation" Creator="Riyafa Abdul Hameed">
+        <description>Navigate through an object</description>
+        <query name="q08_object_navigation" date="2016-08-05"/>
+        <output-file compare="Text">q08_object_navigation.txt</output-file>
+    </test-case>
 </test-group>