Skip to content

Commit

Permalink
[TEMP BACKPORT] TEMPORARY BACKPORT OF: Fix bugs in XQSuite and XQuery…
Browse files Browse the repository at this point in the history
… tests written for XQSuite - #4622
  • Loading branch information
adamretter committed Dec 10, 2022
1 parent bd18a49 commit 02e1601
Show file tree
Hide file tree
Showing 33 changed files with 844 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Install bats
run: sudo apt-get install bats
- name: Build images
run: mvn -V -B -q -Pdocker -DskipTests -Ddependency-check.skip=true clean package
run: mvn -V -B -q -Pdocker -DskipTests -Ddependency-check.skip=true -P !mac-dmg-on-unix,!installer,!concurrency-stress-tests,!micro-benchmarks,skip-build-dist-archives clean package
- name: Check local images
run: docker image ls
- name: Check license headers
Expand Down
8 changes: 8 additions & 0 deletions exist-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@
<exclude>src/main/java/org/exist/xquery/value/SubSequence.java</exclude>
<exclude>src/test/java/org/exist/xquery/value/SubSequenceRangeTest.java</exclude>
<exclude>src/test/java/org/exist/xquery/value/SubSequenceTest.java</exclude>
<exclude>src/test/xquery/type-promotion.xqm</exclude>
<exclude>src/test/xquery/xqsuite/xqsuite-assertions-dynamic.xqm</exclude>
<exclude>src/test/xquery/xqsuite/xqsuite-assertions-inline.xqm</exclude>
<exclude>src/test/xquery/xqsuite/xqsuite-assertions.resources.xqm.ignore</exclude>

<!--
Derivative work licensed under dbXML 1.0 and LGPL 2.1
Expand Down Expand Up @@ -870,6 +874,10 @@ The original license statement is also included below.]]></preamble>
<include>src/main/java/org/exist/xquery/value/SubSequence.java</include>
<include>src/test/java/org/exist/xquery/value/SubSequenceRangeTest.java</include>
<include>src/test/java/org/exist/xquery/value/SubSequenceTest.java</include>
<include>src/test/xquery/type-promotion.xqm</include>
<include>src/test/xquery/xqsuite/xqsuite-assertions-dynamic.xqm</include>
<include>src/test/xquery/xqsuite/xqsuite-assertions-inline.xqm</include>
<include>src/test/xquery/xqsuite/xqsuite-assertions.resources.xqm.ignore</include>
</includes>

</licenseSet>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public UntypedValueCheck(XQueryContext context, int requiredType, Error error) {
public UntypedValueCheck(XQueryContext context, int requiredType, final Expression expression, Error error) {
super(context);
this.requiredType = requiredType;
if (expression instanceof Atomize && requiredType != Type.ATOMIC) {
if (expression instanceof Atomize && !Type.subTypeOf(requiredType, Type.ATOMIC)) {
this.expression = ((Atomize)expression).getExpression();
this.atomize = true;
} else {
Expand Down Expand Up @@ -109,7 +109,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathExc
}

private Item convert(Item item) throws XPathException {
if (atomize || item.getType() == Type.UNTYPED_ATOMIC || Type.subTypeOfUnion(requiredType, Type.NUMBER) && Type.subTypeOfUnion(item.getType(), Type.NUMBER)) {
if (atomize || item.getType() == Type.UNTYPED_ATOMIC || Type.hasMember(Type.NUMBER, requiredType) && Type.subTypeOfUnion(item.getType(), Type.NUMBER)) {
try {
if (Type.subTypeOf(item.getType(), requiredType)) {
return item;
Expand Down
10 changes: 9 additions & 1 deletion exist-core/src/main/java/org/exist/xquery/XQueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2645,7 +2645,15 @@ private Module importModuleFromLocation(final String namespaceURI, @Nullable fin
final Source moduleSource;
try {
//TODO: use URIs to ensure proper resolution of relative locations
moduleSource = SourceFactory.getSource(getBroker(), moduleLoadPath, location, true);
final String contextPath;
if (source instanceof FileSource) {
final Path sourcePath = ((FileSource)source).getPath();
contextPath = sourcePath.resolveSibling(moduleLoadPath).normalize().toString();
} else {
contextPath = moduleLoadPath;
}

moduleSource = SourceFactory.getSource(getBroker(), contextPath, location, true);
if (moduleSource == null) {
throw moduleLoadException("Source for module '" + namespaceURI + "' not found module location hint URI '" + location + "'.", location);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ private static void writeParameters(final FunctionSignature sig, final MemTreeBu
}

private static void writeAnnotations(final FunctionSignature signature, final MemTreeBuilder builder) throws XPathException {
final AttributesImpl attribs = new AttributesImpl();
final Annotation[] annots = signature.getAnnotations();
if (annots != null) {
final AttributesImpl attribs = new AttributesImpl();
for (final Annotation annot : annots) {
attribs.clear();
attribs.addAttribute(null, "name", "name", "CDATA", annot.getName().toString());
Expand All @@ -136,7 +136,9 @@ private static void writeAnnotations(final FunctionSignature signature, final Me
final LiteralValue[] value = annot.getValue();
if (value != null) {
for (final LiteralValue literal : value) {
builder.startElement(ANNOTATION_VALUE_QNAME, null);
attribs.clear();
attribs.addAttribute(null, "type", "type", "CDATA", Type.getTypeName(literal.returnsType()));
builder.startElement(ANNOTATION_VALUE_QNAME, attribs);
builder.characters(literal.getValue().getStringValue());
builder.endElement();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class IndexKeys extends BasicFunction {
"containing three int values: a) the overall frequency of the key within the node set, " +
"b) the number of distinct documents in the node set the key occurs in, " +
"c) the current position of the key in the whole list of keys returned."),
new FunctionParameterSequenceType("max-number-returned", Type.INT, Cardinality.ZERO_OR_ONE, "The maximum number of returned keys")
new FunctionParameterSequenceType("max-number-returned", Type.INTEGER, Cardinality.ZERO_OR_ONE, "The maximum number of returned keys")
},
new FunctionReturnSequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE, "the results of the eval of the $function-reference")),
new FunctionSignature(
Expand All @@ -79,7 +79,7 @@ public class IndexKeys extends BasicFunction {
"containing three int values: a) the overall frequency of the key within the node set, " +
"b) the number of distinct documents in the node set the key occurs in, " +
"c) the current position of the key in the whole list of keys returned."),
new FunctionParameterSequenceType("max-number-returned", Type.INT, Cardinality.ZERO_OR_ONE , "The maximum number of returned keys"),
new FunctionParameterSequenceType("max-number-returned", Type.INTEGER, Cardinality.ZERO_OR_ONE , "The maximum number of returned keys"),
new FunctionParameterSequenceType("index", Type.STRING, Cardinality.EXACTLY_ONE, "The index in which the search is made")
},
new FunctionReturnSequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE, "the results of the eval of the $function-reference")),
Expand All @@ -97,7 +97,7 @@ public class IndexKeys extends BasicFunction {
"containing three int values: a) the overall frequency of the key within the node set, " +
"b) the number of distinct documents in the node set the key occurs in, " +
"c) the current position of the key in the whole list of keys returned."),
new FunctionParameterSequenceType("max-number-returned", Type.INT, Cardinality.ZERO_OR_ONE, "The maximum number of returned keys"),
new FunctionParameterSequenceType("max-number-returned", Type.INTEGER, Cardinality.ZERO_OR_ONE, "The maximum number of returned keys"),
new FunctionParameterSequenceType("index", Type.STRING, Cardinality.EXACTLY_ONE, "The index in which the search is made")
},
new FunctionReturnSequenceType(Type.ITEM, Cardinality.ZERO_OR_MORE, "the results of the eval of the $function-reference")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class XMLDBGetMimeType extends BasicFunction {
new FunctionSignature(
new QName("get-mime-type", XMLDBModule.NAMESPACE_URI, XMLDBModule.PREFIX),
"Returns the MIME type if available of the resource $resource-uri, otherwise the empty sequence. " +
XMLDBModule.ANY_URI,
XMLDBModule.ANY_URI,
new SequenceType[] {
new FunctionParameterSequenceType("resource-uri", Type.ANY_URI, Cardinality.EXACTLY_ONE, "The resource URI")
new FunctionParameterSequenceType("resource-uri", Type.STRING, Cardinality.EXACTLY_ONE, "The resource URI")
},
new FunctionReturnSequenceType(Type.STRING, Cardinality.ZERO_OR_ONE, "the mime-type if available, otherwise the empty sequence")
);
Expand Down
2 changes: 1 addition & 1 deletion exist-core/src/main/java/org/exist/xquery/value/Type.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public class Type {
}

static {
defineUnionType(NUMBER, new int[]{ INTEGER, DECIMAL, FLOAT, DOUBLE });
defineUnionType(NUMBER, new int[]{ DECIMAL, FLOAT, DOUBLE });
}

// https://www.w3.org/TR/xmlschema-2/#built-in-primitive-datatypes
Expand Down

0 comments on commit 02e1601

Please sign in to comment.