You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2016/07/29 00:50:51 UTC
vxquery git commit: VXQUERY-225 resolved-fn:serialize is now supported
Repository: vxquery
Updated Branches:
refs/heads/master fa0b77a84 -> 13e2ff328
VXQUERY-225 resolved-fn:serialize is now supported
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/13e2ff32
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/13e2ff32
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/13e2ff32
Branch: refs/heads/master
Commit: 13e2ff32838e3f37b3585d87e0906b203160030b
Parents: fa0b77a
Author: Christina Pavlopoulou <cp...@ucr.edu>
Authored: Fri Jul 22 13:25:38 2016 -0700
Committer: Christina Pavlopoulou <cp...@ucr.edu>
Committed: Thu Jul 28 17:45:41 2016 -0700
----------------------------------------------------------------------
.../datamodel/accessors/TypedPointables.java | 4 ++
.../vxquery/functions/builtin-functions.xml | 7 ++
.../functions/cast/AbstractCastToOperation.java | 5 ++
.../FnSerializeScalarEvaluatorFactory.java | 74 ++++++++++++++++++++
.../Serialization/q01_serialize.txt | 1 +
.../Serialization/q02_serialize.txt | 1 +
.../Serialization/q03_serialize.txt | 1 +
.../Serialization/q04_serialize.txt | 1 +
.../XQuery/Serialization/q01_serialize.xq | 20 ++++++
.../XQuery/Serialization/q02_serialize.xq | 20 ++++++
.../XQuery/Serialization/q03_serialize.xq | 20 ++++++
.../XQuery/Serialization/q04_serialize.xq | 20 ++++++
.../src/test/resources/VXQueryCatalog.xml | 15 ++++
.../test/resources/cat/SerializationQueries.xml | 43 ++++++++++++
14 files changed, 232 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/TypedPointables.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/TypedPointables.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/TypedPointables.java
index 32eed34..a2cae9d 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/TypedPointables.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/TypedPointables.java
@@ -23,6 +23,8 @@ import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable;
import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
+import org.apache.vxquery.datamodel.accessors.jsonitem.ArrayPointable;
+import org.apache.vxquery.datamodel.accessors.jsonitem.ObjectPointable;
import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable;
import org.apache.vxquery.datamodel.accessors.nodes.DocumentNodePointable;
import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable;
@@ -65,6 +67,8 @@ public class TypedPointables {
public XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
public XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
public XSQNamePointable qnamep = (XSQNamePointable) XSQNamePointable.FACTORY.createPointable();
+ public ArrayPointable ap = (ArrayPointable) ArrayPointable.FACTORY.createPointable();
+ public ObjectPointable op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
// XQuery Nodes
public AttributeNodePointable anp = (AttributeNodePointable) AttributeNodePointable.FACTORY.createPointable();
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml b/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
index 8f777a5..5e58596 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
+++ b/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
@@ -1171,6 +1171,13 @@
<argument value="0"/>
</property>
</function>
+
+ <!-- fn:serialize($data as item()*) as xs:string -->
+ <function name="fn:serialize">
+ <param name="data" type="item()*"/>
+ <return type="xs:string"/>
+ <runtime type="scalar" class="org.apache.vxquery.runtime.functions.serialize.FnSerializeScalarEvaluatorFactory"/>
+ </function>
<!-- jn:keys($arg as item()*) as xs:string* -->
<function name="jn:keys">
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java
index 703d969..bb74ff2 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/AbstractCastToOperation.java
@@ -26,6 +26,7 @@ import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable;
import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable;
import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
+import org.apache.vxquery.datamodel.accessors.jsonitem.ArrayPointable;
import org.apache.vxquery.exceptions.ErrorCode;
import org.apache.vxquery.exceptions.SystemException;
@@ -230,4 +231,8 @@ public abstract class AbstractCastToOperation {
public void convertNull(DataOutput dOut) throws SystemException, IOException {
throw new SystemException(ErrorCode.XPTY0004);
}
+
+ public void convertArray(ArrayPointable ap, DataOutput dOut) throws SystemException, IOException {
+ throw new SystemException(ErrorCode.XPTY0004);
+ }
}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/serialize/FnSerializeScalarEvaluatorFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/serialize/FnSerializeScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/serialize/FnSerializeScalarEvaluatorFactory.java
new file mode 100644
index 0000000..a8025a9
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/serialize/FnSerializeScalarEvaluatorFactory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.serialize;
+
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.PrintStream;
+
+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.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.data.std.util.ByteArrayAccessibleOutputStream;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+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.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+import org.apache.vxquery.serializer.XMLSerializer;
+
+public class FnSerializeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+
+ private static final long serialVersionUID = 1L;
+
+ public FnSerializeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+ super(args);
+ }
+
+ @Override
+ protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+ throws AlgebricksException {
+ final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+ final ByteArrayAccessibleOutputStream baaos = new ByteArrayAccessibleOutputStream();
+ final PrintStream ps = new PrintStream(baaos);
+ final XMLSerializer printer = new XMLSerializer();
+ final DataOutput out = abvs.getDataOutput();
+ return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+
+ @Override
+ protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+ baaos.reset();
+ TaggedValuePointable tvp = args[0];
+ printer.printTaggedValuePointable(ps, tvp);
+ abvs.reset();
+ try {
+ out.write(ValueTag.XS_STRING_TAG);
+ out.write((byte) ((baaos.size() >>> 8) & 0xFF));
+ out.write((byte) ((baaos.size() >>> 0) & 0xFF));
+ out.write(baaos.getByteArray(), 0, baaos.size());
+ } catch (IOException e) {
+ throw new SystemException(ErrorCode.XPTY0004);
+ }
+ result.set(abvs);
+ }
+
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q01_serialize.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q01_serialize.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q01_serialize.txt
new file mode 100644
index 0000000..3cc0ecb
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q01_serialize.txt
@@ -0,0 +1 @@
+[1,2,3]
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q02_serialize.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q02_serialize.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q02_serialize.txt
new file mode 100644
index 0000000..6a84fb5
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q02_serialize.txt
@@ -0,0 +1 @@
+{"name":"Christina"}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q03_serialize.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q03_serialize.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q03_serialize.txt
new file mode 100644
index 0000000..7b4a0ed
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q03_serialize.txt
@@ -0,0 +1 @@
+2016-06-07
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q04_serialize.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q04_serialize.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q04_serialize.txt
new file mode 100644
index 0000000..0b5c905
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Serialization/q04_serialize.txt
@@ -0,0 +1 @@
+<a>3</a>
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q01_serialize.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q01_serialize.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q01_serialize.xq
new file mode 100644
index 0000000..d6adc8e
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q01_serialize.xq
@@ -0,0 +1,20 @@
+(: 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. :)
+
+(: Serialize Function Query :)
+(: Serialize the input :)
+ fn:serialize([1,2,3])
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q02_serialize.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q02_serialize.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q02_serialize.xq
new file mode 100644
index 0000000..1b4dbdd
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q02_serialize.xq
@@ -0,0 +1,20 @@
+(: 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. :)
+
+(: Serialize Function Query :)
+(: Serialize the input :)
+ fn:serialize({"name":"Christina"})
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q03_serialize.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q03_serialize.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q03_serialize.xq
new file mode 100644
index 0000000..16f17bc
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q03_serialize.xq
@@ -0,0 +1,20 @@
+(: 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. :)
+
+(: Serialize Function Query :)
+(: Serialize the input :)
+ fn:serialize(xs:date("2016-06-07"))
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q04_serialize.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q04_serialize.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q04_serialize.xq
new file mode 100644
index 0000000..2a7c755
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Serialization/q04_serialize.xq
@@ -0,0 +1,20 @@
+(: 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. :)
+
+(: Serialize Function Query :)
+(: Serialize the input :)
+ fn:serialize(<a>3</a>)
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/VXQueryCatalog.xml b/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
index e8a3a43..ddb0772 100644
--- a/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
+++ b/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
@@ -54,6 +54,8 @@
<!ENTITY TraceQuery SYSTEM "cat/TraceQuery.xml">
+<!ENTITY SerializationQueries SYSTEM "cat/SerializationQueries.xml">
+
]>
<test-suite xmlns="http://www.w3.org/2005/02/query-test-XQTSCatalog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" CatalogDesignDate="2014-04-01" version="0.0.1" SourceOffsetPath="./" ResultOffsetPath="ExpectedTestResults/" XQueryQueryOffsetPath="Queries/XQuery/" XQueryXQueryOffsetPath="Queries/XQueryX/" XQueryFileExtension=".xq" XQueryXFileExtension=".xqx" xsi:schemaLocation="http://www.w3.org/2005/02/query-test-XQTSCatalog XQTSCatalog.xsd">
<test-suite-info>
@@ -336,4 +338,17 @@
&LibrariesInJSONiq;
</test-group>
</test-group>
+ <test-group name="SerializationQueries" featureOwner="Christina Pavlopoulou">
+ <GroupInfo>
+ <title>Serialize Function Queries</title>
+ <description/>
+ </GroupInfo>
+ <test-group name="SerializeTesting" featureOwner="Christina Pavlopoulou">
+ <GroupInfo>
+ <title>Serialize Function Tests</title>
+ <description/>
+ </GroupInfo>
+ &SerializationQueries;
+ </test-group>
+ </test-group>
</test-suite>
http://git-wip-us.apache.org/repos/asf/vxquery/blob/13e2ff32/vxquery-xtest/src/test/resources/cat/SerializationQueries.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/cat/SerializationQueries.xml b/vxquery-xtest/src/test/resources/cat/SerializationQueries.xml
new file mode 100644
index 0000000..719455c
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/cat/SerializationQueries.xml
@@ -0,0 +1,43 @@
+<!--
+ 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="JsonArrayNavigationQueries" featureOwner="VXQuery">
+ <GroupInfo>
+ <title>Serialize Function</title>
+ <description/>
+ </GroupInfo>
+ <test-case name="serialize-q01" FilePath="Serialization" Creator="Christina Pavlopoulou">
+ <description>Serialize an array.</description>
+ <query name="q01_serialize" date="2016-07-26"/>
+ <output-file compare="Text">q01_serialize.txt</output-file>
+ </test-case>
+ <test-case name="serialize-q02" FilePath="Serialization" Creator="Christina Pavlopoulou">
+ <description>Serialize an object.</description>
+ <query name="q02_serialize" date="2016-07-26"/>
+ <output-file compare="Text">q02_serialize.txt</output-file>
+ </test-case>
+ <test-case name="serialize-q03" FilePath="Serialization" Creator="Christina Pavlopoulou">
+ <description>Serialize a date.</description>
+ <query name="q03_serialize" date="2016-07-26"/>
+ <output-file compare="Text">q03_serialize.txt</output-file>
+ </test-case>
+ <test-case name="serialize-q04" FilePath="Serialization" Creator="Christina Pavlopoulou">
+ <description>Serialize an xml node.</description>
+ <query name="q04_serialize" date="2016-07-26"/>
+ <output-file compare="Text">q04_serialize.txt</output-file>
+ </test-case>
+</test-group>