http://git-wip-us.apache.org/repos/asf/vxquery/blob/47442458/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluator.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluator.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluator.java new file mode 100644 index 0000000..cadf2b9 --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluator.java @@ -0,0 +1,68 @@ +/* + * 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.node; + +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.IMutableValueStorage; +import org.apache.hyracks.data.std.api.IPointable; +import org.apache.hyracks.data.std.primitive.UTF8StringPointable; +import org.apache.hyracks.data.std.primitive.VoidPointable; +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.nodes.DictionaryBuilder; +import org.apache.vxquery.datamodel.values.ValueTag; +import org.apache.vxquery.exceptions.SystemException; + +public class ArrayNodeConstructorScalarEvaluator extends AbstractNodeConstructorScalarEvaluator { + private final ArrayBuilder ab; + + private final SequencePointable sp; + + public ArrayNodeConstructorScalarEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) { + super(ctx, args); + ab = new ArrayBuilder(); + sp = (SequencePointable) SequencePointable.FACTORY.createPointable(); + } + + @Override + protected void constructNode(DictionaryBuilder db, TaggedValuePointable[] args, IMutableValueStorage mvs) + throws IOException, SystemException { + ab.reset(mvs); + TaggedValuePointable arg = args[0]; + TaggedValuePointable tempTvp = ppool.takeOne(TaggedValuePointable.class); + if (arg.getTag() == ValueTag.SEQUENCE_TAG) { + arg.getValue(sp); + for (int i = 0; i < sp.getEntryCount(); ++i) { + sp.getEntry(i, tempTvp); + ab.addItem(tempTvp); + } + ppool.giveBack(tempTvp); + } + + ab.finish(); + } + + @Override + protected boolean createsDictionary() { + return false; + } + +}
http://git-wip-us.apache.org/repos/asf/vxquery/blob/47442458/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluatorFactory.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluatorFactory.java b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluatorFactory.java new file mode 100644 index 0000000..e32034c --- /dev/null +++ b/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/node/ArrayNodeConstructorScalarEvaluatorFactory.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.vxquery.runtime.functions.node; + +import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator; +import org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory; +import org.apache.hyracks.api.context.IHyracksTaskContext; +import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory; + +public class ArrayNodeConstructorScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory { + private static final long serialVersionUID = 1L; + + public ArrayNodeConstructorScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) { + super(args); + } + + @Override + protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args) + throws AlgebricksException { + return new ArrayNodeConstructorScalarEvaluator(ctx, args); + } +} http://git-wip-us.apache.org/repos/asf/vxquery/blob/47442458/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java ---------------------------------------------------------------------- diff --git a/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java b/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java index 5c55731..b980bd6 100644 --- a/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java +++ b/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java @@ -32,6 +32,7 @@ import org.apache.vxquery.datamodel.accessors.atomic.XSDecimalPointable; import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable; import org.apache.vxquery.datamodel.accessors.atomic.XSQNamePointable; import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable; +import org.apache.vxquery.datamodel.accessors.jsonitem.ArrayPointable; import org.apache.vxquery.datamodel.accessors.nodes.AttributeNodePointable; import org.apache.vxquery.datamodel.accessors.nodes.DocumentNodePointable; import org.apache.vxquery.datamodel.accessors.nodes.ElementNodePointable; @@ -220,6 +221,10 @@ public class XMLSerializer implements IPrinter { printElementNode(ps, tvp); break; + case ValueTag.ARRAY_TAG: + printArrayNode(ps, tvp); + break; + case ValueTag.ATTRIBUTE_NODE_TAG: printAttributeNode(ps, tvp); break; @@ -441,6 +446,34 @@ public class XMLSerializer implements IPrinter { } } + private void printArrayNode(PrintStream ps, TaggedValuePointable tvp) { + ArrayPointable ap = pp.takeOne(ArrayPointable.class); + SequencePointable seqp = pp.takeOne(SequencePointable.class); + + try { + tvp.getValue(ap); + if (tvp.getTag() == ValueTag.ARRAY_TAG) { + tvp.getValue(ap); + int len = ap.getEntryCount(); + ps.append('['); + + for (int i = 0; i < len; i++) { + ap.getEntry(i, tvp); + print(tvp.getByteArray(), tvp.getStartOffset(), tvp.getLength(), ps); + if (i != len - 1) { + ps.append(','); + } + } + ps.append(']'); + } + + } finally { + pp.giveBack(ap); + pp.giveBack(seqp); + pp.giveBack(tvp); + } + } + private void printBase64Binary(PrintStream ps, TaggedValuePointable tvp) { XSBinaryPointable bp = pp.takeOne(XSBinaryPointable.class); try { http://git-wip-us.apache.org/repos/asf/vxquery/blob/47442458/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 19ba276..d684e34 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 @@ -98,6 +98,7 @@ import org.apache.vxquery.types.TextType; import org.apache.vxquery.types.TypeUtils; import org.apache.vxquery.xmlquery.ast.ASTNode; import org.apache.vxquery.xmlquery.ast.ASTTag; +import org.apache.vxquery.xmlquery.ast.ArrayConstructorNode; import org.apache.vxquery.xmlquery.ast.AtomicTypeNode; import org.apache.vxquery.xmlquery.ast.AttributeTestNode; import org.apache.vxquery.xmlquery.ast.AxisStepNode; @@ -818,6 +819,11 @@ public class XMLQueryTranslator { return translateComputedElementConstructorNode(tCtx, cNode); } + case ARRAY_CONSTRUCTOR: { + ArrayConstructorNode aNode = (ArrayConstructorNode) value; + return translateArrayConstructorNode(tCtx, aNode); + } + case COMPUTED_ATTRIBUTE_CONSTRUCTOR: { ComputedAttributeConstructorNode cNode = (ComputedAttributeConstructorNode) value; return translateComputedAttributeConstructorNode(tCtx, cNode); @@ -971,6 +977,16 @@ public class XMLQueryTranslator { return lVar; } + private LogicalVariable translateArrayConstructorNode(TranslationContext tCtx, ArrayConstructorNode aNode) + throws SystemException { + ILogicalExpression name = vre(translateExpression(aNode.getExpression(), tCtx)); + ASTNode expression = aNode.getExpression(); + ILogicalExpression aExpr = expression == null ? sfce(BuiltinOperators.CONCATENATE) + : vre(translateExpression(expression, tCtx)); + LogicalVariable lVar = createAssignment(sfce(BuiltinOperators.ARRAY_CONSTRUCTOR, name, aExpr), tCtx); + return lVar; + } + private LogicalVariable translateComputedDocumentConstructorNode(TranslationContext tCtx, ComputedDocumentConstructorNode cNode) throws SystemException { LogicalVariable lVar = createAssignment(
