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/19 15:41:07 UTC
[1/6] vxquery git commit: Implement SimpleObjectUnionConstructor
[Forced Update!]
Repository: vxquery
Updated Branches:
refs/heads/master d7cb0a09f -> ef8efbc26 (forced update)
Implement SimpleObjectUnionConstructor
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/85cb2811
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/85cb2811
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/85cb2811
Branch: refs/heads/master
Commit: 85cb281114d085d2f955442814b7b5db3016e9c6
Parents: 4670e80
Author: riyafa <ri...@gmail.com>
Authored: Sat Jul 16 00:21:31 2016 +0530
Committer: riyafa <ri...@cse.mrt.ac.lk>
Committed: Tue Jul 19 11:52:08 2016 +0530
----------------------------------------------------------------------
.../org/apache/vxquery/xmlquery/ast/ASTTag.java | 1 +
.../ast/SimpleObjectUnionConstructor.java | 40 ++++++++++++++++
.../xmlquery/translator/XMLQueryTranslator.java | 37 +++++++++------
vxquery-core/src/main/javacc/xquery-grammar.jj | 49 +++++++++++---------
4 files changed, 91 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java
index a68dbd7..eb71923 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/ASTTag.java
@@ -110,5 +110,6 @@ public enum ASTTag {
SINGLE_TYPE,
ARRAY_CONSTRUCTOR,
OBJECT_CONSTRUCTOR,
+ SIMPLE_OBJECT_UNION_CONSTRUCTOR,
PAIR_CONSTRUCTOR
}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java
new file mode 100644
index 0000000..c5895c9
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/ast/SimpleObjectUnionConstructor.java
@@ -0,0 +1,40 @@
+/*
+* 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.xmlquery.ast;
+
+import org.apache.vxquery.util.SourceLocation;
+
+public class SimpleObjectUnionConstructor extends ASTNode {
+ private ASTNode expression;
+
+ public SimpleObjectUnionConstructor(SourceLocation loc) {
+ super(loc);
+ }
+
+ @Override
+ public ASTTag getTag() {
+ return ASTTag.SIMPLE_OBJECT_UNION_CONSTRUCTOR;
+ }
+
+ public ASTNode getExpression() {
+ return expression;
+ }
+
+ public void setExpression(ASTNode expression) {
+ this.expression = expression;
+ }
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
index c8cfb2b..bd150e0 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
@@ -168,6 +168,7 @@ import org.apache.vxquery.xmlquery.ast.QueryBodyNode;
import org.apache.vxquery.xmlquery.ast.RelativePathExprNode;
import org.apache.vxquery.xmlquery.ast.SchemaImportNode;
import org.apache.vxquery.xmlquery.ast.SequenceTypeNode;
+import org.apache.vxquery.xmlquery.ast.SimpleObjectUnionConstructor;
import org.apache.vxquery.xmlquery.ast.SingleTypeNode;
import org.apache.vxquery.xmlquery.ast.TypeDeclNode;
import org.apache.vxquery.xmlquery.ast.TypeExprNode;
@@ -837,6 +838,11 @@ public class XMLQueryTranslator {
return translateObjectConstructor(tCtx, obj);
}
+ case SIMPLE_OBJECT_UNION_CONSTRUCTOR: {
+ SimpleObjectUnionConstructor aNode = (SimpleObjectUnionConstructor) value;
+ return translateSimpleObjectUnionConstructor(tCtx, aNode);
+ }
+
case QNAME: {
QNameNode qnNode = (QNameNode) value;
return translateQNameNode(tCtx, qnNode);
@@ -1208,20 +1214,14 @@ public class XMLQueryTranslator {
List<ILogicalExpression> content = new ArrayList<ILogicalExpression>();
PairConstructor pc;
for (ASTNode aVal : obj.getContent()) {
- if (aVal.getTag()==ASTTag.PAIR_CONSTRUCTOR) {
- pc=(PairConstructor) aVal;
- ILogicalExpression ke = string(data(vre(translateExpression(pc.getKey(), tCtx))));
- content.add(ke);
- ILogicalExpression ve = vre(translateExpression(pc.getValue(), tCtx));
- content.add(ve);
- ILogicalExpression qmce = ce(SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE),
- pc.isQuestionMarkColon());
- content.add(qmce);
- } else {
- ILogicalExpression aExpr = aVal == null ? sfce(BuiltinOperators.CONCATENATE)
- : vre(translateExpression(aVal, tCtx));
- return createAssignment(sfce(BuiltinOperators.SIMPLE_OBJECT_UNION, aExpr), tCtx);
- }
+ pc = (PairConstructor) aVal;
+ ILogicalExpression ke = string(data(vre(translateExpression(pc.getKey(), tCtx))));
+ content.add(ke);
+ ILogicalExpression ve = vre(translateExpression(pc.getValue(), tCtx));
+ content.add(ve);
+ ILogicalExpression qmce = ce(SequenceType.create(BuiltinTypeRegistry.XS_BOOLEAN, Quantifier.QUANT_ONE),
+ pc.isQuestionMarkColon());
+ content.add(qmce);
}
return createAssignment(
@@ -1229,6 +1229,15 @@ public class XMLQueryTranslator {
tCtx);
}
+ private LogicalVariable translateSimpleObjectUnionConstructor(TranslationContext tCtx,
+ SimpleObjectUnionConstructor aNode) throws SystemException {
+ ASTNode expression = aNode.getExpression();
+ ILogicalExpression aExpr = expression == null ? sfce(BuiltinOperators.CONCATENATE)
+ : vre(translateExpression(expression, tCtx));
+ LogicalVariable lVar = createAssignment(sfce(BuiltinOperators.SIMPLE_OBJECT_UNION, aExpr), tCtx);
+ return lVar;
+ }
+
private LogicalVariable translateDirectElementConstructorNode(TranslationContext tCtx,
DirectElementConstructorNode decNode) throws SystemException {
QNameNode startName = decNode.getStartTagName();
http://git-wip-us.apache.org/repos/asf/vxquery/blob/85cb2811/vxquery-core/src/main/javacc/xquery-grammar.jj
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/javacc/xquery-grammar.jj b/vxquery-core/src/main/javacc/xquery-grammar.jj
index 9ea3943..bfb5d26 100644
--- a/vxquery-core/src/main/javacc/xquery-grammar.jj
+++ b/vxquery-core/src/main/javacc/xquery-grammar.jj
@@ -1999,8 +1999,9 @@ ASTNode JsonConstructor() :
}
{
(
- result = ObjectConstructor()
- | result = ArrayConstructor()
+ result = ArrayConstructor()
+ | result = ObjectConstructor()
+ | result = SimpleObjectUnionConstructor()
) {
return result;
}
@@ -2013,27 +2014,17 @@ ASTNode ObjectConstructor() :
ASTNode pc;
}
{
+ t = <LbraceExprEnclosure>
(
- (
- t = <LbraceExprEnclosure>
- (
- pc = PairConstructor() {
- content.add(pc);
- } (
- "," pc = PairConstructor() {
- content.add(pc);
- }
- )*
- )*
- <Rbrace>
- )
- | (
- t = "{|" pc = Expr() "|}"
- {
- content.add(pc);
- }
- )
- )
+ pc = PairConstructor() {
+ content.add(pc);
+ } (
+ "," pc = PairConstructor() {
+ content.add(pc);
+ }
+ )*
+ )*
+ <Rbrace>
{
ObjectConstructor obj = new ObjectConstructor(createSourceLocation(t));
obj.setContent(content);
@@ -2077,6 +2068,20 @@ ASTNode ArrayConstructor() :
}
}
+ASTNode SimpleObjectUnionConstructor() :
+{
+ ASTNode expr = null;
+ Token start;
+}
+{
+ start = "{|" expr = Expr() "|}"
+ {
+ SimpleObjectUnionConstructor souc = new SimpleObjectUnionConstructor(createSourceLocation(start));
+ souc.setExpression(expr);
+ return souc;
+ }
+}
+
ASTNode DirectConstructor() :
{
ASTNode result;
[4/6] vxquery git commit: Refactor SimpleObjectUnionScalarEvaluator
Posted by pr...@apache.org.
Refactor SimpleObjectUnionScalarEvaluator
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/f9272583
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/f9272583
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/f9272583
Branch: refs/heads/master
Commit: f9272583a5e149095557764435b28d0476af9e72
Parents: 85cb281
Author: riyafa <ri...@gmail.com>
Authored: Thu Jul 14 21:15:38 2016 +0530
Committer: Preston Carman <pr...@apache.org>
Committed: Tue Jul 19 08:40:22 2016 -0700
----------------------------------------------------------------------
...bstractObjectConstructorScalarEvaluator.java | 53 +++++++++
.../ObjectConstructorScalarEvaluator.java | 36 ++-----
.../SimpleObjectUnionScalarEvaluator.java | 107 ++++++++++---------
.../Json/Object/q15_object.txt | 1 +
.../Json/Object/q16_object.txt | 1 +
.../Queries/XQuery/Json/Object/q15_object.xq | 20 ++++
.../Queries/XQuery/Json/Object/q16_object.xq | 20 ++++
.../test/resources/cat/JsonObjectQueries.xml | 10 ++
8 files changed, 170 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/AbstractObjectConstructorScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/AbstractObjectConstructorScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/AbstractObjectConstructorScalarEvaluator.java
new file mode 100644
index 0000000..810de40
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/AbstractObjectConstructorScalarEvaluator.java
@@ -0,0 +1,53 @@
+/*
+ * 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.jsonitem;
+
+import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import org.apache.hyracks.api.context.IHyracksTaskContext;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.builders.jsonitem.ObjectBuilder;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
+import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractObjectConstructorScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
+ protected final IHyracksTaskContext ctx;
+ protected final ObjectBuilder ob;
+ protected final ArrayBackedValueStorage abvs;
+ protected final List<TaggedValuePointable> tvps;
+
+ public AbstractObjectConstructorScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
+ super(args);
+ this.ctx = ctx;
+ ob = new ObjectBuilder();
+ abvs = new ArrayBackedValueStorage();
+ tvps = new ArrayList<>();
+ }
+
+ protected boolean isDuplicateKeys(IPointable key, List<TaggedValuePointable> pointables) {
+ for (TaggedValuePointable tvp : pointables) {
+ if (tvp != null && FunctionHelper.arraysEqual(tvp, key)) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/ObjectConstructorScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/ObjectConstructorScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/ObjectConstructorScalarEvaluator.java
index c002ad7..0d718a4 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/ObjectConstructorScalarEvaluator.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/ObjectConstructorScalarEvaluator.java
@@ -26,34 +26,24 @@ 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.builders.jsonitem.ArrayBuilder;
-import org.apache.vxquery.datamodel.builders.jsonitem.ObjectBuilder;
import org.apache.vxquery.datamodel.values.ValueTag;
import org.apache.vxquery.datamodel.values.XDMConstants;
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;
-public class ObjectConstructorScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
- private ObjectBuilder ob;
- private TaggedValuePointable[] pointables;
+public class ObjectConstructorScalarEvaluator extends AbstractObjectConstructorScalarEvaluator {
private IPointable vp;
private UTF8StringPointable sp;
private SequencePointable seqp;
- protected final IHyracksTaskContext ctx;
- private final ArrayBackedValueStorage abvs;
private final ArrayBackedValueStorage abvs1;
private final BooleanPointable bp;
private final ArrayBuilder ab;
public ObjectConstructorScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
- super(args);
- this.ctx = ctx;
- abvs = new ArrayBackedValueStorage();
+ super(ctx, args);
abvs1 = new ArrayBackedValueStorage();
- ob = new ObjectBuilder();
vp = VoidPointable.FACTORY.createPointable();
sp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
@@ -61,33 +51,21 @@ public class ObjectConstructorScalarEvaluator extends AbstractTaggedValueArgumen
ab = new ArrayBuilder();
}
- private boolean isDuplicate(TaggedValuePointable tempKey) {
- for (TaggedValuePointable tvp : pointables) {
- tempKey.getValue(vp);
- if (tvp != null && FunctionHelper.arraysEqual(tvp, vp)) {
- return true;
- }
- }
- return false;
- }
-
@Override
protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
- TaggedValuePointable key, value, qmc;
+ TaggedValuePointable key, value, qmc, tvp;
try {
abvs.reset();
ob.reset(abvs);
-
+ tvps.clear();
int len = args.length;
- pointables = new TaggedValuePointable[len / 3];
for (int i = 0; i < len; i += 3) {
key = args[i];
value = args[i + 1];
qmc = args[i + 2];
- if (!isDuplicate(key)) {
- pointables[i / 3] = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
- key.getValue(pointables[i / 3]);
- sp.set(vp);
+ if (!isDuplicateKeys(key, tvps)) {
+ tvps.add(key);
+ key.getValue(sp);
if (value.getTag() == ValueTag.SEQUENCE_TAG) {
qmc.getValue(bp);
value.getValue(seqp);
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/SimpleObjectUnionScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/SimpleObjectUnionScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/SimpleObjectUnionScalarEvaluator.java
index 60347b1..960cea4 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/SimpleObjectUnionScalarEvaluator.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/jsonitem/SimpleObjectUnionScalarEvaluator.java
@@ -24,79 +24,88 @@ 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.values.ValueTag;
-import org.apache.vxquery.datamodel.values.XDMConstants;
import org.apache.vxquery.exceptions.ErrorCode;
import org.apache.vxquery.exceptions.SystemException;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-public class SimpleObjectUnionScalarEvaluator extends ObjectConstructorScalarEvaluator {
+public class SimpleObjectUnionScalarEvaluator extends AbstractObjectConstructorScalarEvaluator {
private final SequencePointable sp, sp1;
+ private ObjectPointable op;
+ private TaggedValuePointable key;
+ private final UTF8StringPointable stringKey;
public SimpleObjectUnionScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
super(ctx, args);
sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
+ stringKey = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
}
@Override
protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
- List<TaggedValuePointable> tvps = new ArrayList<>();
-
- ObjectPointable op;
- TaggedValuePointable key, value;
TaggedValuePointable arg = args[0];
- if (arg.getTag() == ValueTag.SEQUENCE_TAG) {
- arg.getValue(sp);
- TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
- TaggedValuePointable boolTvp = ppool.takeOne(TaggedValuePointable.class);
- UTF8StringPointable tempKey = ppool.takeOne(UTF8StringPointable.class);
- XDMConstants.setFalse(boolTvp);
- try {
+ if (!(arg.getTag() == ValueTag.SEQUENCE_TAG || arg.getTag() == ValueTag.OBJECT_TAG)) {
+ throw new SystemException(ErrorCode.FORG0006);
+ }
+ TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
+ TaggedValuePointable tempValue = 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) {
op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
sp.getEntry(i, tempTvp);
tempTvp.getValue(op);
op.getKeys(tempTvp);
- if (tempTvp.getTag() == ValueTag.XS_STRING_TAG) {
- key = ppool.takeOne(TaggedValuePointable.class);
- value = ppool.takeOne(TaggedValuePointable.class);
- tempTvp.getValue(tempKey);
- op.getValue(tempKey, value);
- key.set(tempTvp);
- tvps.add(key);
- tvps.add(value);
- tvps.add(boolTvp);
+ addPairs(tempTvp, tempValue);
+ }
+ } else {
+ op = (ObjectPointable) ObjectPointable.FACTORY.createPointable();
+ arg.getValue(op);
+ addPairs(tempTvp, tempValue);
+ }
+ ob.finish();
+ result.set(abvs);
+ } catch (IOException e) {
+ throw new SystemException(ErrorCode.SYSE0001, e);
+ } finally {
+ ppool.giveBack(tempTvp);
+ for (TaggedValuePointable pointable : tvps) {
+ ppool.giveBack(pointable);
+ }
+ }
+ }
- } else if (tempTvp.getTag() == ValueTag.SEQUENCE_TAG) {
- tempTvp.getValue(sp1);
- for (int j = 0; j < sp1.getEntryCount(); ++j) {
- key = ppool.takeOne(TaggedValuePointable.class);
- value = ppool.takeOne(TaggedValuePointable.class);
- sp1.getEntry(j, tempTvp);
- tempTvp.getValue(tempKey);
- op.getValue(tempKey, value);
- key.set(tempTvp);
- tvps.add(key);
- tvps.add(value);
- tvps.add(boolTvp);
- }
+ private void addPair(TaggedValuePointable tempTvp, TaggedValuePointable tempValue)
+ throws IOException, SystemException {
+ if (!isDuplicateKeys(tempTvp, tvps)) {
+ key = ppool.takeOne(TaggedValuePointable.class);
+ key.set(tempTvp);
+ tvps.add(key);
+ tempTvp.getValue(stringKey);
+ op.getValue(stringKey, tempValue);
+ ob.addItem(stringKey, tempValue);
+ } else {
+ throw new SystemException(ErrorCode.JNDY0003);
+ }
+ }
- }
- }
- super.evaluate(tvps.toArray(new TaggedValuePointable[tvps.size()]), result);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
- } finally {
- ppool.giveBack(tempKey);
- ppool.giveBack(tempTvp);
- ppool.giveBack(boolTvp);
- for (TaggedValuePointable pointable : tvps) {
- ppool.giveBack(pointable);
- }
+ private void addPairs(TaggedValuePointable tempTvp, TaggedValuePointable tempValue)
+ throws IOException, SystemException {
+ op.getKeys(tempTvp);
+ if (tempTvp.getTag() == ValueTag.XS_STRING_TAG) {
+ addPair(tempTvp, tempValue);
+ } else if (tempTvp.getTag() == ValueTag.SEQUENCE_TAG) {
+ tempTvp.getValue(sp1);
+ for (int j = 0; j < sp1.getEntryCount(); ++j) {
+ key = ppool.takeOne(TaggedValuePointable.class);
+ sp1.getEntry(j, tempTvp);
+ addPair(tempTvp, tempValue);
}
}
}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q15_object.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q15_object.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q15_object.txt
new file mode 100644
index 0000000..37514da
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q15_object.txt
@@ -0,0 +1 @@
+{"Captain":"Kirk"}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q16_object.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q16_object.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q16_object.txt
new file mode 100644
index 0000000..e0e0cb4
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Object/q16_object.txt
@@ -0,0 +1 @@
+{"Captain":"Kirk","123456":"NUM"}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q15_object.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q15_object.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q15_object.xq
new file mode 100644
index 0000000..18d0d9d
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q15_object.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. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-212 :)
+{| { "Captain" : "Kirk" } |}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q16_object.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q16_object.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q16_object.xq
new file mode 100644
index 0000000..36b6e60
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Object/q16_object.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. :)
+
+(: Json Object Query :)
+(: Issue VXQUERY-212 :)
+{| { "Captain" : "Kirk" , 123456 : "NUM"} |}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/vxquery/blob/f9272583/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml b/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
index 2ee68c4..1968853 100644
--- a/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
+++ b/vxquery-xtest/src/test/resources/cat/JsonObjectQueries.xml
@@ -90,4 +90,14 @@
<query name="q14_object" date="2016-07-09"/>
<output-file compare="Text">q14_object.txt</output-file>
</test-case>
+ <test-case name="json-object-q15" FilePath="Json/Object/" Creator="Riyafa Abdul Hameed">
+ <description>Object.</description>
+ <query name="q15_object" date="2016-07-16"/>
+ <output-file compare="Text">q15_object.txt</output-file>
+ </test-case>
+ <test-case name="json-object-q16" FilePath="Json/Object/" Creator="Riyafa Abdul Hameed">
+ <description>Object.</description>
+ <query name="q16_object" date="2016-07-16"/>
+ <output-file compare="Text">q16_object.txt</output-file>
+ </test-case>
</test-group>
\ No newline at end of file
[5/6] vxquery git commit: Fixed an issue with xtest after moving to a
single cluster for testing.
Posted by pr...@apache.org.
Fixed an issue with xtest after moving to a single cluster for testing.
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/cbf2cdb6
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/cbf2cdb6
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/cbf2cdb6
Branch: refs/heads/master
Commit: cbf2cdb68650b17a710611ca4bbab2977a435c4d
Parents: fb785e9
Author: Preston Carman <pr...@apache.org>
Authored: Mon Jul 18 19:13:37 2016 -0700
Committer: Preston Carman <pr...@apache.org>
Committed: Tue Jul 19 08:40:22 2016 -0700
----------------------------------------------------------------------
.../apache/vxquery/xtest/AbstractTestCaseFactory.java | 2 +-
.../org/apache/vxquery/xtest/HTMLFileReporterImpl.java | 10 +++++-----
.../java/org/apache/vxquery/xtest/TestClusterUtil.java | 3 +++
.../src/main/java/org/apache/vxquery/xtest/XTest.java | 13 ++++++++++++-
4 files changed, 21 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/cbf2cdb6/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
index cf52171..a9fd4a4 100644
--- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
+++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/AbstractTestCaseFactory.java
@@ -83,7 +83,7 @@ public abstract class AbstractTestCaseFactory {
}
private static Set<String> getPreviousTests(String previousTestResults) {
- Set<String> tests = new LinkedHashSet<String>();
+ Set<String> tests = new LinkedHashSet<>();
try {
BufferedReader br = new BufferedReader(new FileReader(previousTestResults));
String line;
http://git-wip-us.apache.org/repos/asf/vxquery/blob/cbf2cdb6/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/HTMLFileReporterImpl.java
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/HTMLFileReporterImpl.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/HTMLFileReporterImpl.java
index d9e85e3..d64fcec 100644
--- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/HTMLFileReporterImpl.java
+++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/HTMLFileReporterImpl.java
@@ -76,12 +76,12 @@ public class HTMLFileReporterImpl implements ResultReporter {
++userErrors;
} else {
++internalErrors;
- Integer count = exDistribution.get(result.error.getClass());
- if (count == null) {
- count = 0;
+ Integer internalCount = exDistribution.get(result.error.getClass());
+ if (internalCount == null) {
+ internalCount = 0;
}
- count++;
- exDistribution.put(result.error.getClass(), count);
+ internalCount++;
+ exDistribution.put(result.error.getClass(), internalCount);
}
}
Integer stCount = stDistribution.get(result.state);
http://git-wip-us.apache.org/repos/asf/vxquery/blob/cbf2cdb6/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java
index 9f5bb76..75dce1b 100644
--- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java
+++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestClusterUtil.java
@@ -35,6 +35,9 @@ public class TestClusterUtil {
private static String ccHost = "localhost";
private static String nodeId = "nc1";
+ private TestClusterUtil() {
+ }
+
public static CCConfig createCCConfig() throws UnknownHostException {
String publicAddress = InetAddress.getLocalHost().getHostAddress();
CCConfig ccConfig = new CCConfig();
http://git-wip-us.apache.org/repos/asf/vxquery/blob/cbf2cdb6/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java
index 17dea60..fa07d9b 100644
--- a/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java
+++ b/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/XTest.java
@@ -16,9 +16,12 @@
*/
package org.apache.vxquery.xtest;
+import org.apache.hyracks.control.cc.ClusterControllerService;
+import org.apache.hyracks.control.nc.NodeControllerService;
import org.mortbay.jetty.Server;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -33,6 +36,8 @@ public class XTest {
private TestRunnerFactory trf;
private int count;
private int finishCount;
+ private static NodeControllerService nc;
+ private static ClusterControllerService cc;
XTest(XTestOptions opts) {
this.opts = opts;
@@ -76,6 +81,8 @@ public class XTest {
}
}
});
+ cc = TestClusterUtil.startCC();
+ nc = TestClusterUtil.startNC();
trf = new TestRunnerFactory(opts);
trf.registerReporters(reporters);
TestCaseFactory tcf = new TestCaseFactory(trf, eSvc, opts);
@@ -97,10 +104,14 @@ public class XTest {
r.close();
}
try {
+ TestClusterUtil.stopCluster(cc, nc);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ try {
eSvc.awaitTermination(opts.keepalive, TimeUnit.MILLISECONDS);
} finally {
try {
-
if (server != null) {
server.stop();
}
[2/6] vxquery git commit: Adding the rest namespaces
Posted by pr...@apache.org.
Adding the rest namespaces
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/ef8efbc2
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/ef8efbc2
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/ef8efbc2
Branch: refs/heads/master
Commit: ef8efbc263c11dde90f43a2443c02ac909d481f2
Parents: cbf2cdb
Author: Christina Pavlopoulou <cp...@ucr.edu>
Authored: Mon Jul 18 15:56:37 2016 -0700
Committer: Preston Carman <pr...@apache.org>
Committed: Tue Jul 19 08:40:22 2016 -0700
----------------------------------------------------------------------
.../java/org/apache/vxquery/context/RootStaticContextImpl.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/ef8efbc2/vxquery-core/src/main/java/org/apache/vxquery/context/RootStaticContextImpl.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/context/RootStaticContextImpl.java b/vxquery-core/src/main/java/org/apache/vxquery/context/RootStaticContextImpl.java
index 8c695e2..922103b 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/context/RootStaticContextImpl.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/context/RootStaticContextImpl.java
@@ -46,8 +46,13 @@ public final class RootStaticContextImpl extends StaticContextImpl {
INSTANCE.registerNamespaceUri(XQueryConstants.XSI_PREFIX, XQueryConstants.XSI_NSURI);
INSTANCE.registerNamespaceUri(XQueryConstants.FN_PREFIX, XQueryConstants.FN_NSURI);
INSTANCE.registerNamespaceUri(XQueryConstants.LOCAL_PREFIX, XQueryConstants.LOCAL_NSURI);
+ INSTANCE.registerNamespaceUri(XQueryConstants.OP_PREFIX, XQueryConstants.OP_NSURI);
+ INSTANCE.registerNamespaceUri(XQueryConstants.OPEXT_PREFIX, XQueryConstants.OPEXT_NSURI);
INSTANCE.registerNamespaceUri(XQueryConstants.JS_PREFIX, XQueryConstants.JS_NSURI);
INSTANCE.registerNamespaceUri(XQueryConstants.JN_PREFIX, XQueryConstants.JN_NSURI);
+ INSTANCE.registerNamespaceUri(XQueryConstants.LIBJN_PREFIX, XQueryConstants.LIBJN_NSURI);
+ INSTANCE.registerNamespaceUri(XQueryConstants.JERR_PREFIX, XQueryConstants.JERR_NSURI);
+ INSTANCE.registerNamespaceUri(XQueryConstants.JUPD_PREFIX, XQueryConstants.JUPD_NSURI);
INSTANCE.registerNamespaceUri(XQueryConstants.JDM_PREFIX, XQueryConstants.JDM_NSURI);
INSTANCE.setBaseUri(".");
[3/6] vxquery git commit: Editing fn:collection for json and testing
Posted by pr...@apache.org.
Editing fn:collection for json and testing
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/fb785e98
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/fb785e98
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/fb785e98
Branch: refs/heads/master
Commit: fb785e984c8fcd54947a8ffb9fc076500b5c3008
Parents: 6effe1b
Author: Christina Pavlopoulou <cp...@ucr.edu>
Authored: Thu Jul 14 13:51:14 2016 -0700
Committer: Preston Carman <pr...@apache.org>
Committed: Tue Jul 19 08:40:22 2016 -0700
----------------------------------------------------------------------
.../apache/vxquery/jsonparser/JSONParser.java | 3 +-
.../VXQueryCollectionOperatorDescriptor.java | 35 +++++++++++++++++---
.../vxquery/metadata/VXQueryIOFileFilter.java | 3 +-
.../Json/Parser/Partition-1/q14_parser.txt | 3 ++
.../Json/Parser/Partition-2/q15_parser.txt | 3 ++
.../Json/Parser/Partition-4/q16_parser.txt | 3 ++
.../Json/Parser/Partition-1/q14_parser.xq | 25 ++++++++++++++
.../Json/Parser/Partition-2/q15_parser.xq | 25 ++++++++++++++
.../Json/Parser/Partition-4/q16_parser.xq | 25 ++++++++++++++
.../quarter_1/sensors/US000000001_200101_0.json | 29 ++++++++++++++++
.../quarter_2/sensors/US000000002_200202_0.json | 29 ++++++++++++++++
.../quarter_3/sensors/AS000000003_200303_0.json | 22 ++++++++++++
.../quarter_4/sensors/US000000004_200404_0.json | 22 ++++++++++++
.../src/test/resources/VXQueryCatalog.xml | 21 ++++++++++++
.../test/resources/cat/JsonParserQueries.xml | 15 +++++++++
15 files changed, 255 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-core/src/main/java/org/apache/vxquery/jsonparser/JSONParser.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/jsonparser/JSONParser.java b/vxquery-core/src/main/java/org/apache/vxquery/jsonparser/JSONParser.java
index 71220cf..68fbb82 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/jsonparser/JSONParser.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/jsonparser/JSONParser.java
@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.htrace.fasterxml.jackson.core.JsonFactory;
-import org.apache.htrace.fasterxml.jackson.core.JsonParseException;
import org.apache.htrace.fasterxml.jackson.core.JsonParser;
import org.apache.htrace.fasterxml.jackson.core.JsonToken;
import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -56,7 +55,7 @@ public class JSONParser implements IParser {
protected final List<itemType> itemStack;
- public JSONParser() throws JsonParseException {
+ public JSONParser() {
factory = new JsonFactory();
atomic = new ArrayBackedValueStorage();
abStack = new ArrayList<ArrayBuilder>();
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/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 acd74b1..7736edd 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,7 +18,11 @@ package org.apache.vxquery.metadata;
import java.io.ByteArrayInputStream;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
@@ -52,14 +56,17 @@ import org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider;
import org.apache.hyracks.api.dataflow.value.RecordDescriptor;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.job.IOperatorDescriptorRegistry;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
import org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldTupleAppender;
import org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor;
+import org.apache.hyracks.dataflow.common.comm.util.FrameUtils;
import org.apache.hyracks.dataflow.std.base.AbstractSingleActivityOperatorDescriptor;
import org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable;
import org.apache.hyracks.hdfs.ContextFactory;
import org.apache.hyracks.hdfs2.dataflow.FileSplitsFactory;
import org.apache.vxquery.context.DynamicContext;
import org.apache.vxquery.hdfs2.HDFSFunctions;
+import org.apache.vxquery.jsonparser.JSONParser;
import org.apache.vxquery.xmlparser.ITreeNodeIdProvider;
import org.apache.vxquery.xmlparser.TreeNodeIdProvider;
import org.apache.vxquery.xmlparser.XMLParser;
@@ -102,10 +109,11 @@ public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityO
final ITreeNodeIdProvider nodeIdProvider = new TreeNodeIdProvider(partitionId, dataSourceId, totalDataSources);
final String nodeId = ctx.getJobletContext().getApplicationContext().getNodeId();
final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
-
+ final ArrayBackedValueStorage jsonAbvs = new ArrayBackedValueStorage();
final String collectionName = collectionPartitions[partition % collectionPartitions.length];
final XMLParser parser = new XMLParser(false, nodeIdProvider, nodeId, appender, childSeq,
dCtx.getStaticContext());
+ final JSONParser jparser = new JSONParser();
return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {
@Override
@@ -119,6 +127,7 @@ public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityO
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
fta.reset(buffer);
String collectionModifiedName = collectionName.replace("${nodeId}", nodeId);
+ Reader input;
if (!collectionModifiedName.contains("hdfs:/")) {
File collectionDirectory = new File(collectionModifiedName);
//check if directory is in the local file system
@@ -129,11 +138,27 @@ public class VXQueryCollectionOperatorDescriptor extends AbstractSingleActivityO
Iterator<File> it = FileUtils.iterateFiles(collectionDirectory,
new VXQueryIOFileFilter(), TrueFileFilter.INSTANCE);
while (it.hasNext()) {
- File xmlDocument = it.next();
- if (LOGGER.isLoggable(Level.FINE)) {
- LOGGER.fine("Starting to read XML document: " + xmlDocument.getAbsolutePath());
+ File file = it.next();
+ String fileName = file.getName().toLowerCase();
+ if (fileName.endsWith(".xml")) {
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.fine("Starting to read XML document: " + file.getAbsolutePath());
+ }
+ parser.parseElements(file, writer, tupleIndex);
+ } else if (fileName.endsWith(".json")) {
+ if (LOGGER.isLoggable(Level.FINE)) {
+ LOGGER.fine("Starting to read JSON document: " + file.getAbsolutePath());
+ }
+ try {
+ jsonAbvs.reset();
+ input = new InputStreamReader(new FileInputStream(file));
+ jparser.parse(input, jsonAbvs);
+ FrameUtils.appendFieldToWriter(writer, appender, jsonAbvs.getByteArray(),
+ jsonAbvs.getStartOffset(), jsonAbvs.getLength());
+ } catch (FileNotFoundException e) {
+ throw new HyracksDataException(e.toString());
+ }
}
- parser.parseElements(xmlDocument, writer, tupleIndex);
}
}
} else {
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIOFileFilter.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIOFileFilter.java b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIOFileFilter.java
index 70070dc..9a68eec 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIOFileFilter.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/metadata/VXQueryIOFileFilter.java
@@ -29,7 +29,8 @@ public class VXQueryIOFileFilter implements IOFileFilter {
@Override
public boolean accept(final File file, final String name) {
- if (name.toLowerCase().endsWith(".xml") || name.toLowerCase().endsWith(".xml.gz")) {
+ String fileName = name.toLowerCase();
+ if (fileName.endsWith(".xml") || fileName.endsWith(".json")) {
return true;
}
return false;
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-1/q14_parser.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-1/q14_parser.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-1/q14_parser.txt
new file mode 100644
index 0000000..abbafea
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-1/q14_parser.txt
@@ -0,0 +1,3 @@
+{"date":"2001-01-01T00:00:00.000","datatype":"TMIN","station":"GHCND:US000000001","attributes":",,","value":11.25}
+{"date":"2001-01-01T00:00:00.000","datatype":"TMAX","station":"GHCND:US000000001","attributes":",,","value":31}
+{"date":"2001-01-01T00:00:00.000","datatype":"AWND","station":"GHCND:US000000001","attributes":",,","value":1000}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-2/q15_parser.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-2/q15_parser.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-2/q15_parser.txt
new file mode 100644
index 0000000..3ca741c
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-2/q15_parser.txt
@@ -0,0 +1,3 @@
+{"date":"2001-01-01T00:00:00.000","datatype":"TMIN","station":"GHCND:US000000001","attributes":",,","value":11.25}
+{"date":"2002-02-02T00:00:00.000","datatype":"TMIN","station":"GHCND:US000000002","attributes":",,","value":12.5}
+{"date":"2003-03-03T00:00:00.000","datatype":"TMIN","station":"GHCND:AS000000003","attributes":",,","value":13.75}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-4/q16_parser.txt
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-4/q16_parser.txt b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-4/q16_parser.txt
new file mode 100644
index 0000000..abbafea
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/ExpectedTestResults/Json/Parser/Partition-4/q16_parser.txt
@@ -0,0 +1,3 @@
+{"date":"2001-01-01T00:00:00.000","datatype":"TMIN","station":"GHCND:US000000001","attributes":",,","value":11.25}
+{"date":"2001-01-01T00:00:00.000","datatype":"TMAX","station":"GHCND:US000000001","attributes":",,","value":31}
+{"date":"2001-01-01T00:00:00.000","datatype":"AWND","station":"GHCND:US000000001","attributes":",,","value":1000}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-1/q14_parser.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-1/q14_parser.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-1/q14_parser.xq
new file mode 100644
index 0000000..7bc86b6
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-1/q14_parser.xq
@@ -0,0 +1,25 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License. :)
+
+(: Json Parser Query :)
+(: parse a string with arrays :)
+let $x:="jsonCollection"
+for $r in collection($x)
+ let $z:=$r("results")()
+ for $i in $z()
+where $i("date")="2001-01-01T00:00:00.000"
+return $i
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-2/q15_parser.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-2/q15_parser.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-2/q15_parser.xq
new file mode 100644
index 0000000..b43ddc3
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-2/q15_parser.xq
@@ -0,0 +1,25 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License. :)
+
+(: Json Parser Query :)
+(: parse a string with arrays :)
+let $x:="json_half_1|json_half_2"
+for $r in collection($x)
+ let $z:=$r("results")()
+ for $i in $z()
+where $i("datatype")="TMIN"
+return $i
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-4/q16_parser.xq
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-4/q16_parser.xq b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-4/q16_parser.xq
new file mode 100644
index 0000000..4fabd06
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/Queries/XQuery/Json/Parser/Partition-4/q16_parser.xq
@@ -0,0 +1,25 @@
+(: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License. :)
+
+(: Json Parser Query :)
+(: parse a string with arrays :)
+let $x:="json_quarter_1|json_quarter_2|json_quarter_3|json_quarter_4"
+for $r in collection($x)
+ let $z:=$r("results")()
+ for $i in $z()
+where $i("station")="GHCND:US000000001"
+return $i
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_1/sensors/US000000001_200101_0.json
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_1/sensors/US000000001_200101_0.json b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_1/sensors/US000000001_200101_0.json
new file mode 100644
index 0000000..e16b964
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_1/sensors/US000000001_200101_0.json
@@ -0,0 +1,29 @@
+{
+ "metadata": {
+ "pageCount": 1,
+ "count": 3
+ },
+ "results": [
+ {
+ "date": "2001-01-01T00:00:00.000",
+ "datatype": "TMIN",
+ "station": "GHCND:US000000001",
+ "attributes": ",,",
+ "value": 11.25
+ },
+ {
+ "date": "2001-01-01T00:00:00.000",
+ "datatype": "TMAX",
+ "station": "GHCND:US000000001",
+ "attributes": ",,",
+ "value": 31
+ },
+ {
+ "date": "2001-01-01T00:00:00.000",
+ "datatype": "AWND",
+ "station": "GHCND:US000000001",
+ "attributes": ",,",
+ "value": 1000
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_2/sensors/US000000002_200202_0.json
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_2/sensors/US000000002_200202_0.json b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_2/sensors/US000000002_200202_0.json
new file mode 100644
index 0000000..59a82ea
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_1/quarter_2/sensors/US000000002_200202_0.json
@@ -0,0 +1,29 @@
+{
+ "metadata": {
+ "pageCount": 1,
+ "count": 3
+ },
+ "results": [
+ {
+ "date": "2002-02-02T00:00:00.000",
+ "datatype": "TMIN",
+ "station": "GHCND:US000000002",
+ "attributes": ",,",
+ "value": 12.5
+ },
+ {
+ "date": "2002-02-02T00:00:00.000",
+ "datatype": "TMAX",
+ "station": "GHCND:US000000002",
+ "attributes": ",,",
+ "value": 32
+ },
+ {
+ "date": "2002-02-02T00:00:00.000",
+ "datatype": "PRCP",
+ "station": "GHCND:US000000002",
+ "attributes": ",,",
+ "value": 20
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_3/sensors/AS000000003_200303_0.json
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_3/sensors/AS000000003_200303_0.json b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_3/sensors/AS000000003_200303_0.json
new file mode 100644
index 0000000..221de5f
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_3/sensors/AS000000003_200303_0.json
@@ -0,0 +1,22 @@
+{
+ "metadata": {
+ "pageCount": 1,
+ "count": 2
+ },
+ "results": [
+ {
+ "date": "2003-03-03T00:00:00.000",
+ "datatype": "TMIN",
+ "station": "GHCND:AS000000003",
+ "attributes": ",,",
+ "value": 13.75
+ },
+ {
+ "date": "2003-03-03T00:00:00.000",
+ "datatype": "TMAX",
+ "station": "GHCND:AS000000003",
+ "attributes": ",,",
+ "value": 33
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_4/sensors/US000000004_200404_0.json
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_4/sensors/US000000004_200404_0.json b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_4/sensors/US000000004_200404_0.json
new file mode 100644
index 0000000..98493ce
--- /dev/null
+++ b/vxquery-xtest/src/test/resources/TestSources/jsonCollection/half_2/quarter_4/sensors/US000000004_200404_0.json
@@ -0,0 +1,22 @@
+{
+ "metadata": {
+ "pageCount": 1,
+ "count": 2
+ },
+ "results": [
+ {
+ "date": "2004-04-04T00:00:00.000",
+ "datatype": "PRCP",
+ "station": "GHCND:US000000004",
+ "attributes": ",,",
+ "value": 40
+ },
+ {
+ "date": "2003-03-03T00:00:00.000",
+ "datatype": "AWND",
+ "station": "GHCND:US000000004",
+ "attributes": ",,",
+ "value": 4
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/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 8ef09a6..f678fba 100644
--- a/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
+++ b/vxquery-xtest/src/test/resources/VXQueryCatalog.xml
@@ -94,6 +94,27 @@
<source ID="ghcnd_quarter_4" FileName="TestSources/ghcnd/half_2/quarter_4" Creator="Preston Carman">
<description last-mod="2014-04-02">Collection of files</description>
</source>
+ <source ID="jsonCollection" FileName="TestSources/jsonCollection" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
+ <source ID="json_half_1" FileName="TestSources/jsonCollection/half_1" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
+ <source ID="json_half_2" FileName="TestSources/jsonCollection/half_2" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
+ <source ID="json_quarter_1" FileName="TestSources/jsonCollection/half_1/quarter_1" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
+ <source ID="json_quarter_2" FileName="TestSources/jsonCollection/half_1/quarter_2" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
+ <source ID="json_quarter_3" FileName="TestSources/jsonCollection/half_2/quarter_3" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
+ <source ID="json_quarter_4" FileName="TestSources/jsonCollection/half_2/quarter_4" Creator="Christina Pavlopoulou">
+ <description last-mod="2016-07-12">Collection of files</description>
+ </source>
<source ID="station_xml_file" FileName="TestSources/ghcnd/half_1/quarter_1/stations/US000000001.xml"
Creator="Shivani Mall">
<description last-mod="2015-06-26">File</description>
http://git-wip-us.apache.org/repos/asf/vxquery/blob/fb785e98/vxquery-xtest/src/test/resources/cat/JsonParserQueries.xml
----------------------------------------------------------------------
diff --git a/vxquery-xtest/src/test/resources/cat/JsonParserQueries.xml b/vxquery-xtest/src/test/resources/cat/JsonParserQueries.xml
index 74f7b00..795ab9b 100644
--- a/vxquery-xtest/src/test/resources/cat/JsonParserQueries.xml
+++ b/vxquery-xtest/src/test/resources/cat/JsonParserQueries.xml
@@ -70,4 +70,19 @@
<query name="q13_parser" date="2016-07-12"/>
<expected-error>JNDY0021</expected-error>
</test-case>
+ <test-case name="json-parser-q14" FilePath="Json/Parser/Partition-1" Creator="Christina Pavlopoulou">
+ <description>Parsing a collection of json files.</description>
+ <query name="q14_parser" date="2016-07-12"/>
+ <output-file compare="Text">q14_parser.txt</output-file>
+ </test-case>
+ <test-case name="json-parser-q15" FilePath="Json/Parser/Partition-2" Creator="Christina Pavlopoulou">
+ <description>Parsing a collection of json files.</description>
+ <query name="q15_parser" date="2016-07-15"/>
+ <output-file compare="Text">q15_parser.txt</output-file>
+ </test-case>
+ <test-case name="json-parser-q16" FilePath="Json/Parser/Partition-4" Creator="Christina Pavlopoulou">
+ <description>Parsing a collection of json files.</description>
+ <query name="q16_parser" date="2016-07-15"/>
+ <output-file compare="Text">q16_parser.txt</output-file>
+ </test-case>
</test-group>
[6/6] vxquery git commit: some array access cleanup
Posted by pr...@apache.org.
some array access cleanup
- extract common code in SequencePointable and ArrayPointable to
AbstractSequencePointable
- add code to extract sequences from arrays to ArrayPointable and use it
in JnMembersScalarEvaluator and KeysOrMembersScalarEvaluator
- reduce complexity of KeysOrMembersScalarEvaluator.evaluate by introducing
a switch and pulling exception wrapping further out
Project: http://git-wip-us.apache.org/repos/asf/vxquery/repo
Commit: http://git-wip-us.apache.org/repos/asf/vxquery/commit/6effe1b5
Tree: http://git-wip-us.apache.org/repos/asf/vxquery/tree/6effe1b5
Diff: http://git-wip-us.apache.org/repos/asf/vxquery/diff/6effe1b5
Branch: refs/heads/master
Commit: 6effe1b59689b6de81ba2259d0ba20f2db781e24
Parents: f927258
Author: Till Westmann <ti...@apache.org>
Authored: Wed Jul 13 21:49:21 2016 -0700
Committer: Preston Carman <pr...@apache.org>
Committed: Tue Jul 19 08:40:22 2016 -0700
----------------------------------------------------------------------
.../accessors/AbstractSequencePointable.java | 59 ++++++++++++++++++++
.../datamodel/accessors/SequencePointable.java | 46 ++-------------
.../accessors/jsonitem/ArrayPointable.java | 48 +++++-----------
.../json/JnMembersScalarEvaluator.java | 56 ++++++-------------
.../json/KeysOrMembersScalarEvaluator.java | 58 +++++++------------
5 files changed, 115 insertions(+), 152 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/vxquery/blob/6effe1b5/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/AbstractSequencePointable.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/AbstractSequencePointable.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/AbstractSequencePointable.java
new file mode 100644
index 0000000..2fdfcef
--- /dev/null
+++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/AbstractSequencePointable.java
@@ -0,0 +1,59 @@
+/*
+ * 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;
+
+import org.apache.hyracks.data.std.api.AbstractPointable;
+import org.apache.hyracks.data.std.api.IPointable;
+import org.apache.hyracks.data.std.primitive.IntegerPointable;
+
+public class AbstractSequencePointable extends AbstractPointable {
+ private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
+ private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
+
+ public int getEntryCount() {
+ return getEntryCount(bytes, start);
+ }
+
+ protected static int getEntryCount(byte[] bytes, int start) {
+ return IntegerPointable.getInteger(bytes, start);
+ }
+
+ public void getEntry(int idx, IPointable pointer) {
+ int dataAreaOffset = getDataAreaOffset(bytes, start);
+ pointer.set(bytes, dataAreaOffset + getRelativeEntryStartOffset(idx), getEntryLength(idx));
+ }
+
+ static int getSlotValue(byte[] bytes, int start, int idx) {
+ return IntegerPointable.getInteger(bytes, getSlotArrayOffset(start) + idx * SLOT_SIZE);
+ }
+
+ 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);
+ }
+
+ private static int getSlotArrayOffset(int start) {
+ return start + ENTRY_COUNT_SIZE;
+ }
+
+ static int getDataAreaOffset(byte[] bytes, int start) {
+ return getSlotArrayOffset(start) + getEntryCount(bytes, start) * SLOT_SIZE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/6effe1b5/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java
index 9ccac0b..401f606 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/SequencePointable.java
@@ -17,15 +17,11 @@
package org.apache.vxquery.datamodel.accessors;
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.VoidPointable;
-public class SequencePointable extends AbstractPointable {
- private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
- private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
+public class SequencePointable extends AbstractSequencePointable {
public static final IPointableFactory FACTORY = new IPointableFactory() {
private static final long serialVersionUID = 1L;
@@ -41,40 +37,8 @@ public class SequencePointable extends AbstractPointable {
};
public static int getSequenceLength(byte[] bytes, int start) {
- int entryCount = getEntryCount(bytes, start);
- return getSlotValue(bytes, start, entryCount - 1) + (getDataAreaOffset(bytes, start) - start);
+ int entryCount = AbstractSequencePointable.getEntryCount(bytes, start);
+ return AbstractSequencePointable.getSlotValue(bytes, start, entryCount - 1)
+ + (AbstractSequencePointable.getDataAreaOffset(bytes, start) - start);
}
-
- public int getEntryCount() {
- return getEntryCount(bytes, start);
- }
-
- private static int getEntryCount(byte[] bytes, int start) {
- return IntegerPointable.getInteger(bytes, start);
- }
-
- public void getEntry(int idx, IPointable pointer) {
- int dataAreaOffset = getDataAreaOffset(bytes, start);
- pointer.set(bytes, dataAreaOffset + getRelativeEntryStartOffset(idx), getEntryLength(idx));
- }
-
- private static int getSlotValue(byte[] bytes, int start, int idx) {
- return IntegerPointable.getInteger(bytes, getSlotArrayOffset(start) + idx * SLOT_SIZE);
- }
-
- 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);
- }
-
- 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;
- }
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/6effe1b5/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 462b4d6..306c8d5 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
@@ -16,16 +16,17 @@
*/
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.VoidPointable;
+import org.apache.vxquery.datamodel.accessors.AbstractSequencePointable;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
-public class ArrayPointable extends AbstractPointable {
- private static final int ENTRY_COUNT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
- private static final int SLOT_SIZE = IntegerPointable.TYPE_TRAITS.getFixedLength();
+public class ArrayPointable extends AbstractSequencePointable {
public static final IPointableFactory FACTORY = new IPointableFactory() {
private static final long serialVersionUID = 1L;
@@ -40,36 +41,13 @@ public class ArrayPointable extends AbstractPointable {
}
};
- public int getEntryCount() {
- return getEntryCount(bytes, start);
- }
-
- private static int getEntryCount(byte[] bytes, int start) {
- return IntegerPointable.getInteger(bytes, start);
- }
-
- public void getEntry(int idx, IPointable pointer) {
- int dataStart = getDataStart(bytes, start);
- pointer.set(bytes, dataStart + getRelativeEntryStartOffset(idx), getEntryLength(idx));
- }
-
- private static int getEntryOffsetValue(byte[] bytes, int start, int idx) {
- return IntegerPointable.getInteger(bytes, getOffsetsStart(start) + idx * SLOT_SIZE);
- }
+ private TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
- private int getRelativeEntryStartOffset(int idx) {
- return idx == 0 ? 0 : getEntryOffsetValue(bytes, start, idx - 1);
- }
-
- private int getEntryLength(int idx) {
- return getEntryOffsetValue(bytes, start, idx) - getRelativeEntryStartOffset(idx);
- }
-
- private static int getOffsetsStart(int start) {
- return start + ENTRY_COUNT_SIZE;
- }
-
- private static int getDataStart(byte[] bytes, int start) {
- return getOffsetsStart(start) + getEntryCount(bytes, start) * SLOT_SIZE;
+ public void appendItems(SequenceBuilder sb) throws IOException {
+ final int size = getEntryCount();
+ for (int j = 0; j < size; j++) {
+ getEntry(j, tvp);
+ sb.addItem(tvp);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/6effe1b5/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnMembersScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnMembersScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnMembersScalarEvaluator.java
index 5777cbc..7b588c0 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnMembersScalarEvaluator.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/JnMembersScalarEvaluator.java
@@ -34,68 +34,46 @@ import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScal
public class JnMembersScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
protected final IHyracksTaskContext ctx;
- private final SequencePointable sp1, sp2;
+ private final SequencePointable sp;
private final ArrayBackedValueStorage abvs;
private final SequenceBuilder sb;
private ArrayPointable ap;
+ private TaggedValuePointable tempTvp;
public JnMembersScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) {
super(args);
this.ctx = ctx;
- sp1 = (SequencePointable) SequencePointable.FACTORY.createPointable();
- sp2 = (SequencePointable) SequencePointable.FACTORY.createPointable();
+ sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
abvs = new ArrayBackedValueStorage();
sb = new SequenceBuilder();
ap = (ArrayPointable) ArrayPointable.FACTORY.createPointable();
+ tempTvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
}
@Override
protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
TaggedValuePointable tvp = args[0];
- TaggedValuePointable tvp1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
- abvs.reset();
- sb.reset(abvs);
- if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
- TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class);
- try {
- tvp.getValue(sp1);
- int size1 = sp1.getEntryCount();
+ try {
+ abvs.reset();
+ sb.reset(abvs);
+ if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
+ tvp.getValue(sp);
+ int size1 = sp.getEntryCount();
for (int i = 0; i < size1; i++) {
- sp1.getEntry(i, tempTvp);
+ sp.getEntry(i, tempTvp);
if (tempTvp.getTag() == ValueTag.ARRAY_TAG) {
- membersSequence(tempTvp, result, tvp1);
- } else {
- XDMConstants.setEmptySequence(result);
+ tempTvp.getValue(ap);
+ ap.appendItems(sb);
}
}
- } finally {
- ppool.giveBack(tempTvp);
+ } else if (tvp.getTag() == ValueTag.ARRAY_TAG) {
+ tvp.getValue(ap);
+ ap.appendItems(sb);
}
- } else if (tvp.getTag() == ValueTag.ARRAY_TAG) {
- membersSequence(tvp, result, tvp1);
- } else {
- XDMConstants.setEmptySequence(result);
- }
- try {
sb.finish();
result.set(abvs);
} catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void membersSequence(TaggedValuePointable tvp, IPointable result, TaggedValuePointable tvp1)
- throws SystemException {
- tvp.getValue(ap);
- tvp.getValue(sp2);
- int size = sp2.getEntryCount();
- for (int j = 0; j < size; j++) {
- sp2.getEntry(j, tvp1);
- try {
- sb.addItem(tvp1);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
- }
+ throw new SystemException(ErrorCode.SYSE0001, e);
}
}
}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/6effe1b5/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
----------------------------------------------------------------------
diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
index 81afd94..b19985a 100644
--- a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
+++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/json/KeysOrMembersScalarEvaluator.java
@@ -16,11 +16,12 @@
*/
package org.apache.vxquery.runtime.functions.json;
+import java.io.IOException;
+
import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator;
import org.apache.hyracks.api.context.IHyracksTaskContext;
import org.apache.hyracks.data.std.api.IPointable;
import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-import org.apache.vxquery.datamodel.accessors.SequencePointable;
import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
import org.apache.vxquery.datamodel.accessors.jsonitem.ArrayPointable;
import org.apache.vxquery.datamodel.accessors.jsonitem.ObjectPointable;
@@ -30,13 +31,10 @@ import org.apache.vxquery.exceptions.ErrorCode;
import org.apache.vxquery.exceptions.SystemException;
import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import java.io.IOException;
-
public class KeysOrMembersScalarEvaluator extends AbstractTaggedValueArgumentScalarEvaluator {
protected final IHyracksTaskContext ctx;
private final ObjectPointable op;
private final ArrayPointable ap;
- private final SequencePointable sp;
private final ArrayBackedValueStorage abvs;
private final SequenceBuilder sb;
private final TaggedValuePointable tempTvp;
@@ -48,45 +46,31 @@ public class KeysOrMembersScalarEvaluator extends AbstractTaggedValueArgumentSca
ap = (ArrayPointable) ArrayPointable.FACTORY.createPointable();
abvs = new ArrayBackedValueStorage();
sb = new SequenceBuilder();
- sp = (SequencePointable) SequencePointable.FACTORY.createPointable();
tempTvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
}
@Override
protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
- TaggedValuePointable tvp1 = args[0];
- if (!((tvp1.getTag() == ValueTag.OBJECT_TAG) || (tvp1.getTag() == ValueTag.ARRAY_TAG))) {
- throw new SystemException(ErrorCode.FORG0006);
- }
- if (tvp1.getTag() == ValueTag.OBJECT_TAG) {
- try {
- tvp1.getValue(op);
- op.getKeys(result);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
-
- }
- } else if (tvp1.getTag() == ValueTag.ARRAY_TAG) {
- abvs.reset();
- sb.reset(abvs);
- tvp1.getValue(ap);
- tvp1.getValue(sp);
- int size = sp.getEntryCount();
- for (int i = 0; i < size; i++) {
- sp.getEntry(i, tempTvp);
- try {
- sb.addItem(tempTvp);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
- }
+ final TaggedValuePointable tvp = args[0];
+ try {
+ switch (tvp.getTag()) {
+ case ValueTag.OBJECT_TAG:
+ tvp.getValue(op);
+ op.getKeys(result);
+ break;
+ case ValueTag.ARRAY_TAG:
+ abvs.reset();
+ sb.reset(abvs);
+ tvp.getValue(ap);
+ ap.appendItems(sb);
+ sb.finish();
+ result.set(abvs);
+ break;
+ default:
+ throw new SystemException(ErrorCode.FORG0006);
}
- try {
- sb.finish();
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
- }
- result.set(abvs);
+ } catch (IOException e) {
+ throw new SystemException(ErrorCode.SYSE0001, e);
}
}
-
}