You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by vi...@apache.org on 2012/08/08 14:58:44 UTC
svn commit: r1370750 [2/2] - in /incubator/vxquery/trunk/vxquery:
vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/
vxquery-core/src/main/java/org/apache/vxquery/datamodel/accessors/nodes/
vxquery-core/src/main/java/org/apache/vxquery/...
Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/SequenceTypeMatcher.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/SequenceTypeMatcher.java?rev=1370750&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/SequenceTypeMatcher.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/SequenceTypeMatcher.java Wed Aug 8 12:58:42 2012
@@ -0,0 +1,154 @@
+package org.apache.vxquery.runtime.functions.type;
+
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
+import org.apache.vxquery.datamodel.accessors.nodes.PINodePointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.types.AnyItemType;
+import org.apache.vxquery.types.AtomicType;
+import org.apache.vxquery.types.AttributeType;
+import org.apache.vxquery.types.BuiltinTypeRegistry;
+import org.apache.vxquery.types.DocumentType;
+import org.apache.vxquery.types.ElementType;
+import org.apache.vxquery.types.ItemType;
+import org.apache.vxquery.types.NodeKind;
+import org.apache.vxquery.types.NodeType;
+import org.apache.vxquery.types.ProcessingInstructionType;
+import org.apache.vxquery.types.Quantifier;
+import org.apache.vxquery.types.SchemaType;
+import org.apache.vxquery.types.SequenceType;
+
+import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
+
+public class SequenceTypeMatcher {
+ private final NodeTreePointable ntp = (NodeTreePointable) NodeTreePointable.FACTORY.createPointable();
+ private final TaggedValuePointable tempTVP1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+ private final PINodePointable pinp = (PINodePointable) PINodePointable.FACTORY.createPointable();
+ private final UTF8StringPointable utf8sp = (UTF8StringPointable) UTF8StringPointable.FACTORY.createPointable();
+ private final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
+ private final TaggedValuePointable tempTVP2 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+
+ private SequenceType sequenceType;
+
+ public boolean sequenceTypeMatch(TaggedValuePointable tvp) {
+ byte tag = tvp.getTag();
+ Quantifier stq = sequenceType.getQuantifier();
+ ItemType it = sequenceType.getItemType();
+ if (tag == ValueTag.SEQUENCE_TAG) {
+ tvp.getValue(seqp);
+ Quantifier vq = getSequenceQuantifier(seqp);
+ if (stq.isSubQuantifier(vq)) {
+ if (it instanceof AnyItemType) {
+ return true;
+ } else {
+ int n = seqp.getEntryCount();
+ for (int i = 0; i < n; ++i) {
+ seqp.getEntry(i, tempTVP2);
+ if (!itemSequenceTypeMatch(tempTVP2, it)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+ } else {
+ if (stq.isSubQuantifier(Quantifier.QUANT_ONE)) {
+ return itemSequenceTypeMatch(tvp, it);
+ }
+ }
+ return false;
+ }
+
+ private boolean itemSequenceTypeMatch(TaggedValuePointable tvp, ItemType it) {
+ byte tag = tvp.getTag();
+ if (it instanceof AnyItemType) {
+ return true;
+ } else if (it.isAtomicType()) {
+ AtomicType ait = (AtomicType) it;
+ if (BuiltinTypeRegistry.INSTANCE.isBuiltinTypeId(tag)) {
+ SchemaType vType = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tag);
+ while (vType != null && vType.getTypeId() != ait.getTypeId()) {
+ vType = vType.getBaseType();
+ }
+ return vType != null;
+ }
+ } else if (it instanceof NodeType && tag == ValueTag.NODE_TREE_TAG) {
+ NodeType nt = (NodeType) it;
+ NodeKind kind = nt.getNodeKind();
+ if (kind == NodeKind.ANY) {
+ return true;
+ } else {
+ tvp.getValue(ntp);
+ ntp.getRootNode(tempTVP1);
+ switch (tempTVP1.getTag()) {
+ case ValueTag.ATTRIBUTE_NODE_TAG:
+ if (kind == NodeKind.ATTRIBUTE) {
+ if (nt.equals(AttributeType.ANYATTRIBUTE)) {
+ return true;
+ } else {
+
+ }
+ }
+ break;
+
+ case ValueTag.COMMENT_NODE_TAG:
+ return kind == NodeKind.ATTRIBUTE;
+
+ case ValueTag.DOCUMENT_NODE_TAG:
+ if (kind == NodeKind.DOCUMENT) {
+ if (nt.equals(DocumentType.ANYDOCUMENT)) {
+ return true;
+ } else {
+
+ }
+ }
+ break;
+
+ case ValueTag.ELEMENT_NODE_TAG:
+ if (kind == NodeKind.ELEMENT) {
+ if (nt.equals(ElementType.ANYELEMENT)) {
+ return true;
+ } else {
+
+ }
+ }
+ break;
+
+ case ValueTag.PI_NODE_TAG:
+ if (kind == NodeKind.PI) {
+ if (nt.equals(ProcessingInstructionType.ANYPI)) {
+ return true;
+ } else {
+ ProcessingInstructionType pit = (ProcessingInstructionType) nt;
+ tempTVP1.getValue(pinp);
+ pinp.getTarget(ntp, utf8sp);
+ byte[] target = pit.getTarget();
+ return utf8sp.compareTo(target, 0, target.length) == 0;
+ }
+ }
+ break;
+
+ case ValueTag.TEXT_NODE_TAG:
+ return kind == NodeKind.TEXT;
+ }
+ }
+ }
+ return false;
+ }
+
+ private Quantifier getSequenceQuantifier(SequencePointable seqp) {
+ switch (seqp.getEntryCount()) {
+ case 0:
+ return Quantifier.QUANT_ZERO;
+
+ case 1:
+ return Quantifier.QUANT_ONE;
+ }
+ return Quantifier.QUANT_PLUS;
+ }
+
+ public void setSequenceType(SequenceType sType) {
+ this.sequenceType = sType;
+ }
+}
\ No newline at end of file
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java?rev=1370750&r1=1370749&r2=1370750&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/TreatScalarEvaluatorFactory.java Wed Aug 8 12:58:42 2012
@@ -1,24 +1,8 @@
package org.apache.vxquery.runtime.functions.type;
-import org.apache.vxquery.datamodel.accessors.SequencePointable;
import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.NodeTreePointable;
-import org.apache.vxquery.datamodel.accessors.nodes.PINodePointable;
-import org.apache.vxquery.datamodel.values.ValueTag;
import org.apache.vxquery.exceptions.ErrorCode;
import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.types.AnyItemType;
-import org.apache.vxquery.types.AtomicType;
-import org.apache.vxquery.types.AttributeType;
-import org.apache.vxquery.types.BuiltinTypeRegistry;
-import org.apache.vxquery.types.DocumentType;
-import org.apache.vxquery.types.ElementType;
-import org.apache.vxquery.types.ItemType;
-import org.apache.vxquery.types.NodeKind;
-import org.apache.vxquery.types.NodeType;
-import org.apache.vxquery.types.ProcessingInstructionType;
-import org.apache.vxquery.types.Quantifier;
-import org.apache.vxquery.types.SchemaType;
import org.apache.vxquery.types.SequenceType;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -26,7 +10,6 @@ import edu.uci.ics.hyracks.algebricks.ru
import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.primitive.UTF8StringPointable;
public class TreatScalarEvaluatorFactory extends AbstractTypeScalarEvaluatorFactory {
private static final long serialVersionUID = 1L;
@@ -39,147 +22,20 @@ public class TreatScalarEvaluatorFactory
protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
throws AlgebricksException {
return new AbstractTypeScalarEvaluator(args, ctx) {
- private final NodeTreePointable ntp = (NodeTreePointable) NodeTreePointable.FACTORY.createPointable();
- private final TaggedValuePointable tempTVP1 = (TaggedValuePointable) TaggedValuePointable.FACTORY
- .createPointable();
- private final PINodePointable pinp = (PINodePointable) PINodePointable.FACTORY.createPointable();
- private final UTF8StringPointable utf8sp = (UTF8StringPointable) UTF8StringPointable.FACTORY
- .createPointable();
- private final SequencePointable seqp = (SequencePointable) SequencePointable.FACTORY.createPointable();
- private final TaggedValuePointable tempTVP2 = (TaggedValuePointable) TaggedValuePointable.FACTORY
- .createPointable();
-
- private SequenceType sequenceType;
+ private final SequenceTypeMatcher matcher = new SequenceTypeMatcher();
@Override
protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
- boolean success = sequenceTypeMatch(tvp);
+ boolean success = matcher.sequenceTypeMatch(tvp);
if (!success) {
throw new SystemException(ErrorCode.XPDY0050);
}
result.set(tvp);
}
- private boolean sequenceTypeMatch(TaggedValuePointable tvp) {
- byte tag = tvp.getTag();
- Quantifier stq = sequenceType.getQuantifier();
- ItemType it = sequenceType.getItemType();
- if (tag == ValueTag.SEQUENCE_TAG) {
- tvp.getValue(seqp);
- Quantifier vq = getSequenceQuantifier(seqp);
- if (stq.isSubQuantifier(vq)) {
- if (it instanceof AnyItemType) {
- return true;
- } else {
- int n = seqp.getEntryCount();
- for (int i = 0; i < n; ++i) {
- seqp.getEntry(i, tempTVP2);
- if (!itemSequenceTypeMatch(tempTVP2, it)) {
- return false;
- }
- }
- return true;
- }
- }
- } else {
- if (stq.isSubQuantifier(Quantifier.QUANT_ONE)) {
- return itemSequenceTypeMatch(tvp, it);
- }
- }
- return false;
- }
-
- private boolean itemSequenceTypeMatch(TaggedValuePointable tvp, ItemType it) {
- byte tag = tvp.getTag();
- if (it instanceof AnyItemType) {
- return true;
- } else if (it.isAtomicType()) {
- AtomicType ait = (AtomicType) it;
- if (BuiltinTypeRegistry.INSTANCE.isBuiltinTypeId(tag)) {
- SchemaType vType = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tag);
- while (vType != null && vType.getTypeId() != ait.getTypeId()) {
- vType = vType.getBaseType();
- }
- return vType != null;
- }
- } else if (it instanceof NodeType && tag == ValueTag.NODE_TREE_TAG) {
- NodeType nt = (NodeType) it;
- NodeKind kind = nt.getNodeKind();
- if (kind == NodeKind.ANY) {
- return true;
- } else {
- tvp.getValue(ntp);
- ntp.getRootNode(tempTVP1);
- switch (tempTVP1.getTag()) {
- case ValueTag.ATTRIBUTE_NODE_TAG:
- if (kind == NodeKind.ATTRIBUTE) {
- if (nt.equals(AttributeType.ANYATTRIBUTE)) {
- return true;
- } else {
-
- }
- }
- break;
-
- case ValueTag.COMMENT_NODE_TAG:
- return kind == NodeKind.ATTRIBUTE;
-
- case ValueTag.DOCUMENT_NODE_TAG:
- if (kind == NodeKind.DOCUMENT) {
- if (nt.equals(DocumentType.ANYDOCUMENT)) {
- return true;
- } else {
-
- }
- }
- break;
-
- case ValueTag.ELEMENT_NODE_TAG:
- if (kind == NodeKind.ELEMENT) {
- if (nt.equals(ElementType.ANYELEMENT)) {
- return true;
- } else {
-
- }
- }
- break;
-
- case ValueTag.PI_NODE_TAG:
- if (kind == NodeKind.PI) {
- if (nt.equals(ProcessingInstructionType.ANYPI)) {
- return true;
- } else {
- ProcessingInstructionType pit = (ProcessingInstructionType) nt;
- tempTVP1.getValue(pinp);
- pinp.getTarget(ntp, utf8sp);
- byte[] target = pit.getTarget();
- return utf8sp.compareTo(target, 0, target.length) == 0;
- }
- }
- break;
-
- case ValueTag.TEXT_NODE_TAG:
- return kind == NodeKind.TEXT;
- }
- }
- }
- return false;
- }
-
- private Quantifier getSequenceQuantifier(SequencePointable seqp) {
- switch (seqp.getEntryCount()) {
- case 0:
- return Quantifier.QUANT_ZERO;
-
- case 1:
- return Quantifier.QUANT_ONE;
- }
- return Quantifier.QUANT_PLUS;
- }
-
@Override
protected void setSequenceType(SequenceType sType) {
- this.sequenceType = sType;
+ matcher.setSequenceType(sType);
}
};
}
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java?rev=1370750&r1=1370749&r2=1370750&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/serializer/XMLSerializer.java Wed Aug 8 12:58:42 2012
@@ -210,6 +210,9 @@ public class XMLSerializer implements IP
}
private void printNodeTree(PrintStream ps, TaggedValuePointable tvp) {
+ if (ntp != null) {
+ throw new IllegalStateException("Nested NodeTreePointable found");
+ }
ntp = pp.takeOne(NodeTreePointable.class);
TaggedValuePointable rootTVP = pp.takeOne(TaggedValuePointable.class);
try {
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java?rev=1370750&r1=1370749&r2=1370750&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/xmlquery/translator/XMLQueryTranslator.java Wed Aug 8 12:58:42 2012
@@ -905,7 +905,7 @@ public class XMLQueryTranslator {
throws SystemException {
LogicalVariable lVar = createAssignment(
sfce(BuiltinOperators.TEXT_CONSTRUCTOR,
- ce(SequenceType.create(BuiltinTypeRegistry.XS_STRING, Quantifier.QUANT_ONE),
+ ce(SequenceType.create(BuiltinTypeRegistry.XS_UNTYPED_ATOMIC, Quantifier.QUANT_ONE),
cdsNode.getContent())), tCtx);
return lVar;
}
@@ -973,7 +973,7 @@ public class XMLQueryTranslator {
throws SystemException {
ASTNode content = cNode.getContent();
LogicalVariable lVar = createAssignment(
- sfce(BuiltinOperators.TEXT_CONSTRUCTOR, vre(translateExpression(cNode.getTarget(), tCtx)),
+ sfce(BuiltinOperators.PI_CONSTRUCTOR, vre(translateExpression(cNode.getTarget(), tCtx)),
content == null ? sfce(BuiltinOperators.CONCATENATE) : vre(translateExpression(content, tCtx))),
tCtx);
return lVar;
@@ -983,8 +983,10 @@ public class XMLQueryTranslator {
ComputedTextConstructorNode cNode) throws SystemException {
ASTNode content = cNode.getContent();
LogicalVariable lVar = createAssignment(
- sfce(BuiltinOperators.TEXT_CONSTRUCTOR, content == null ? sfce(BuiltinOperators.CONCATENATE)
- : vre(translateExpression(content, tCtx))), tCtx);
+ sfce(BuiltinOperators.TEXT_CONSTRUCTOR,
+ content == null ? ce(
+ SequenceType.create(BuiltinTypeRegistry.XS_UNTYPED_ATOMIC, Quantifier.QUANT_ONE), "")
+ : vre(translateExpression(content, tCtx))), tCtx);
return lVar;
}
@@ -1131,8 +1133,7 @@ public class XMLQueryTranslator {
private LogicalVariable translateDirectAttributeConstructorNode(TranslationContext tCtx,
DirectAttributeConstructorNode dacNode) throws SystemException {
QName aQName = createQName(dacNode.getName());
- ILogicalExpression name = ce(SequenceType.create(BuiltinTypeRegistry.XS_QNAME, Quantifier.QUANT_ONE),
- aQName.toString());
+ ILogicalExpression name = ce(SequenceType.create(BuiltinTypeRegistry.XS_QNAME, Quantifier.QUANT_ONE), aQName);
List<ILogicalExpression> content = new ArrayList<ILogicalExpression>();
for (ASTNode aVal : dacNode.getValue()) {
switch (aVal.getTag()) {
@@ -1185,7 +1186,7 @@ public class XMLQueryTranslator {
}
}
ILogicalExpression name = ce(SequenceType.create(BuiltinTypeRegistry.XS_QNAME, Quantifier.QUANT_ONE),
- createQName(startName, moduleCtx.getDefaultElementNamespaceUri()).toString());
+ createQName(startName, moduleCtx.getDefaultElementNamespaceUri()));
for (ASTNode cVal : decNode.getContent()) {
switch (cVal.getTag()) {
case CONTENT_CHARS: {
@@ -1566,7 +1567,9 @@ public class XMLQueryTranslator {
uri = "";
}
}
- NameTest nameTest = new NameTest(createUTF8String(uri), createUTF8String(ntn.getLocalName()));
+ String localName = ntn.getLocalName();
+ NameTest nameTest = new NameTest(uri == null ? null : createUTF8String(uri),
+ localName == null ? null : createUTF8String(ntn.getLocalName()));
if (axis == AxisStepNode.Axis.ATTRIBUTE || axis == AxisStepNode.Axis.ABBREV_ATTRIBUTE) {
nt = new AttributeType(nameTest, BuiltinTypeRegistry.XS_ANY_ATOMIC);
} else {
@@ -1818,82 +1821,78 @@ public class XMLQueryTranslator {
}
private ILogicalExpression ce(SequenceType type, Object value) throws SystemException {
- ItemType it = type.getItemType();
- if (it.isAtomicType()) {
- AtomicType at = (AtomicType) it;
- byte[] bytes = null;
- switch (at.getTypeId()) {
- case BuiltinTypeConstants.XS_BOOLEAN_TYPE_ID: {
- baaos.reset();
- try {
+ try {
+ ItemType it = type.getItemType();
+ if (it.isAtomicType()) {
+ AtomicType at = (AtomicType) it;
+ byte[] bytes = null;
+ switch (at.getTypeId()) {
+ case BuiltinTypeConstants.XS_BOOLEAN_TYPE_ID: {
+ baaos.reset();
dOut.write((byte) ValueTag.XS_BOOLEAN_TAG);
dOut.writeByte(((Boolean) value).booleanValue() ? 1 : 0);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
+ break;
}
- break;
- }
- case BuiltinTypeConstants.XS_INT_TYPE_ID: {
- baaos.reset();
- try {
+ case BuiltinTypeConstants.XS_INT_TYPE_ID: {
+ baaos.reset();
dOut.write((byte) ValueTag.XS_INT_TAG);
dOut.writeInt(((Number) value).intValue());
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
+ break;
}
- break;
- }
- case BuiltinTypeConstants.XS_INTEGER_TYPE_ID: {
- baaos.reset();
- try {
+ case BuiltinTypeConstants.XS_INTEGER_TYPE_ID: {
+ baaos.reset();
dOut.write((byte) ValueTag.XS_INTEGER_TAG);
dOut.writeLong(((Number) value).longValue());
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
+ break;
}
- break;
- }
- case BuiltinTypeConstants.XS_DOUBLE_TYPE_ID: {
- baaos.reset();
- try {
+ case BuiltinTypeConstants.XS_DOUBLE_TYPE_ID: {
+ baaos.reset();
dOut.write((byte) ValueTag.XS_DOUBLE_TAG);
dOut.writeDouble(((Number) value).doubleValue());
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
+ break;
}
- break;
- }
- case BuiltinTypeConstants.XS_STRING_TYPE_ID: {
- baaos.reset();
- try {
+ case BuiltinTypeConstants.XS_STRING_TYPE_ID: {
+ baaos.reset();
dOut.write((byte) ValueTag.XS_STRING_TAG);
stringVB.write((CharSequence) value, dOut);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
+ break;
}
- break;
- }
- case BuiltinTypeConstants.XS_DECIMAL_TYPE_ID: {
- baaos.reset();
- try {
+ case BuiltinTypeConstants.XS_DECIMAL_TYPE_ID: {
+ baaos.reset();
// TODO Remove the creation of the separate byte array.
DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
- doublep.set(new byte[DoublePointable.TYPE_TRAITS.getFixedLength()], 0, DoublePointable.TYPE_TRAITS.getFixedLength());
+ doublep.set(new byte[DoublePointable.TYPE_TRAITS.getFixedLength()], 0,
+ DoublePointable.TYPE_TRAITS.getFixedLength());
doublep.setDouble(((Number) value).doubleValue());
CastToDecimalOperation castToDecimal = new CastToDecimalOperation();
castToDecimal.convertDouble(doublep, dOut);
- } catch (IOException e) {
- throw new SystemException(ErrorCode.SYSE0001, e);
+ break;
}
- break;
+ case BuiltinTypeConstants.XS_QNAME_TYPE_ID: {
+ QName qname = (QName) value;
+ baaos.reset();
+ dOut.write((byte) ValueTag.XS_QNAME_TAG);
+ stringVB.write(qname.getNamespaceURI(), dOut);
+ stringVB.write(qname.getPrefix(), dOut);
+ stringVB.write(qname.getLocalPart(), dOut);
+ break;
+ }
+ case BuiltinTypeConstants.XS_UNTYPED_ATOMIC_TYPE_ID: {
+ baaos.reset();
+ dOut.write((byte) ValueTag.XS_UNTYPED_ATOMIC_TAG);
+ stringVB.write((CharSequence) value, dOut);
+ break;
+ }
+ default:
+ throw new SystemException(ErrorCode.SYSE0001);
}
- default:
- throw new SystemException(ErrorCode.SYSE0001);
+ bytes = Arrays.copyOf(baaos.getByteArray(), baaos.size());
+ return new ConstantExpression(new VXQueryConstantValue(type, bytes));
}
- bytes = Arrays.copyOf(baaos.getByteArray(), baaos.size());
- return new ConstantExpression(new VXQueryConstantValue(type, bytes));
+ throw new UnsupportedOperationException();
+ } catch (IOException e) {
+ throw new SystemException(ErrorCode.SYSE0001, e);
}
- throw new UnsupportedOperationException();
}
private static ILogicalExpression vre(LogicalVariable var) {
Modified: incubator/vxquery/trunk/vxquery/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java?rev=1370750&r1=1370749&r2=1370750&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-xtest/src/main/java/org/apache/vxquery/xtest/TestRunnerFactory.java Wed Aug 8 12:58:42 2012
@@ -22,6 +22,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.apache.vxquery.compiler.CompilerControlBlock;
@@ -30,6 +32,7 @@ import org.apache.vxquery.context.Dynami
import org.apache.vxquery.context.DynamicContextImpl;
import org.apache.vxquery.context.RootStaticContextImpl;
import org.apache.vxquery.context.StaticContextImpl;
+import org.apache.vxquery.exceptions.ErrorCode;
import org.apache.vxquery.exceptions.SystemException;
import org.apache.vxquery.xmlquery.query.XMLQueryCompiler;
@@ -46,6 +49,9 @@ import edu.uci.ics.hyracks.control.nc.No
import edu.uci.ics.hyracks.dataflow.std.file.FileSplit;
public class TestRunnerFactory {
+ private static final Pattern EMBEDDED_SYSERROR_PATTERN = Pattern
+ .compile("org\\.apache\\.vxquery\\.exceptions\\.SystemException: (\\p{javaUpperCase}{4}\\d{4})");
+
private List<ResultReporter> reporters;
private XTestOptions opts;
private ClusterControllerService cc;
@@ -108,27 +114,38 @@ public class TestRunnerFactory {
}
long start = System.currentTimeMillis();
try {
- XMLQueryCompiler compiler = new XMLQueryCompiler(null);
- File tempFile = File.createTempFile(testCase.getXQueryFile().getName(), ".tmp");
- tempFile.deleteOnExit();
- Reader in = new InputStreamReader(new FileInputStream(testCase.getXQueryFile()), "UTF-8");
- CompilerControlBlock ccb = new CompilerControlBlock(new StaticContextImpl(
- RootStaticContextImpl.INSTANCE), new FileSplit[] { new FileSplit("nc1",
- tempFile.getAbsolutePath()) });
- compiler.compile(testCase.getXQueryDisplayName(), in, ccb, opts.optimizationLevel);
- JobSpecification spec = compiler.getModule().getHyracksJobSpecification();
-
- DynamicContext dCtx = new DynamicContextImpl(compiler.getModule().getModuleContext());
- spec.setGlobalJobDataFactory(new VXQueryGlobalDataFactory(dCtx.createFactory()));
-
- spec.setMaxReattempts(0);
- JobId jobId = hcc.startJob("test", spec, EnumSet.of(JobFlag.PROFILE_RUNTIME));
- hcc.waitForCompletion(jobId);
- res.result = FileUtils.readFileToString(tempFile, "UTF-8").trim();
+ try {
+ XMLQueryCompiler compiler = new XMLQueryCompiler(null);
+ File tempFile = File.createTempFile(testCase.getXQueryFile().getName(), ".tmp");
+ tempFile.deleteOnExit();
+ Reader in = new InputStreamReader(new FileInputStream(testCase.getXQueryFile()), "UTF-8");
+ CompilerControlBlock ccb = new CompilerControlBlock(new StaticContextImpl(
+ RootStaticContextImpl.INSTANCE), new FileSplit[] { new FileSplit("nc1",
+ tempFile.getAbsolutePath()) });
+ compiler.compile(testCase.getXQueryDisplayName(), in, ccb, opts.optimizationLevel);
+ JobSpecification spec = compiler.getModule().getHyracksJobSpecification();
+
+ DynamicContext dCtx = new DynamicContextImpl(compiler.getModule().getModuleContext());
+ spec.setGlobalJobDataFactory(new VXQueryGlobalDataFactory(dCtx.createFactory()));
+
+ spec.setMaxReattempts(0);
+ JobId jobId = hcc.startJob("test", spec, EnumSet.of(JobFlag.PROFILE_RUNTIME));
+ hcc.waitForCompletion(jobId);
+ res.result = FileUtils.readFileToString(tempFile, "UTF-8").trim();
+ } catch (HyracksException e) {
+ Throwable t = e;
+ while (t.getCause() != null) {
+ t = t.getCause();
+ }
+ Matcher m = EMBEDDED_SYSERROR_PATTERN.matcher(t.getMessage());
+ if (m.find()) {
+ String eCode = m.group(1);
+ throw new SystemException(ErrorCode.valueOf(eCode), e);
+ }
+ throw e;
+ }
} catch (SystemException e) {
res.error = e;
- } catch (HyracksException e) {
- res.error = e;
} catch (Throwable e) {
res.error = e;
} finally {