use of org.sirix.service.xml.xpath.expr.SequenceAxis in project sirix by sirixdb.
the class PipelineBuilder method finishExpr.
/**
* Ends an expression. This means that the currently used pipeline stack will be emptied and the
* singleExpressions that were on the stack are combined by a sequence expression, which is lated
* added to the next pipeline stack.
*
* @param mTransaction transaction to operate on
* @param mNum number of singleExpressions that will be added to the sequence
*/
public void finishExpr(final XdmNodeReadTrx mTransaction, final int mNum) {
// of the stack containing these SingleExpressions have to be the same.
if (getPipeStack().size() != mNum) {
// this should never happen
throw new IllegalStateException("The query has not been processed correctly");
}
int no = mNum;
Axis[] axis;
if (no > 1) {
axis = new Axis[no];
// add all SingleExpression to a list
while (no-- > 0) {
axis[no] = getPipeStack().pop().getExpr();
}
if (mExprStack.size() > 1) {
assert mExprStack.peek().empty();
mExprStack.pop();
}
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(new SequenceAxis(mTransaction, axis));
} else if (no == 1) {
// only one expression does not need to be capsled by a seq
axis = new Axis[1];
axis[0] = getPipeStack().pop().getExpr();
if (mExprStack.size() > 1) {
assert mExprStack.peek().empty();
mExprStack.pop();
}
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
final Axis iAxis;
if (mExprStack.size() == 1 && getPipeStack().size() == 1 && getExpression().getSize() == 0) {
iAxis = new SequenceAxis(mTransaction, axis);
} else {
iAxis = axis[0];
}
getExpression().add(iAxis);
} else {
mExprStack.pop();
}
}
use of org.sirix.service.xml.xpath.expr.SequenceAxis in project sirix by sirixdb.
the class IDivOpAxisTest method testGetReturnType.
@Test
public final void testGetReturnType() throws SirixException {
AbstractAxis op1 = new SequenceAxis(holder.getReader());
AbstractAxis op2 = new SequenceAxis(holder.getReader());
AbstractObAxis axis = new IDivOpAxis(holder.getReader(), op1, op2);
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
assertEquals(Type.INTEGER, axis.getReturnType(holder.getReader().keyForName("xs:integer"), holder.getReader().keyForName("xs:integer")));
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:double"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:IDREF"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
}
use of org.sirix.service.xml.xpath.expr.SequenceAxis in project sirix by sirixdb.
the class ModOpAxisTest method testGetReturnType.
@Test
public final void testGetReturnType() throws SirixException {
AbstractAxis op1 = new SequenceAxis(holder.getReader());
AbstractAxis op2 = new SequenceAxis(holder.getReader());
AbstractObAxis axis = new ModOpAxis(holder.getReader(), op1, op2);
assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.FLOAT, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:double"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:IDREF"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
}
use of org.sirix.service.xml.xpath.expr.SequenceAxis in project sirix by sirixdb.
the class AddOpAxisTest method testGetReturnType.
@Test
public final void testGetReturnType() throws SirixException {
AbstractAxis op1 = new SequenceAxis(holder.getReader());
AbstractAxis op2 = new SequenceAxis(holder.getReader());
AbstractObAxis axis = new AddOpAxis(holder.getReader(), op1, op2);
assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.FLOAT, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
// assertEquals(Type.INTEGER,
// axis.getReturnType(holder.getRtx().keyForName("xs:integer"),
// holder.getRtx().keyForName("xs:integer")));
assertEquals(Type.YEAR_MONTH_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:yearMonthDuration"), holder.getReader().keyForName("xs:yearMonthDuration")));
assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:dayTimeDuration"), holder.getReader().keyForName("xs:dayTimeDuration")));
assertEquals(Type.DATE, axis.getReturnType(holder.getReader().keyForName("xs:date"), holder.getReader().keyForName("xs:yearMonthDuration")));
assertEquals(Type.DATE, axis.getReturnType(holder.getReader().keyForName("xs:date"), holder.getReader().keyForName("xs:dayTimeDuration")));
assertEquals(Type.TIME, axis.getReturnType(holder.getReader().keyForName("xs:time"), holder.getReader().keyForName("xs:dayTimeDuration")));
assertEquals(Type.DATE_TIME, axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:yearMonthDuration")));
assertEquals(Type.DATE_TIME, axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:dayTimeDuration")));
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:dateTime"));
fail("Expected an XPathError-Exception.");
} catch (final SirixXPathException e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:double"));
fail("Expected an XPathError-Exception.");
} catch (final SirixXPathException e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (final SirixXPathException e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:IDREF"));
fail("Expected an XPathError-Exception.");
} catch (final SirixXPathException e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
}
use of org.sirix.service.xml.xpath.expr.SequenceAxis in project sirix by sirixdb.
the class DivOpAxisTest method testGetReturnType.
@Test
public final void testGetReturnType() throws SirixException {
AbstractAxis op1 = new SequenceAxis(holder.getReader());
AbstractAxis op2 = new SequenceAxis(holder.getReader());
AbstractObAxis axis = new DivOpAxis(holder.getReader(), op1, op2);
assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:double"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.DOUBLE, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.FLOAT, axis.getReturnType(holder.getReader().keyForName("xs:float"), holder.getReader().keyForName("xs:decimal")));
assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:decimal"), holder.getReader().keyForName("xs:integer")));
// assertEquals(Type.INTEGER,
// axis.getReturnType(holder.getRtx().keyForName("xs:integer"),
// holder.getRtx().keyForName("xs:integer")));
assertEquals(Type.YEAR_MONTH_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:yearMonthDuration"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.DAY_TIME_DURATION, axis.getReturnType(holder.getReader().keyForName("xs:dayTimeDuration"), holder.getReader().keyForName("xs:double")));
assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:yearMonthDuration"), holder.getReader().keyForName("xs:yearMonthDuration")));
assertEquals(Type.DECIMAL, axis.getReturnType(holder.getReader().keyForName("xs:dayTimeDuration"), holder.getReader().keyForName("xs:dayTimeDuration")));
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:double"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:string"), holder.getReader().keyForName("xs:yearMonthDuration"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
try {
axis.getReturnType(holder.getReader().keyForName("xs:dateTime"), holder.getReader().keyForName("xs:IDREF"));
fail("Expected an XPathError-Exception.");
} catch (XPathError e) {
assertThat(e.getMessage(), is("err:XPTY0004 The type is not appropriate the expression or the " + "typedoes not match a required type as specified by the matching rules."));
}
}
Aggregations