Repository: vxquery
Updated Branches:
  refs/heads/master d19fa2630 -> 00a10eeec


Implementation of array unboxing and testing


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

Branch: refs/heads/master
Commit: 00a10eeecaec211c36e18439f49020e4cd4b51a6
Parents: d19fa26
Author: Christina Pavlopoulou <[email protected]>
Authored: Tue Jul 12 14:30:00 2016 -0700
Committer: Christina Pavlopoulou <[email protected]>
Committed: Tue Jul 12 20:09:30 2016 -0700

----------------------------------------------------------------------
 .../json/KeysOrMembersScalarEvaluator.java      | 34 ++++++++++++++++++++
 .../Array/Navigation/q06_array_navigation.txt   |  2 ++
 .../Array/Navigation/q06_array_navigation.xq    | 21 ++++++++++++
 .../Queries/XQuery/Json/Parser/q13_parser.xq    |  2 +-
 .../cat/JsonArrayNavigationQueries.xml          |  5 +++
 5 files changed, 63 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/vxquery/blob/00a10eee/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
----------------------------------------------------------------------
diff --git 
a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
 
b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
index 1b90282..81afd94 100644
--- 
a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
+++ 
b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
@@ -19,8 +19,12 @@ package org.apache.vxquery.runtime.functions.json;
 import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import org.apache.hyracks.api.context.IHyracksTaskContext;
 import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.jsonitem.ArrayPointable;
 import org.apache.vxquery.datamodel.accessors.jsonitem.ObjectPointable;
+import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
 import org.apache.vxquery.datamodel.values.ValueTag;
 import org.apache.vxquery.exceptions.ErrorCode;
 import org.apache.vxquery.exceptions.SystemException;
@@ -31,11 +35,21 @@ import java.io.IOException;
 public class KeysOrMembersScalarEvaluator extends 
AbstractTaggedValueArgumentScalarEvaluator {
     protected final IHyracksTaskContext ctx;
     private final ObjectPointable op;
+    private final ArrayPointable ap;
+    private final SequencePointable sp;
+    private final ArrayBackedValueStorage abvs;
+    private final SequenceBuilder sb;
+    private final TaggedValuePointable tempTvp;
 
     public KeysOrMembersScalarEvaluator(IHyracksTaskContext ctx, 
IScalarEvaluator[] args) {
         super(args);
         this.ctx = ctx;
         op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+        ap = (ArrayPointable) ArrayPointable.FACTORY.createPointable();
+        abvs = new ArrayBackedValueStorage();
+        sb = new SequenceBuilder();
+        sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        tempTvp = (TaggedValuePointable) 
TaggedValuePointable.FACTORY.createPointable();
     }
 
     @Override
@@ -52,6 +66,26 @@ public class KeysOrMembersScalarEvaluator extends 
AbstractTaggedValueArgumentSca
                 throw new SystemException(ErrorCode.SYSE0001, e);
 
             }
+        } else if (tvp1.getTag() == ValueTag.ARRAY_TAG) {
+            abvs.reset();
+            sb.reset(abvs);
+            tvp1.getValue(ap);
+            tvp1.getValue(sp);
+            int size = sp.getEntryCount();
+            for (int i = 0; i < size; i++) {
+                sp.getEntry(i, tempTvp);
+                try {
+                    sb.addItem(tempTvp);
+                } catch (IOException e) {
+                    throw new SystemException(ErrorCode.SYSE0001, e);
+                }
+            }
+            try {
+                sb.finish();
+            } catch (IOException e) {
+                throw new SystemException(ErrorCode.SYSE0001, e);
+            }
+            result.set(abvs);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/vxquery/blob/00a10eee/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q06_array_navigation.txt
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q06_array_navigation.txt
 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q06_array_navigation.txt
new file mode 100644
index 0000000..1191247
--- /dev/null
+++ 
b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Array/Navigation/q06_array_navigation.txt
@@ -0,0 +1,2 @@
+1
+2

http://git-wip-us.apache.org/repos/asf/vxquery/blob/00a10eee/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q06_array_navigation.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q06_array_navigation.xq
 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q06_array_navigation.xq
new file mode 100644
index 0000000..2316243
--- /dev/null
+++ 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Array/Navigation/q06_array_navigation.xq
@@ -0,0 +1,21 @@
+(: 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 :)
+(: Ask for an index out of the array size:)
+let $x:=[1,2]
+return $x()

http://git-wip-us.apache.org/repos/asf/vxquery/blob/00a10eee/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/q13_parser.xq
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/q13_parser.xq 
b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/q13_parser.xq
index f4a8d31..f2f00c9 100644
--- a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/q13_parser.xq
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/q13_parser.xq
@@ -16,7 +16,7 @@
    under the License. :)
 
 (: Json Parser Query :)
-(: parse a string with arrays :)
+(: parse a string with multiple items :)
 let $x:="{&quot;foo&quot;:&quot;bar&quot;} [1]"
 let $y:={"jsoniq-multiple-top-level-items":xs:boolean("false")}
 return jn:parse-json($x,$y)

http://git-wip-us.apache.org/repos/asf/vxquery/blob/00a10eee/vxquery-xtest/src/test/resources/cat/JsonArrayNavigationQueries.xml
----------------------------------------------------------------------
diff --git 
a/vxquery-xtest/src/test/resources/cat/JsonArrayNavigationQueries.xml 
b/vxquery-xtest/src/test/resources/cat/JsonArrayNavigationQueries.xml
index f40db91..808d0fb 100644
--- a/vxquery-xtest/src/test/resources/cat/JsonArrayNavigationQueries.xml
+++ b/vxquery-xtest/src/test/resources/cat/JsonArrayNavigationQueries.xml
@@ -45,4 +45,9 @@
         <query name="q05_array_navigation" date="2016-06-18"/>
         <output-file compare="Text">q05_array_navigation.txt</output-file>
     </test-case>
+    <test-case name="json-array-navigation-q06" 
FilePath="Json/Array/Navigation" Creator="Christina Pavlopoulou">
+        <description>Ask for the whole array.</description>
+        <query name="q06_array_navigation" date="2016-07-12"/>
+        <output-file compare="Text">q06_array_navigation.txt</output-file>
+    </test-case>
 </test-group>

Reply via email to