Implement libjn:accumulate and libjn:intersect 126/head
authorriyafa <riyafa.12@cse.mrt.ac.lk>
Wed, 27 Jul 2016 08:42:51 +0000 (14:12 +0530)
committerriyafa <riyafa.12@cse.mrt.ac.lk>
Sat, 13 Aug 2016 13:32:26 +0000 (19:02 +0530)
14 files changed:
vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/AbstractLibjnAccumulateScalarEvaluator.java [new file with mode: 0644]
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnKeysScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnNullScalarEvaluator.java
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnAccumulateScalarEvaluator.java [new file with mode: 0644]
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnAccumulateScalarEvaluatorFactory.java [new file with mode: 0644]
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnIntersectScalarEvaluator.java [new file with mode: 0644]
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnIntersectScalarEvaluatorFactory.java [new file with mode: 0644]
vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/util/FunctionHelper.java
vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Libraries/accumulate.txt [new file with mode: 0644]
vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Libraries/intersect.txt [new file with mode: 0644]
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Libraries/accumulate.xq [new file with mode: 0644]
vxquery-xtest/src/test/resources/Queries/XQuery/Json/Libraries/intersect.xq [new file with mode: 0644]
vxquery-xtest/src/test/resources/cat/LibrariesInJSONiq.xml

index 43839f8..9156331 100644 (file)
         <return type="item()*"/>
         <runtime type="scalar" class="org.apache.vxquery.runtime.functions.json.LibjnRemoveKeysScalarEvaluatorFactory"/>
     </function>
+
+    <!-- libjn:accumulate($sequence as item()*) as object() -->
+    <function name="libjn:accumulate">
+        <param name="sequence" type="item()*"/>
+        <return type="object()"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.json.LibjnAccumulateScalarEvaluatorFactory"/>
+    </function>
+
+    <!-- libjn:intersect($sequence as item()*) as object() -->
+    <function name="libjn:intersect">
+        <param name="sequence" type="item()*"/>
+        <return type="object()"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.json.LibjnIntersectScalarEvaluatorFactory"/>
+    </function>
 </functions>
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/AbstractLibjnAccumulateScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/AbstractLibjnAccumulateScalarEvaluator.java
new file mode 100644 (file)
index 0000000..90dc034
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+* 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.
+*/
+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.primitive.UTF8StringPointable;
+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.ObjectPointable;
+import org.apache.vxquery.datamodel.builders.jsonitem.ArrayBuilder;
+import org.apache.vxquery.datamodel.builders.jsonitem.ObjectBuilder;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
+import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public abstract class AbstractLibjnAccumulateScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
+    protected final IHyracksTaskContext ctx;
+    private final SequencePointable sp, sp1;
+    protected final ObjectBuilder ob;
+    private final ArrayBuilder ab;
+    protected TaggedValuePointable key, value;
+    private final UTF8StringPointable stringKey;
+    private final ArrayBackedValueStorage abvs, abvs1;
+    private final Map<TaggedValuePointable, List<TaggedValuePointable>> tvps;
+    protected List<TaggedValuePointable> values;
+
+    public AbstractLibjnAccumulateScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
+        super(args);
+        this.ctx = ctx;
+        sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
+        stringKey = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
+        abvs = new ArrayBackedValueStorage();
+        abvs1 = new ArrayBackedValueStorage();
+        ob = new ObjectBuilder();
+        ab = new ArrayBuilder();
+        tvps = new LinkedHashMap<>();
+
+    }
+
+    @Override
+    protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+        TaggedValuePointable arg = args[0];
+        if (!(arg.getTag() == ValueTag.SEQUENCE_TAG || arg.getTag() == ValueTag.OBJECT_TAG)) {
+            throw new SystemException(ErrorCode.FORG0006);
+        }
+        TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
+        try {
+            abvs.reset();
+            ob.reset(abvs);
+            tvps.clear();
+            if (arg.getTag() == ValueTag.SEQUENCE_TAG) {
+                arg.getValue(sp);
+                for (int i = 0; i < sp.getEntryCount(); ++i) {
+                    sp.getEntry(i, tempTvp);
+                    if (tempTvp.getTag() == ValueTag.OBJECT_TAG) {
+                        addPairs(tempTvp);
+                    }
+                }
+            } else if (arg.getTag() == ValueTag.OBJECT_TAG) {
+                addPairs(arg);
+            }
+            for (TaggedValuePointable key1 : tvps.keySet()) {
+                key1.getValue(stringKey);
+                values = tvps.get(key1);
+                if (values.size() > 1) {
+                    FunctionHelper.removeDuplicates(values);
+                    if (values.size() > 1) {
+                        abvs1.reset();
+                        ab.reset(abvs1);
+                        for (TaggedValuePointable pointable : values) {
+                            ab.addItem(pointable);
+                        }
+                        ab.finish();
+                        ob.addItem(stringKey, abvs1);
+                    } else {
+                        ob.addItem(stringKey, values.get(0));
+                    }
+                } else {
+                    addKeyValue(stringKey, values.get(0));
+                }
+            }
+            ob.finish();
+            result.set(abvs);
+        } catch (IOException e) {
+            throw new SystemException(ErrorCode.SYSE0001, e);
+        } finally {
+            ppool.giveBack(tempTvp);
+            for (TaggedValuePointable key1 : tvps.keySet()) {
+                for (TaggedValuePointable value1 : tvps.get(key1)) {
+                    ppool.giveBack(value1);
+                }
+                ppool.giveBack(key1);
+            }
+        }
+    }
+
+    protected abstract void addKeyValue(UTF8StringPointable stringKey, TaggedValuePointable taggedValuePointable)
+            throws IOException;
+
+    private void addPair(TaggedValuePointable tvp1, ObjectPointable op) throws IOException, SystemException {
+        TaggedValuePointable tvp = isDuplicateKeys(tvp1, tvps.keySet());
+        value = ppool.takeOne(TaggedValuePointable.class);
+        tvp1.getValue(stringKey);
+        op.getValue(stringKey, value);
+        if (tvp == null) {
+            key = ppool.takeOne(TaggedValuePointable.class);
+            key.set(tvp1);
+            values = new ArrayList<>();
+            values.add(value);
+            tvps.put(key, values);
+        } else {
+            tvps.get(tvp).add(value);
+        }
+    }
+
+    private void addPairs(TaggedValuePointable tvp1) throws IOException, SystemException {
+        ObjectPointable op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+        tvp1.getValue(op);
+        op.getKeys(tvp1);
+        if (tvp1.getTag() == ValueTag.XS_STRING_TAG) {
+            addPair(tvp1, op);
+        } else if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+            tvp1.getValue(sp1);
+            for (int j = 0; j < sp1.getEntryCount(); ++j) {
+                sp1.getEntry(j, tvp1);
+                addPair(tvp1, op);
+            }
+        }
+    }
+
+    private TaggedValuePointable isDuplicateKeys(TaggedValuePointable key, Set<TaggedValuePointable> pointables) {
+        for (TaggedValuePointable tvp : pointables) {
+            if (tvp != null && FunctionHelper.arraysEqual(tvp, key)) {
+                return tvp;
+            }
+        }
+        return null;
+    }
+}
index 4b093eb..c90472e 100644 (file)
@@ -79,7 +79,7 @@ public class JnKeysScalarEvaluator extends AbstractTaggedValueArgumentScalarEval
                         }
                     }
                 }
-                removeDuplicates(pointables);
+                FunctionHelper.removeDuplicates(pointables);
                 abvs.reset();
                 sb.reset(abvs);
                 for (TaggedValuePointable tvp : pointables) {
@@ -104,18 +104,4 @@ public class JnKeysScalarEvaluator extends AbstractTaggedValueArgumentScalarEval
             XDMConstants.setEmptySequence(result);
         }
     }
-
-    private void removeDuplicates(List<TaggedValuePointable> pointables) {
-        int size = pointables.size();
-        for (int i = 0; i < size - 1; i++) {
-            for (int j = i + 1; j < size; j++) {
-                if (!FunctionHelper.arraysEqual(pointables.get(j), pointables.get(i))) {
-                    continue;
-                }
-                pointables.remove(j);
-                j--;
-                size--;
-            }
-        }
-    }
 }
index 772f30a..3137b67 100644 (file)
@@ -27,12 +27,10 @@ import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScal
 
 public class JnNullScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
     protected final IHyracksTaskContext ctx;
-    private final ArrayBackedValueStorage abvs;
 
     public JnNullScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
         super(args);
         this.ctx = ctx;
-        abvs = new ArrayBackedValueStorage();
     }
 
     @Override
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnAccumulateScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnAccumulateScalarEvaluator.java
new file mode 100644 (file)
index 0000000..378c53d
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+* 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.
+*/
+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.primitive.UTF8StringPointable;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+
+import java.io.IOException;
+
+public class LibjnAccumulateScalarEvaluator extends AbstractLibjnAccumulateScalarEvaluator {
+
+    public LibjnAccumulateScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
+        super(ctx, args);
+    }
+
+    @Override
+    protected void addKeyValue(UTF8StringPointable stringKey, TaggedValuePointable taggedValuePointable)
+            throws IOException {
+        ob.addItem(stringKey, values.get(0));
+    }
+
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnAccumulateScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnAccumulateScalarEvaluatorFactory.java
new file mode 100644 (file)
index 0000000..fbbb997
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.vxquery.runtime.functions.json;
+
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+
+public class LibjnAccumulateScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+
+    private static final long serialVersionUID = 1L;
+
+    public LibjnAccumulateScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        return new LibjnAccumulateScalarEvaluator(ctx, args);
+    }
+
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnIntersectScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnIntersectScalarEvaluator.java
new file mode 100644 (file)
index 0000000..b8fcaa3
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+* 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.
+*/
+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.primitive.UTF8StringPointable;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+
+import java.io.IOException;
+
+public class LibjnIntersectScalarEvaluator extends AbstractLibjnAccumulateScalarEvaluator {
+
+    public LibjnIntersectScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
+        super(ctx, args);
+    }
+
+    @Override
+    protected void addKeyValue(UTF8StringPointable stringKey, TaggedValuePointable taggedValuePointable)
+            throws IOException {
+    }
+
+}
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnIntersectScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/LibjnIntersectScalarEvaluatorFactory.java
new file mode 100644 (file)
index 0000000..a7d7b91
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package org.apache.vxquery.runtime.functions.json;
+
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+
+public class LibjnIntersectScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+
+    private static final long serialVersionUID = 1L;
+
+    public LibjnIntersectScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        return new LibjnIntersectScalarEvaluator(ctx, args);
+    }
+
+}
index 0b3ea28..4176b20 100644 (file)
@@ -28,6 +28,7 @@ import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -1425,4 +1426,18 @@ public class FunctionHelper {
         }
     }
 
+    public static void removeDuplicates(List<TaggedValuePointable> pointables) {
+        int size = pointables.size();
+        for (int i = 0; i < size - 1; i++) {
+            for (int j = i + 1; j < size; j++) {
+                if (!FunctionHelper.arraysEqual(pointables.get(j), pointables.get(i))) {
+                    continue;
+                }
+                pointables.remove(j);
+                j--;
+                size--;
+            }
+        }
+    }
+
 }
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Libraries/accumulate.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Libraries/accumulate.txt
new file mode 100644 (file)
index 0000000..2ac05a3
--- /dev/null
@@ -0,0 +1,5 @@
+{"Sunday":1,"Monday":2,"Tuesday":3,"Wednesday":4,"Thursday":5,"Friday":6,"Saturday":7}
+{"a":"b","c":"d"}
+{"a":["b","d"]}
+{"foo":[{"bar":[1,2]},"bar"],"bar":"foo","coa":123,"456":[789,"number"]}
+{"a":[{"c":"d"},{"e":"f"}]}
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Libraries/intersect.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Libraries/intersect.txt
new file mode 100644 (file)
index 0000000..ce52d9a
--- /dev/null
@@ -0,0 +1 @@
+{"foo":[{"bar":[1,2]},"bar"],"coa":123,"456":[789,"number"]}
\ No newline at end of file
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Libraries/accumulate.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Libraries/accumulate.xq
new file mode 100644 (file)
index 0000000..dfaaa8f
--- /dev/null
@@ -0,0 +1,41 @@
+(: 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. :)
+
+(: JSONiq libjn:accumulate :)
+libjn:accumulate(
+        for $d at $i in ("Sunday",
+        "Monday",
+        "Tuesday",
+        "Wednesday",
+        "Thursday",
+        "Friday",
+        "Saturday" )
+        return { $d : $i }
+),
+libjn:accumulate(({ "a": "b" }, { "c": "d" })),
+libjn:accumulate(({ "a": "b" }, { "a": "d" })),
+libjn:accumulate(
+        (
+                { "foo" : { "bar" : [ 1, 2 ] } },
+                [ 1, 2, 3, 4 ],
+                { "foo" : "bar", "bar" : "foo", "coa":123 , 456: 789},
+                {"foo" : "bar", "coa" :123, 456 :"number"},
+                1,
+                jn:null()
+        )
+),
+libjn:accumulate(({ "a": { "c": "d" } }, { "a": { "e": "f" } }))
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Libraries/intersect.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Libraries/intersect.xq
new file mode 100644 (file)
index 0000000..2b48b61
--- /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. :)
+
+(: JSONiq libjn:intersect :)
+libjn:intersect(
+    (
+        { "foo" : { "bar" : [ 1, 2 ] } },
+        [ 1, 2, 3, 4 ],
+        { "foo" : "bar", "bar" : "foo", "coa":123 , 456: 789},
+        {"foo" : "bar", "coa" :123, 456 :"number"},
+        1,
+        jn:null()
+    )
+)
index 66cab65..a656aba 100644 (file)
@@ -40,7 +40,6 @@
       <query name="flatten" date="2016-07-20"/>
       <output-file compare="Text">flatten.txt</output-file>
    </test-case>
-
     <test-case name="values" FilePath="Json/Libraries/" Creator="Riyafa Abdul Hameed">
         <description>Json Libraries.</description>
         <query name="values" date="2016-07-31"/>
       <query name="remove_keys" date="2016-07-31"/>
       <output-file compare="Text">remove_keys.txt</output-file>
    </test-case>
+   <test-case name="accumulate" FilePath="Json/Libraries/" Creator="Riyafa Abdul Hameed">
+      <description>Json Libraries.</description>
+      <query name="accumulate" date="2016-07-27"/>
+      <output-file compare="Text">accumulate.txt</output-file>
+   </test-case>
+   <test-case name="intersect" FilePath="Json/Libraries/" Creator="Riyafa Abdul Hameed">
+      <description>Json Libraries.</description>
+      <query name="intersect" date="2016-07-30"/>
+      <output-file compare="Text">intersect.txt</output-file>
+   </test-case>
 </test-group>