merge master
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/bf475170 Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/bf475170 Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/bf475170 Branch: refs/heads/master Commit: bf475170f4f86532dc0cf1b679a17080e423eb00 Parents: bb1fa8e Author: Preston Carman <[email protected]> Authored: Thu Jun 9 20:25:36 2016 -0700 Committer: Preston Carman <[email protected]> Committed: Thu Jun 9 20:25:36 2016 -0700 ---------------------------------------------------------------------- pom.xml | 41 +- vxquery-core/pom.xml | 31 +- .../accessors/jsonItem/ObjectPointable.java | 126 --- .../accessors/jsonitem/ArrayPointable.java | 16 + .../accessors/jsonitem/ObjectPointable.java | 126 +++ .../builders/jsonItem/ObjectBuilder.java | 39 - .../builders/jsonitem/AbstractJsonBuilder.java | 16 + .../builders/jsonitem/ArrayBuilder.java | 16 + .../builders/jsonitem/ObjectBuilder.java | 39 + .../vxquery/functions/builtin-functions.xml | 22 + .../apache/vxquery/index/IndexAttributes.java | 287 ++++++ .../vxquery/index/IndexDocumentBuilder.java | 882 +++++++++++++++++++ .../org/apache/vxquery/index/IndexElement.java | 42 + .../VXQueryCollectionOperatorDescriptor.java | 81 +- .../functions/index/CaseSensitiveAnalyzer.java | 144 +++ .../index/CaseSensitiveQueryParser.java | 42 + ...ctionFromIndexUnnestingEvaluatorFactory.java | 327 +++++++ .../IndexConstructorScalarEvaluatorFactory.java | 70 ++ .../functions/index/IndexConstructorUtil.java | 144 +++ .../runtime/functions/util/FunctionHelper.java | 7 +- .../vxquery/xmlparser/SAXContentHandler.java | 72 +- .../org/apache/vxquery/xmlparser/XMLParser.java | 2 +- .../apache/vxquery/datamodel/ArrayByteTest.java | 16 + .../java/org/apache/vxquery/xtest/MiniDFS.java | 7 +- .../org/apache/vxquery/xtest/VXQueryTest.java | 53 +- .../Indexing/createIndex.txt | 0 .../ExpectedTestResults/Indexing/useIndex1.txt | 2 + .../ExpectedTestResults/Indexing/useIndex2.txt | 1 + .../ExpectedTestResults/Indexing/useIndex3.txt | 1 + .../ExpectedTestResults/Indexing/useIndex4.txt | 1 + .../ExpectedTestResults/Indexing/useIndex5.txt | 3 + .../ExpectedTestResults/Indexing/useIndex6.txt | 2 + .../ExpectedTestResults/Indexing/useIndex7.txt | 3 + .../Queries/XQuery/Indexing/createIndex.xq | 20 + .../Queries/XQuery/Indexing/useIndex1.xq | 25 + .../Queries/XQuery/Indexing/useIndex2.xq | 24 + .../Queries/XQuery/Indexing/useIndex3.xq | 27 + .../Queries/XQuery/Indexing/useIndex4.xq | 24 + .../Queries/XQuery/Indexing/useIndex5.xq | 23 + .../Queries/XQuery/Indexing/useIndex6.xq | 23 + .../Queries/XQuery/Indexing/useIndex7.xq | 27 + .../src/test/resources/VXQueryCatalog.xml | 17 +- .../src/test/resources/cat/IndexingQueries.xml | 63 ++ 43 files changed, 2649 insertions(+), 285 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index dd51adf..a082505 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -475,20 +478,20 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> - <!-- We override the configuration plugin to override the descriptor - to use for building the source release zip. Specifically, we would like to - control the inclusions/exclusions. For example, we exclude the KEYS file + <!-- We override the configuration plugin to override the descriptor + to use for building the source release zip. Specifically, we would like to + control the inclusions/exclusions. For example, we exclude the KEYS file from the zip --> <executions> <execution> - <!-- Use this id to match the id mentioned in the assembly plugin configuration + <!-- Use this id to match the id mentioned in the assembly plugin configuration in the apache parent POM under the apache-release profile --> <id>source-release-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> - <!-- combine.self should be override to replace the configuration in + <!-- combine.self should be override to replace the configuration in the parent POM --> <configuration combine.self="override"> <runOnlyAtExecutionRoot>true</runOnlyAtExecutionRoot> @@ -550,6 +553,30 @@ </executions> </plugin> <plugin> + <groupId>org.apache.rat</groupId> + <artifactId>apache-rat-plugin</artifactId> + <version>0.11</version> + <executions> + <execution> + <phase>verify</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + <configuration> + <excludes> + <exclude>.gitignore</exclude> + <exclude>.rat-excludes</exclude> + <exclude>.project</exclude> + <exclude>.classpath</exclude> + <exclude>.basex</exclude> + <exclude>**/ExpectedTestResults/**</exclude> + <exclude>**/xqts.txt</exclude> + </excludes> + </configuration> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-site-plugin</artifactId> </plugin> @@ -626,7 +653,7 @@ <maxmemory>2g</maxmemory> </configuration> </plugin> - + </plugins> </reporting> http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/pom.xml ---------------------------------------------------------------------- diff --git a/vxquery-core/pom.xml b/vxquery-core/pom.xml index d8f5f53..56eb45f 100644 --- a/vxquery-core/pom.xml +++ b/vxquery-core/pom.xml @@ -266,7 +266,36 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> - + <dependency> + <artifactId>lucene-core</artifactId> + <groupId>org.apache.lucene</groupId> + <type>jar</type> + <version>5.5.1</version> + </dependency> + <dependency> + <artifactId>lucene-queryparser</artifactId> + <groupId>org.apache.lucene</groupId> + <type>jar</type> + <version>5.5.1</version> + </dependency> + <dependency> + <artifactId>lucene-analyzers-common</artifactId> + <groupId>org.apache.lucene</groupId> + <type>jar</type> + <version>5.5.1</version> + </dependency> + <dependency> + <artifactId>lucene-demo</artifactId> + <groupId>org.apache.lucene</groupId> + <type>jar</type> + <version>5.5.1</version> + </dependency> + <dependency> + <artifactId>lucene-backward-codecs</artifactId> + <groupId>org.apache.lucene</groupId> + <type>jar</type> + <version>5.5.1</version> + </dependency> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-mapreduce-client-core</artifactId> http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java deleted file mode 100644 index 9c714ec..0000000 --- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonItem/ObjectPointable.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * 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.datamodel.accessors.jsonitem; - -import java.io.IOException; - -import org.apache.hyracks.api.dataflow.value.ITypeTraits; -import org.apache.hyracks.data.std.api.AbstractPointable; -import org.apache.hyracks.data.std.api.IPointable; -import org.apache.hyracks.data.std.api.IPointableFactory; -import org.apache.hyracks.data.std.primitive.IntegerPointable; -import org.apache.hyracks.data.std.primitive.UTF8StringPointable; -import org.apache.hyracks.data.std.primitive.VoidPointable; -import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; -import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder; -import org.apache.vxquery.datamodel.values.ValueTag; -import org.apache.vxquery.runtime.functions.util.FunctionHelper; - -/** - * The datamodel of the JSON object is represented in this class: - * Byte 1: Value tag of object (109) - * Byte 2 to 5: number of key-value pairs in the object - * Next few bytes: Offsets for each key-value pair in the object in the order appearing in the json data - * Next bytes: The keys in the object each followed by the value of the key. Each key is a StringPointable and the value - * of the key will be the respective pointable starting with its valuetag. - */ -public class ObjectPointable extends AbstractPointable { - public static final IPointableFactory FACTORY = new IPointableFactory() { - private static final long serialVersionUID = 1L; - - @Override - public ITypeTraits getTypeTraits() { - return VoidPointable.TYPE_TRAITS; - } - - @Override - public IPointable createPointable() { - return new ObjectPointable(); - } - }; - private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); - private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); - private final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage(); - private final SequenceBuilder sb = new SequenceBuilder(); - private final UTF8StringPointable key = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable(); - - private static int getSlotValue(byte[] bytes, int start, int idx) { - return IntegerPointable.getInteger(bytes, getSlotArrayOffset(start) + idx * SLOT_SIZE); - } - - private static int getEntryCount(byte[] bytes, int start) { - return IntegerPointable.getInteger(bytes, start); - } - - private static int getKeyLength(byte[] b, int s) { - return UTF8StringPointable.getUTFLength(b, s) + 2; - } - - private static int getSlotArrayOffset(int start) { - return start + ENTRY_COUNT_SIZE; - } - - private static int getDataAreaOffset(byte[] bytes, int start) { - return getSlotArrayOffset(start) + getEntryCount(bytes, start) * SLOT_SIZE; - } - - public void getKeys(IPointable result) throws IOException { - abvs.reset(); - sb.reset(abvs); - int dataAreaOffset = getDataAreaOffset(bytes, start); - int entryCount = getEntryCount(); - int s; - for (int i = 0; i < entryCount; i++) { - s = dataAreaOffset + getRelativeEntryStartOffset(i); - key.set(bytes, s, getKeyLength(bytes, s)); - sb.addItem(ValueTag.XS_STRING_TAG, key); - } - sb.finish(); - result.set(abvs); - } - - public boolean getValue(UTF8StringPointable key, IPointable result) { - int dataAreaOffset = getDataAreaOffset(bytes, start); - int entryCount = getEntryCount(); - int start; - int length; - int i; - for (i = 0; i < entryCount; i++) { - start = dataAreaOffset + getRelativeEntryStartOffset(i); - length = getKeyLength(bytes, start); - if (FunctionHelper.arraysEqual(bytes, start, length, key.getByteArray(), key.getStartOffset(), - key.getLength())) { - result.set(bytes, start + length, getEntryLength(i) - length); - return true; - } - } - return false; - } - - private int getRelativeEntryStartOffset(int idx) { - return idx == 0 ? 0 : getSlotValue(bytes, start, idx - 1); - } - - private int getEntryLength(int idx) { - return getSlotValue(bytes, start, idx) - getRelativeEntryStartOffset(idx); - } - - public int getEntryCount() { - return getEntryCount(bytes, start); - } - -} http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ArrayPointable.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ArrayPointable.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ArrayPointable.java index 0b15604..462b4d6 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ArrayPointable.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ArrayPointable.java @@ -1,3 +1,19 @@ +/* + * 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.datamodel.accessors.jsonitem; import org.apache.hyracks.api.dataflow.value.ITypeTraits; http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ObjectPointable.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ObjectPointable.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ObjectPointable.java new file mode 100644 index 0000000..9c714ec --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/jsonitem/ObjectPointable.java @@ -0,0 +1,126 @@ +/* + * 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.datamodel.accessors.jsonitem; + +import java.io.IOException; + +import org.apache.hyracks.api.dataflow.value.ITypeTraits; +import org.apache.hyracks.data.std.api.AbstractPointable; +import org.apache.hyracks.data.std.api.IPointable; +import org.apache.hyracks.data.std.api.IPointableFactory; +import org.apache.hyracks.data.std.primitive.IntegerPointable; +import org.apache.hyracks.data.std.primitive.UTF8StringPointable; +import org.apache.hyracks.data.std.primitive.VoidPointable; +import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; +import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder; +import org.apache.vxquery.datamodel.values.ValueTag; +import org.apache.vxquery.runtime.functions.util.FunctionHelper; + +/** + * The datamodel of the JSON object is represented in this class: + * Byte 1: Value tag of object (109) + * Byte 2 to 5: number of key-value pairs in the object + * Next few bytes: Offsets for each key-value pair in the object in the order appearing in the json data + * Next bytes: The keys in the object each followed by the value of the key. Each key is a StringPointable and the value + * of the key will be the respective pointable starting with its valuetag. + */ +public class ObjectPointable extends AbstractPointable { + public static final IPointableFactory FACTORY = new IPointableFactory() { + private static final long serialVersionUID = 1L; + + @Override + public ITypeTraits getTypeTraits() { + return VoidPointable.TYPE_TRAITS; + } + + @Override + public IPointable createPointable() { + return new ObjectPointable(); + } + }; + private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); + private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength(); + private final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage(); + private final SequenceBuilder sb = new SequenceBuilder(); + private final UTF8StringPointable key = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable(); + + private static int getSlotValue(byte[] bytes, int start, int idx) { + return IntegerPointable.getInteger(bytes, getSlotArrayOffset(start) + idx * SLOT_SIZE); + } + + private static int getEntryCount(byte[] bytes, int start) { + return IntegerPointable.getInteger(bytes, start); + } + + private static int getKeyLength(byte[] b, int s) { + return UTF8StringPointable.getUTFLength(b, s) + 2; + } + + private static int getSlotArrayOffset(int start) { + return start + ENTRY_COUNT_SIZE; + } + + private static int getDataAreaOffset(byte[] bytes, int start) { + return getSlotArrayOffset(start) + getEntryCount(bytes, start) * SLOT_SIZE; + } + + public void getKeys(IPointable result) throws IOException { + abvs.reset(); + sb.reset(abvs); + int dataAreaOffset = getDataAreaOffset(bytes, start); + int entryCount = getEntryCount(); + int s; + for (int i = 0; i < entryCount; i++) { + s = dataAreaOffset + getRelativeEntryStartOffset(i); + key.set(bytes, s, getKeyLength(bytes, s)); + sb.addItem(ValueTag.XS_STRING_TAG, key); + } + sb.finish(); + result.set(abvs); + } + + public boolean getValue(UTF8StringPointable key, IPointable result) { + int dataAreaOffset = getDataAreaOffset(bytes, start); + int entryCount = getEntryCount(); + int start; + int length; + int i; + for (i = 0; i < entryCount; i++) { + start = dataAreaOffset + getRelativeEntryStartOffset(i); + length = getKeyLength(bytes, start); + if (FunctionHelper.arraysEqual(bytes, start, length, key.getByteArray(), key.getStartOffset(), + key.getLength())) { + result.set(bytes, start + length, getEntryLength(i) - length); + return true; + } + } + return false; + } + + private int getRelativeEntryStartOffset(int idx) { + return idx == 0 ? 0 : getSlotValue(bytes, start, idx - 1); + } + + private int getEntryLength(int idx) { + return getSlotValue(bytes, start, idx) - getRelativeEntryStartOffset(idx); + } + + public int getEntryCount() { + return getEntryCount(bytes, start); + } + +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonItem/ObjectBuilder.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonItem/ObjectBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonItem/ObjectBuilder.java deleted file mode 100644 index 000110a..0000000 --- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonItem/ObjectBuilder.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.datamodel.builders.jsonitem; - -import java.io.IOException; - -import org.apache.hyracks.data.std.api.IValueReference; -import org.apache.hyracks.data.std.primitive.UTF8StringPointable; -import org.apache.vxquery.datamodel.builders.base.IBuilder; -import org.apache.vxquery.datamodel.values.ValueTag; - -public class ObjectBuilder extends AbstractJsonBuilder implements IBuilder { - - @Override - public int getValueTag() { - return ValueTag.OBJECT_TAG; - } - - public void addItem(UTF8StringPointable key, IValueReference value) throws IOException { - dataArea.getDataOutput().write(key.getByteArray(), key.getStartOffset(), key.getLength()); - dataArea.getDataOutput().write(value.getByteArray(), value.getStartOffset(), value.getLength()); - slots.append(dataArea.getLength()); - } - -} http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/AbstractJsonBuilder.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/AbstractJsonBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/AbstractJsonBuilder.java index e5a11ed..75534c3 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/AbstractJsonBuilder.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/AbstractJsonBuilder.java @@ -1,3 +1,19 @@ +/* + * 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.datamodel.builders.jsonitem; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ArrayBuilder.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ArrayBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ArrayBuilder.java index 4ef642f..970071d 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ArrayBuilder.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ArrayBuilder.java @@ -1,3 +1,19 @@ +/* + * 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.datamodel.builders.jsonitem; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ObjectBuilder.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ObjectBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ObjectBuilder.java new file mode 100644 index 0000000..000110a --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/builders/jsonitem/ObjectBuilder.java @@ -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.datamodel.builders.jsonitem; + +import java.io.IOException; + +import org.apache.hyracks.data.std.api.IValueReference; +import org.apache.hyracks.data.std.primitive.UTF8StringPointable; +import org.apache.vxquery.datamodel.builders.base.IBuilder; +import org.apache.vxquery.datamodel.values.ValueTag; + +public class ObjectBuilder extends AbstractJsonBuilder implements IBuilder { + + @Override + public int getValueTag() { + return ValueTag.OBJECT_TAG; + } + + public void addItem(UTF8StringPointable key, IValueReference value) throws IOException { + dataArea.getDataOutput().write(key.getByteArray(), key.getStartOffset(), key.getLength()); + dataArea.getDataOutput().write(value.getByteArray(), value.getStartOffset(), value.getLength()); + slots.append(dataArea.getLength()); + } + +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/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 3b9371d..8379ccf 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 @@ -128,6 +128,28 @@ <!-- Collection operator is added during the rewrite rules phase. --> </function> + <!-- fn:build-index-on-collection($arg as xs:string?, $indexFolder as xs:string?) as node()* --> + <function name="fn:build-index-on-collection"> + <param name="collection-folder" type="xs:string?"/> + <param name="index-folder" type="xs:string?"/> + <return type="node()*"/> + <runtime type="scalar" class="org.apache.vxquery.runtime.functions.index.IndexConstructorScalarEvaluatorFactory"/> + </function> + + <!-- fn:collection-from-index($indexfolder as xs:string?, $elementpath as xs:string?) as node()* --> + <function name="fn:collection-from-index"> + <param name="index-folder" type="xs:string?"/> + <param name="element-path" type="xs:string?"/> + <return type="node()*"/> + <runtime type="unnesting" class="org.apache.vxquery.runtime.functions.index.CollectionFromIndexUnnestingEvaluatorFactory"/> + <property type="DocumentOrder" class="org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.InputPropertyPropagationPolicy"> + <argument value="0"/> + </property> + <property type="UniqueNodes" class="org.apache.vxquery.compiler.rewriter.rules.propagationpolicies.InputPropertyPropagationPolicy"> + <argument value="0"/> + </property> + </function> + <!-- fn:collection-with-tag($arg1 as xs:string?, $arg2 as xs:string?) as node()* --> <function name="fn:collection-with-tag"> <param name="arg1" type="xs:string?"/> http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java new file mode 100644 index 0000000..cf8e3c0 --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexAttributes.java @@ -0,0 +1,287 @@ +/* + * 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.index; + +import java.util.List; + +import org.xml.sax.Attributes; + +public class IndexAttributes implements Attributes { + int length; + + List<String> names; + List<String> values; + List<String> uris; + List<String> localnames; + List<String> types; + List<String> qnames; + + public IndexAttributes(List<String> n, List<String> v, List<String> u, List<String> l, List<String> t, + List<String> q) { + length = n.size(); + names = n; + values = v; + uris = u; + localnames = l; + types = t; + qnames = q; + } + + /** + * Return the number of attributes in the list. + * <p> + * Once you know the number of attributes, you can iterate through the list. + * </p> + * + * @return The number of attributes in the list. + * @see #getURI(int) + * @see #getLocalName(int) + * @see #getQName(int) + * @see #getType(int) + * @see #getValue(int) + */ + @Override + public int getLength() { + return length; + } + + /** + * Look up an attribute's Namespace URI by index. + * + * @param index + * The attribute index (zero-based). + * @return The Namespace URI, or the empty string if none + * is available, or null if the index is out of + * range. + * @see #getLength + */ + @Override + public String getURI(int index) { + return uris.get(index); + } + + /** + * Look up an attribute's local name by index. + * + * @param index + * The attribute index (zero-based). + * @return The local name, or the empty string if Namespace + * processing is not being performed, or null + * if the index is out of range. + * @see #getLength + */ + @Override + public String getLocalName(int index) { + return localnames.get(index); + } + + /** + * Look up an attribute's XML qualified (prefixed) name by index. + * + * @param index + * The attribute index (zero-based). + * @return The XML qualified name, or the empty string + * if none is available, or null if the index + * is out of range. + * @see #getLength + */ + @Override + public String getQName(int index) { + return qnames.get(index); + } + + /** + * Look up an attribute's type by index. + * <p> + * The attribute type is one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", + * "ENTITIES", or "NOTATION" (always in upper case). + * </p> + * <p> + * If the parser has not read a declaration for the attribute, or if the parser does not report attribute types, + * then it must return the value "CDATA" as stated in the XML 1.0 Recommendation (clause 3.3.3, + * "Attribute-Value Normalization"). + * </p> + * <p> + * For an enumerated attribute that is not a notation, the parser will report the type as "NMTOKEN". + * </p> + * + * @param index + * The attribute index (zero-based). + * @return The attribute's type as a string, or null if the + * index is out of range. + * @see #getLength + */ + @Override + public String getType(int index) { + return types.get(index); + } + + /** + * Look up an attribute's value by index. + * <p> + * If the attribute value is a list of tokens (IDREFS, ENTITIES, or NMTOKENS), the tokens will be concatenated into + * a single string with each token separated by a single space. + * </p> + * + * @param index + * The attribute index (zero-based). + * @return The attribute's value as a string, or null if the + * index is out of range. + * @see #getLength + */ + @Override + public String getValue(int index) { + return values.get(index); + } + + //////////////////////////////////////////////////////////////////// + // Name-based query. + //////////////////////////////////////////////////////////////////// + + /** + * Look up the index of an attribute by Namespace name. + * + * @param uri + * The Namespace URI, or the empty string if + * the name has no Namespace URI. + * @param localName + * The attribute's local name. + * @return The index of the attribute, or -1 if it does not + * appear in the list. + */ + @Override + public int getIndex(String uri, String localName) { + for (int i = 0; i < length; i++) { + if (localnames.get(i).equals(localName) && uris.get(i).equals(uri)) { + return i; + } + } + return -1; + } + + /** + * Look up the index of an attribute by XML qualified (prefixed) name. + * + * @param qName + * The qualified (prefixed) name. + * @return The index of the attribute, or -1 if it does not + * appear in the list. + */ + @Override + public int getIndex(String qName) { + for (int i = 0; i < length; i++) { + if (qnames.get(i).equals(qName)) { + return i; + } + } + return -1; + } + + /** + * Look up an attribute's type by Namespace name. + * <p> + * See {@link #getType(int) getType(int)} for a description of the possible types. + * </p> + * + * @param uri + * The Namespace URI, or the empty String if the + * name has no Namespace URI. + * @param localName + * The local name of the attribute. + * @return The attribute type as a string, or null if the + * attribute is not in the list or if Namespace + * processing is not being performed. + */ + @Override + public String getType(String uri, String localName) { + for (int i = 0; i < length; i++) { + if (localnames.get(i).equals(localName) && uris.get(i).equals(uri)) { + return types.get(i); + } + } + return null; + } + + /** + * Look up an attribute's type by XML qualified (prefixed) name. + * <p> + * See {@link #getType(int) getType(int)} for a description of the possible types. + * </p> + * + * @param qName + * The XML qualified name. + * @return The attribute type as a string, or null if the + * attribute is not in the list or if qualified names + * are not available. + */ + @Override + public String getType(String qName) { + for (int i = 0; i < length; i++) { + if (qnames.get(i).equals(qName)) { + return types.get(i); + } + } + return null; + } + + /** + * Look up an attribute's value by Namespace name. + * <p> + * See {@link #getValue(int) getValue(int)} for a description of the possible values. + * </p> + * + * @param uri + * The Namespace URI, or the empty String if the + * name has no Namespace URI. + * @param localName + * The local name of the attribute. + * @return The attribute value as a string, or null if the + * attribute is not in the list. + */ + @Override + public String getValue(String uri, String localName) { + for (int i = 0; i < length; i++) { + if (localnames.get(i).equals(localName) && uris.get(i).equals(uri)) { + return values.get(i); + } + } + return null; + } + + /** + * Look up an attribute's value by XML qualified (prefixed) name. + * <p> + * See {@link #getValue(int) getValue(int)} for a description of the possible values. + * </p> + * + * @param qName + * The XML qualified name. + * @return The attribute value as a string, or null if the + * attribute is not in the list or if qualified names + * are not available. + */ + @Override + public String getValue(String qName) { + for (int i = 0; i < length; i++) { + if (qnames.get(i).equals(qName)) { + return values.get(i); + } + } + return null; + } + +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java new file mode 100644 index 0000000..2884097 --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexDocumentBuilder.java @@ -0,0 +1,882 @@ +/* + * 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.index; + +import java.io.DataOutput; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.apache.hyracks.data.std.api.IPointable; +import org.apache.hyracks.data.std.primitive.BooleanPointable; +import org.apache.hyracks.data.std.primitive.BytePointable; +import org.apache.hyracks.data.std.primitive.DoublePointable; +import org.apache.hyracks.data.std.primitive.FloatPointable; +import org.apache.hyracks.data.std.primitive.IntegerPointable; +import org.apache.hyracks.data.std.primitive.LongPointable; +import org.apache.hyracks.data.std.primitive.ShortPointable; +import org.apache.hyracks.data.std.primitive.UTF8StringPointable; +import org.apache.hyracks.data.std.primitive.VoidPointable; +import org.apache.hyracks.data.std.util.ArrayBackedValueStorage; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.StringField; +import org.apache.lucene.index.IndexWriter; +import org.apache.vxquery.datamodel.accessors.PointablePool; +import org.apache.vxquery.datamodel.accessors.PointablePoolFactory; +import org.apache.vxquery.datamodel.accessors.SequencePointable; +import org.apache.vxquery.datamodel.accessors.TaggedValuePointable; +import org.apache.vxquery.datamodel.accessors.atomic.CodedQNamePointable; +import org.apache.vxquery.datamodel.accessors.atomic.XSBinaryPointable; +import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable; +import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable; +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.nodes.AttributeNodePointable; +import org.apache.vxquery.datamodel.accessors.nodes.DocumentNodePointable; +import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable; +import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable; +import org.apache.vxquery.datamodel.accessors.nodes.TextOrCommentNodePointable; +import org.apache.vxquery.datamodel.values.ValueTag; +import org.apache.vxquery.runtime.functions.cast.CastToStringOperation; +import org.apache.vxquery.serializer.XMLSerializer; + +public class IndexDocumentBuilder extends XMLSerializer { + private final IPointable treePointable; + + private final PointablePool pp; + private NodeTreePointable ntp; + + private final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage(); + private final DataOutput dOut = abvs.getDataOutput(); + private final CastToStringOperation castToString = new CastToStringOperation(); + private final Document doc; + private final List<ComplexItem> results; + + private final byte[] bstart; + private final int sstart; + private final int lstart; + private final IndexWriter writer; + + class ComplexItem { + public final StringField sf; + public final String id; + + public ComplexItem(StringField sfin, String idin) { + sf = sfin; + id = idin; + } + } + + //TODO: Handle Processing Instructions, PrefixedNames, and Namepsace entries + public IndexDocumentBuilder(IPointable tree, IndexWriter inWriter) { + this.treePointable = tree; + writer = inWriter; + + //convert to tagged value pointable + TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable(); + tvp.set(treePointable.getByteArray(), 0, treePointable.getLength()); + + //get bytes and info from doc pointer + bstart = tvp.getByteArray(); + sstart = tvp.getStartOffset(); + lstart = tvp.getLength(); + + doc = new Document(); + + results = new ArrayList<ComplexItem>(); + + pp = PointablePoolFactory.INSTANCE.createPointablePool(); + } + + //This is a wrapper to start indexing using the functions adapted from XMLSerializer + public void printStart() throws IOException { + + print(bstart, sstart, lstart, "0", ""); + for (int i = 1; i < results.size() - 1; i++) { + //TODO: Since each doc is a file, + //we can only handle files + //small enough to fit in memory + doc.add(results.get(i).sf); + } + writer.addDocument(doc); + + } + + //adapted from XMLSerializer. The following functions are used to traverse the TaggedValuePointable + //and create the index elements, then create the item for the lucene index + public void print(byte[] b, int s, int l, String deweyId, String epath) throws IOException { + TaggedValuePointable tvp = pp.takeOne(TaggedValuePointable.class); + try { + tvp.set(b, s, l); + printTaggedValuePointable(tvp, deweyId, epath); + } finally { + pp.giveBack(tvp); + } + } + + private void printTaggedValuePointable(TaggedValuePointable tvp, String deweyId, String epath) throws IOException { + byte tag = tvp.getTag(); + String type = "text"; + String[] result = { "", "" }; + switch ((int) tag) { + case ValueTag.XS_ANY_URI_TAG: + result = printString(tvp, epath); + break; + + case ValueTag.XS_BASE64_BINARY_TAG: + result = printBase64Binary(tvp, epath); + break; + + case ValueTag.XS_BOOLEAN_TAG: + result = printBoolean(tvp, epath); + break; + + case ValueTag.XS_DATE_TAG: + result = printDate(tvp, epath); + break; + + case ValueTag.XS_DATETIME_TAG: + result = printDateTime(tvp, epath); + break; + + case ValueTag.XS_DAY_TIME_DURATION_TAG: + result = printDTDuration(tvp, epath); + break; + + case ValueTag.XS_BYTE_TAG: + result = printByte(tvp, epath); + break; + + case ValueTag.XS_DECIMAL_TAG: + result = printDecimal(tvp, epath); + break; + + case ValueTag.XS_DOUBLE_TAG: + result = printDouble(tvp, epath); + break; + + case ValueTag.XS_DURATION_TAG: + result = printDuration(tvp, epath); + break; + + case ValueTag.XS_FLOAT_TAG: + result = printFloat(tvp, epath); + break; + + case ValueTag.XS_G_DAY_TAG: + result = printGDay(tvp, epath); + break; + + case ValueTag.XS_G_MONTH_TAG: + result = printGMonth(tvp, epath); + break; + + case ValueTag.XS_G_MONTH_DAY_TAG: + result = printGMonthDay(tvp, epath); + break; + + case ValueTag.XS_G_YEAR_TAG: + result = printGYear(tvp, epath); + break; + + case ValueTag.XS_G_YEAR_MONTH_TAG: + result = printGYearMonth(tvp, epath); + break; + + case ValueTag.XS_HEX_BINARY_TAG: + result = printHexBinary(tvp, epath); + break; + + case ValueTag.XS_INT_TAG: + case ValueTag.XS_UNSIGNED_SHORT_TAG: + result = printInt(tvp, epath); + break; + + case ValueTag.XS_INTEGER_TAG: + case ValueTag.XS_LONG_TAG: + case ValueTag.XS_NEGATIVE_INTEGER_TAG: + case ValueTag.XS_NON_POSITIVE_INTEGER_TAG: + case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG: + case ValueTag.XS_POSITIVE_INTEGER_TAG: + case ValueTag.XS_UNSIGNED_INT_TAG: + case ValueTag.XS_UNSIGNED_LONG_TAG: + result = printInteger(tvp, epath); + break; + + case ValueTag.XS_NOTATION_TAG: + result = printString(tvp, epath); + break; + + case ValueTag.XS_QNAME_TAG: + result = printQName(tvp, epath); + break; + + case ValueTag.XS_SHORT_TAG: + case ValueTag.XS_UNSIGNED_BYTE_TAG: + result = printShort(tvp, epath); + break; + + case ValueTag.XS_STRING_TAG: + case ValueTag.XS_NORMALIZED_STRING_TAG: + case ValueTag.XS_TOKEN_TAG: + case ValueTag.XS_LANGUAGE_TAG: + case ValueTag.XS_NMTOKEN_TAG: + case ValueTag.XS_NAME_TAG: + case ValueTag.XS_NCNAME_TAG: + case ValueTag.XS_ID_TAG: + case ValueTag.XS_IDREF_TAG: + case ValueTag.XS_ENTITY_TAG: + result = printString(tvp, epath); + break; + + case ValueTag.XS_TIME_TAG: + result = printTime(tvp, epath); + break; + + case ValueTag.XS_UNTYPED_ATOMIC_TAG: + result = printString(tvp, epath); + break; + + case ValueTag.XS_YEAR_MONTH_DURATION_TAG: + result = printYMDuration(tvp, epath); + break; + + case ValueTag.ATTRIBUTE_NODE_TAG: + type = "attribute"; + printAttributeNode(tvp, deweyId, epath); + break; + + case ValueTag.TEXT_NODE_TAG: + type = "textnode"; + result = printTextNode(tvp, epath); + break; + + case ValueTag.COMMENT_NODE_TAG: + type = "comment"; + result = printCommentNode(tvp, epath); + break; + + case ValueTag.SEQUENCE_TAG: + type = "sequence"; + printSequence(tvp, deweyId, epath); + break; + + case ValueTag.NODE_TREE_TAG: + type = "tree"; + printNodeTree(tvp, deweyId, epath); + break; + + case ValueTag.ELEMENT_NODE_TAG: + type = "element"; + printElementNode(tvp, deweyId, epath); + break; + + case ValueTag.DOCUMENT_NODE_TAG: + type = "doc"; + buildIndexItem(deweyId, type, result, epath); + printDocumentNode(tvp, deweyId, epath); + break; + + default: + throw new UnsupportedOperationException("Encountered tag: " + tvp.getTag()); + } + if ((int) tag != ValueTag.DOCUMENT_NODE_TAG && (int) tag != ValueTag.SEQUENCE_TAG + && (int) tag != ValueTag.NODE_TREE_TAG && (int) tag != ValueTag.ELEMENT_NODE_TAG + && (int) tag != ValueTag.ATTRIBUTE_NODE_TAG) { + buildIndexItem(deweyId, type, result, epath); + } + + } + + private void buildIndexItem(String deweyId, String type, String[] result, String parentPath) { + //Create an Index element + IndexElement test = new IndexElement(deweyId, type, result[1]); + + String path = test.epath(); + + path = StringUtils.replace(path, parentPath, ""); + //Parser doesn't like / so paths are saved as name.name.... + String luceneParentPath = parentPath.replaceAll("/", "."); + + if (!type.equals("doc")) { + path = path.replaceFirst("/", ":"); + } else { + luceneParentPath = ""; + } + //Parser doesn't like / so paths are saved as name.name.... + path = path.replaceAll("/", "."); + //Add this element to the array (they will be added in reverse order. + String fullItem = luceneParentPath + path + "." + test.type(); + + results.add(new ComplexItem(new StringField("item", fullItem, Field.Store.YES), test.id())); + } + + private String[] printDecimal(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDecimalPointable dp = pp.takeOne(XSDecimalPointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertDecimal(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private void printNodeTree(TaggedValuePointable tvp, String deweyId, String path) throws IOException { + if (ntp != null) { + throw new IllegalStateException("Nested NodeTreePointable found"); + } + ntp = pp.takeOne(NodeTreePointable.class); + TaggedValuePointable rootTVP = pp.takeOne(TaggedValuePointable.class); + try { + tvp.getValue(ntp); + ntp.getRootNode(rootTVP); + printTaggedValuePointable(rootTVP, deweyId, path); + } finally { + pp.giveBack(rootTVP); + pp.giveBack(ntp); + ntp = null; + } + } + + private String[] printCommentNode(TaggedValuePointable tvp, String path) { + String[] result = { "", path }; + TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class); + UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class); + try { + tvp.getValue(tcnp); + tcnp.getValue(ntp, utf8sp); + + result = printString(utf8sp, path); + + } finally { + pp.giveBack(tcnp); + pp.giveBack(utf8sp); + } + return result; + } + + private String[] printTextNode(TaggedValuePointable tvp, String path) { + String[] result = { "", path }; + TextOrCommentNodePointable tcnp = pp.takeOne(TextOrCommentNodePointable.class); + UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class); + try { + tvp.getValue(tcnp); + tcnp.getValue(ntp, utf8sp); + result = printString(utf8sp, path); + } finally { + pp.giveBack(tcnp); + pp.giveBack(utf8sp); + } + return result; + } + + private void printAttributeNode(TaggedValuePointable tvp, String deweyId, String path) throws IOException { + String[] result = { "", path }; + AttributeNodePointable anp = pp.takeOne(AttributeNodePointable.class); + CodedQNamePointable cqp = pp.takeOne(CodedQNamePointable.class); + UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class); + TaggedValuePointable valueTVP = pp.takeOne(TaggedValuePointable.class); + try { + tvp.getValue(anp); + anp.getName(cqp); + result = printPrefixedQName(cqp, utf8sp, path); + buildIndexItem(deweyId, "attribute", result, path); + + anp.getValue(ntp, valueTVP); + + String attributeValueId = deweyId + ".0"; + printTaggedValuePointable(valueTVP, attributeValueId, result[1]); + + } finally { + pp.giveBack(valueTVP); + pp.giveBack(utf8sp); + pp.giveBack(anp); + pp.giveBack(cqp); + } + } + + private void printElementNode(TaggedValuePointable tvp, String deweyId, String path) throws IOException { + String[] result = { "", path }; + ElementNodePointable enp = pp.takeOne(ElementNodePointable.class); + CodedQNamePointable cqp = pp.takeOne(CodedQNamePointable.class); + UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class); + SequencePointable seqp = pp.takeOne(SequencePointable.class); + try { + tvp.getValue(enp); + enp.getName(cqp); + result = printPrefixedQName(cqp, utf8sp, path); + buildIndexItem(deweyId, "element", result, path); + + enp.getAttributeSequence(ntp, seqp); + int numattributes = 0; + if (seqp.getByteArray() != null && seqp.getEntryCount() > 0) { + printSequence(seqp, deweyId, 0, result[1]); + numattributes = seqp.getEntryCount(); + } + + enp.getChildrenSequence(ntp, seqp); + if (seqp.getByteArray() != null) { + printSequence(seqp, deweyId, numattributes, result[1]); + } + + } finally { + pp.giveBack(seqp); + pp.giveBack(utf8sp); + pp.giveBack(cqp); + pp.giveBack(enp); + } + } + + private String[] printPrefixedQName(CodedQNamePointable cqp, UTF8StringPointable utf8sp, String path) { + ntp.getString(cqp.getLocalCode(), utf8sp); + return printString(utf8sp, path); + } + + private void printDocumentNode(TaggedValuePointable tvp, String deweyId, String path) throws IOException { + DocumentNodePointable dnp = pp.takeOne(DocumentNodePointable.class); + SequencePointable seqp = pp.takeOne(SequencePointable.class); + try { + tvp.getValue(dnp); + dnp.getContent(ntp, seqp); + printSequence(seqp, deweyId, 0, path); + } finally { + pp.giveBack(seqp); + pp.giveBack(dnp); + } + } + + private void printSequence(TaggedValuePointable tvp, String deweyId, String path) throws IOException { + SequencePointable seqp = pp.takeOne(SequencePointable.class); + try { + tvp.getValue(seqp); + printSequence(seqp, deweyId, 0, path); + } finally { + pp.giveBack(seqp); + } + } + + private void printSequence(SequencePointable seqp, String deweyId, int addon, String path) throws IOException { + VoidPointable vp = pp.takeOne(VoidPointable.class); + try { + int len = seqp.getEntryCount(); + for (int i = 0; i < len; ++i) { + int location = i + addon; + String childID = deweyId + "." + Integer.toString(location); + seqp.getEntry(i, vp); + print(vp.getByteArray(), vp.getStartOffset(), vp.getLength(), childID, path); + } + } finally { + pp.giveBack(vp); + } + } + + private String[] printBase64Binary(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSBinaryPointable bp = pp.takeOne(XSBinaryPointable.class); + try { + tvp.getValue(bp); + abvs.reset(); + castToString.convertBase64Binary(bp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(bp); + } + return result; + } + + private String[] printBoolean(TaggedValuePointable tvp, String path) { + String[] result = { "", path }; + BooleanPointable bp = pp.takeOne(BooleanPointable.class); + try { + tvp.getValue(bp); + result[0] = Boolean.toString(bp.getBoolean()); + result[1] = path + "/" + result[0]; + } finally { + pp.giveBack(bp); + } + return result; + } + + private String[] printByte(TaggedValuePointable tvp, String path) { + String[] result = { "", path }; + BytePointable bp = pp.takeOne(BytePointable.class); + try { + tvp.getValue(bp); + result[0] = Byte.toString(bp.byteValue()); + result[1] = path + "/" + result[0]; + } finally { + pp.giveBack(bp); + } + return result; + } + + private String[] printDouble(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + DoublePointable dp = pp.takeOne(DoublePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertDouble(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printDate(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDatePointable dp = pp.takeOne(XSDatePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertDate(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printDateTime(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDateTimePointable dtp = pp.takeOne(XSDateTimePointable.class); + try { + tvp.getValue(dtp); + abvs.reset(); + castToString.convertDatetime(dtp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dtp); + } + return result; + } + + private String[] printDTDuration(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + LongPointable lp = pp.takeOne(LongPointable.class); + try { + tvp.getValue(lp); + abvs.reset(); + castToString.convertDTDuration(lp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(lp); + } + return result; + } + + private String[] printDuration(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDurationPointable dp = pp.takeOne(XSDurationPointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertDuration(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printFloat(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + FloatPointable fp = pp.takeOne(FloatPointable.class); + try { + tvp.getValue(fp); + abvs.reset(); + castToString.convertFloat(fp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(fp); + } + return result; + } + + private String[] printGDay(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDatePointable dp = pp.takeOne(XSDatePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertGDay(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printGMonth(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDatePointable dp = pp.takeOne(XSDatePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertGMonth(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printGMonthDay(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDatePointable dp = pp.takeOne(XSDatePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertGMonthDay(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printGYear(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDatePointable dp = pp.takeOne(XSDatePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertGYear(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printGYearMonth(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSDatePointable dp = pp.takeOne(XSDatePointable.class); + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertGYearMonth(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printHexBinary(TaggedValuePointable tvp, String path) throws IOException { + String[] result = { "", path }; + XSBinaryPointable bp = pp.takeOne(XSBinaryPointable.class); + try { + tvp.getValue(bp); + abvs.reset(); + castToString.convertHexBinary(bp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(bp); + } + return result; + } + + private String[] printInt(TaggedValuePointable tvp, String path) { + String[] result = { "", path }; + IntegerPointable ip = pp.takeOne(IntegerPointable.class); + try { + tvp.getValue(ip); + result[0] = Integer.toString(ip.intValue()); + result[1] = path + "/" + result[0]; + } finally { + pp.giveBack(ip); + } + return result; + } + + private String[] printInteger(TaggedValuePointable tvp, String path) { + String[] result = { "", path }; + LongPointable lp = pp.takeOne(LongPointable.class); + try { + tvp.getValue(lp); + result[0] = Long.toString(lp.longValue()); + result[1] = path + "/" + result[0]; + } finally { + pp.giveBack(lp); + } + return result; + } + + private String[] printShort(TaggedValuePointable tvp, String path) { + ShortPointable sp = pp.takeOne(ShortPointable.class); + String[] result = { "", path }; + try { + tvp.getValue(sp); + result[0] = Short.toString(sp.shortValue()); + result[1] = path + "/" + result[0]; + } finally { + pp.giveBack(sp); + } + return result; + } + + private String[] printQName(TaggedValuePointable tvp, String path) throws IOException { + XSQNamePointable dp = pp.takeOne(XSQNamePointable.class); + String[] result = { "", path }; + try { + tvp.getValue(dp); + abvs.reset(); + castToString.convertQName(dp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(dp); + } + return result; + } + + private String[] printStringAbvs(String path) { + UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class); + String[] result = { "", path }; + try { + utf8sp.set(abvs.getByteArray(), abvs.getStartOffset() + 1, abvs.getLength() - 1); + result = printString(utf8sp, path); + } finally { + pp.giveBack(utf8sp); + } + return result; + } + + private String[] printString(TaggedValuePointable tvp, String path) { + UTF8StringPointable utf8sp = pp.takeOne(UTF8StringPointable.class); + String[] result = { "", path }; + try { + tvp.getValue(utf8sp); + result = printString(utf8sp, path); + } finally { + pp.giveBack(utf8sp); + } + return result; + } + + private String[] printString(UTF8StringPointable utf8sp, String path) { + int utfLen = utf8sp.getUTFLength(); + int offset = 2; + String[] result = { "", path }; + while (utfLen > 0) { + char c = utf8sp.charAt(offset); + switch (c) { + case '<': + result[0] += "<"; + break; + + case '>': + result[0] += ">"; + break; + + case '&': + result[0] += "&"; + break; + + case '"': + result[0] += """; + break; + + case '\'': + result[0] += "'"; + break; + + default: + result[0] += Character.toString(c); + break; + } + int cLen = UTF8StringPointable.getModifiedUTF8Len(c); + offset += cLen; + utfLen -= cLen; + + } + result[1] = path + "/" + result[0]; + return result; + } + + private String[] printTime(TaggedValuePointable tvp, String path) throws IOException { + XSTimePointable tp = pp.takeOne(XSTimePointable.class); + String[] result = { "", path }; + try { + tvp.getValue(tp); + abvs.reset(); + castToString.convertTime(tp, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(tp); + } + return result; + } + + private String[] printYMDuration(TaggedValuePointable tvp, String path) throws IOException { + IntegerPointable ip = pp.takeOne(IntegerPointable.class); + String[] result = { "", path }; + try { + tvp.getValue(ip); + abvs.reset(); + castToString.convertYMDuration(ip, dOut); + result = printStringAbvs(path); + } catch (Exception e) { + throw new IOException(e); + } finally { + pp.giveBack(ip); + } + return result; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/index/IndexElement.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/index/IndexElement.java b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexElement.java new file mode 100644 index 0000000..d2487a5 --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/index/IndexElement.java @@ -0,0 +1,42 @@ +/* +* 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.index; + +public class IndexElement { + private String id; + private String type; + private String elementpath; + + public IndexElement(String id, String type, String elementpath) { + this.id = id; + this.type = type; + this.elementpath = elementpath; + } + + public String id() { + return id; + } + + public String type() { + return type; + } + + public String epath() { + return elementpath; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/vxquery/blob/bf475170/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java index b8dca63..ef51cee 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryCollectionOperatorDescriptor.java @@ -18,8 +18,6 @@ package org.apache.vxquery.metadata; import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.nio.ByteBuffer; @@ -31,8 +29,6 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import javax.xml.parsers.ParserConfigurationException; - import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.commons.lang.StringUtils; @@ -67,7 +63,6 @@ import org.apache.vxquery.hdfs2.HDFSFunctions; import org.apache.vxquery.xmlparser.ITreeNodeIdProvider; import org.apache.vxquery.xmlparser.TreeNodeIdProvider; import org.apache.vxquery.xmlparser.XMLParser; -import org.xml.sax.SAXException; public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityOperatorDescriptor { private static final long serialVersionUID = 1L; @@ -179,50 +174,34 @@ public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityO for (int i = 0; i < size; i++) { //read split context = ctxFactory.createContext(job.getConfiguration(), i); - try { - reader = inputFormat.createRecordReader(inputSplits.get(i), context); - reader.initialize(inputSplits.get(i), context); - while (reader.nextKeyValue()) { - value = reader.getCurrentValue().toString(); - //Split value if it contains more than one item with the tag - if (StringUtils.countMatches(value, tag) > 1) { - String items[] = value.split(tag); - for (String item : items) { - if (item.length() > 0) { - item = START_TAG + tag + item; - stream = new ByteArrayInputStream( - item.getBytes(StandardCharsets.UTF_8)); - parser.parseHDFSElements(stream, writer, fta, i); - } + + reader = inputFormat.createRecordReader(inputSplits.get(i), context); + reader.initialize(inputSplits.get(i), context); + while (reader.nextKeyValue()) { + value = reader.getCurrentValue().toString(); + //Split value if it contains more than one item with the tag + if (StringUtils.countMatches(value, tag) > 1) { + String items[] = value.split(tag); + for (String item : items) { + if (item.length() > 0) { + item = START_TAG + tag + item; + stream = new ByteArrayInputStream( + item.getBytes(StandardCharsets.UTF_8)); + parser.parseHDFSElements(stream, writer, fta, i); } - } else { - value = START_TAG + value; - //create an input stream to the file currently reading and send it to parser - stream = new ByteArrayInputStream( - value.getBytes(StandardCharsets.UTF_8)); - parser.parseHDFSElements(stream, writer, fta, i); } - } - - } catch (InterruptedException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); + } else { + value = START_TAG + value; + //create an input stream to the file currently reading and send it to parser + stream = new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8)); + parser.parseHDFSElements(stream, writer, fta, i); } } - } - } catch (IOException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); - } - } catch (ParserConfigurationException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); - } - } catch (SAXException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); } + + } catch (Exception e) { + throw new HyracksDataException(e); } } else { try { @@ -248,22 +227,14 @@ public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityO throw new HyracksDataException("Invalid HDFS directory parameter (" + nodeId + ":" + directory + ") passed to collection."); } - } catch (FileNotFoundException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); - } - } catch (IOException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); - } + } catch (Exception e) { + throw new HyracksDataException(e); } } try { fs.close(); - } catch (IOException e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe(e.getMessage()); - } + } catch (Exception e) { + throw new HyracksDataException(e); } } }
