Search in sources :

Example 1 with SequenceAxis

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();
    }
}
Also used : SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) ModOpAxis(org.sirix.service.xml.xpath.operators.ModOpAxis) RangeAxis(org.sirix.service.xml.xpath.expr.RangeAxis) AddOpAxis(org.sirix.service.xml.xpath.operators.AddOpAxis) ExceptAxis(org.sirix.service.xml.xpath.expr.ExceptAxis) Axis(org.sirix.api.Axis) MulOpAxis(org.sirix.service.xml.xpath.operators.MulOpAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) IfAxis(org.sirix.service.xml.xpath.expr.IfAxis) IntersectAxis(org.sirix.service.xml.xpath.expr.IntersectAxis) IDivOpAxis(org.sirix.service.xml.xpath.operators.IDivOpAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) PredicateFilterAxis(org.sirix.axis.filter.PredicateFilterAxis) VariableAxis(org.sirix.service.xml.xpath.expr.VariableAxis) ForAxis(org.sirix.axis.ForAxis) SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) SubOpAxis(org.sirix.service.xml.xpath.operators.SubOpAxis) DivOpAxis(org.sirix.service.xml.xpath.operators.DivOpAxis)

Example 2 with SequenceAxis

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."));
    }
}
Also used : SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Example 3 with SequenceAxis

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."));
    }
}
Also used : SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Example 4 with SequenceAxis

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."));
    }
}
Also used : SirixXPathException(org.sirix.exception.SirixXPathException) SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) Test(org.junit.Test)

Example 5 with SequenceAxis

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."));
    }
}
Also used : SequenceAxis(org.sirix.service.xml.xpath.expr.SequenceAxis) AbstractAxis(org.sirix.service.xml.xpath.AbstractAxis) XPathError(org.sirix.service.xml.xpath.XPathError) Test(org.junit.Test)

Aggregations

SequenceAxis (org.sirix.service.xml.xpath.expr.SequenceAxis)7 Test (org.junit.Test)6 AbstractAxis (org.sirix.service.xml.xpath.AbstractAxis)6 XPathError (org.sirix.service.xml.xpath.XPathError)5 Axis (org.sirix.api.Axis)1 ForAxis (org.sirix.axis.ForAxis)1 FilterAxis (org.sirix.axis.filter.FilterAxis)1 PredicateFilterAxis (org.sirix.axis.filter.PredicateFilterAxis)1 SirixXPathException (org.sirix.exception.SirixXPathException)1 ExceptAxis (org.sirix.service.xml.xpath.expr.ExceptAxis)1 IfAxis (org.sirix.service.xml.xpath.expr.IfAxis)1 IntersectAxis (org.sirix.service.xml.xpath.expr.IntersectAxis)1 RangeAxis (org.sirix.service.xml.xpath.expr.RangeAxis)1 UnionAxis (org.sirix.service.xml.xpath.expr.UnionAxis)1 VariableAxis (org.sirix.service.xml.xpath.expr.VariableAxis)1 DupFilterAxis (org.sirix.service.xml.xpath.filter.DupFilterAxis)1 AddOpAxis (org.sirix.service.xml.xpath.operators.AddOpAxis)1 DivOpAxis (org.sirix.service.xml.xpath.operators.DivOpAxis)1 IDivOpAxis (org.sirix.service.xml.xpath.operators.IDivOpAxis)1 ModOpAxis (org.sirix.service.xml.xpath.operators.ModOpAxis)1