Search in sources :

Example 6 with ConstraintImpl

use of org.apache.jackrabbit.oak.query.ast.ConstraintImpl in project jackrabbit-oak by apache.

the class SQL2Parser method parseCondition.

private ConstraintImpl parseCondition(DynamicOperandImpl left) throws ParseException {
    ConstraintImpl c;
    if (readIf("=")) {
        c = factory.comparison(left, Operator.EQUAL, parseStaticOperand());
    } else if (readIf("<>")) {
        c = factory.comparison(left, Operator.NOT_EQUAL, parseStaticOperand());
    } else if (readIf("<")) {
        c = factory.comparison(left, Operator.LESS_THAN, parseStaticOperand());
    } else if (readIf(">")) {
        c = factory.comparison(left, Operator.GREATER_THAN, parseStaticOperand());
    } else if (readIf("<=")) {
        c = factory.comparison(left, Operator.LESS_OR_EQUAL, parseStaticOperand());
    } else if (readIf(">=")) {
        c = factory.comparison(left, Operator.GREATER_OR_EQUAL, parseStaticOperand());
    } else if (readIf("LIKE")) {
        c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
        if (supportSQL1) {
            if (readIf("ESCAPE")) {
                StaticOperandImpl esc = parseStaticOperand();
                if (!(esc instanceof LiteralImpl)) {
                    throw getSyntaxError("only ESCAPE '\' is supported");
                }
                PropertyValue v = ((LiteralImpl) esc).getLiteralValue();
                if (!v.getValue(Type.STRING).equals("\\")) {
                    throw getSyntaxError("only ESCAPE '\' is supported");
                }
            }
        }
    } else if (readIf("IN")) {
        read("(");
        ArrayList<StaticOperandImpl> list = new ArrayList<StaticOperandImpl>();
        do {
            StaticOperandImpl x = parseStaticOperand();
            list.add(x);
        } while (readIf(","));
        read(")");
        c = factory.in(left, list);
    } else if (readIf("IS")) {
        boolean not = readIf("NOT");
        read("NULL");
        if (!(left instanceof PropertyValueImpl)) {
            throw getSyntaxError("propertyName (NOT NULL is only supported for properties)");
        }
        PropertyValueImpl p = (PropertyValueImpl) left;
        if (not) {
            c = getPropertyExistence(p);
        } else {
            c = getPropertyInexistence(p);
        }
    } else if (readIf("NOT")) {
        if (readIf("IS")) {
            read("NULL");
            if (!(left instanceof PropertyValueImpl)) {
                throw new ParseException("Only property values can be tested for NOT IS NULL; got: " + left.getClass().getName(), parseIndex);
            }
            PropertyValueImpl pv = (PropertyValueImpl) left;
            c = getPropertyExistence(pv);
        } else {
            read("LIKE");
            c = factory.comparison(left, Operator.LIKE, parseStaticOperand());
            c = factory.not(c);
        }
    } else {
        throw getSyntaxError();
    }
    return c;
}
Also used : LiteralImpl(org.apache.jackrabbit.oak.query.ast.LiteralImpl) ConstraintImpl(org.apache.jackrabbit.oak.query.ast.ConstraintImpl) StaticOperandImpl(org.apache.jackrabbit.oak.query.ast.StaticOperandImpl) ArrayList(java.util.ArrayList) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ParseException(java.text.ParseException) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)

Example 7 with ConstraintImpl

use of org.apache.jackrabbit.oak.query.ast.ConstraintImpl in project jackrabbit-oak by apache.

the class QueryCostOverheadTest method getCostOverhead.

@Test
public void getCostOverhead() {
    QueryImpl query;
    UnionQueryImpl union;
    ConstraintImpl c, c1, c2, c3, c4, c5;
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    union = new UnionQueryImpl(false, new QueryImpl(null, null, c1, null, null, null), new QueryImpl(null, null, c2, null, null, null), null);
    assertFalse("we always expect false from a `UnionQueryImpl`", union.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c = new OrImpl(c1, c2);
    query = new QueryImpl(null, null, c, null, null, null);
    assertTrue(query.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c = new OrImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertTrue(query.containsUnfilteredFullTextCondition());
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c4 = new ComparisonImpl(null, null, null);
    c1 = new OrImpl(of(c2, c3, c4));
    c5 = mock(DescendantNodeImpl.class);
    c = new AndImpl(c1, c5);
    query = new QueryImpl(null, null, c, null, null, null);
    assertTrue(query.containsUnfilteredFullTextCondition());
    c = new FullTextSearchImpl(null, null, null);
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
    c1 = new FullTextSearchImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c = new OrImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c = new AndImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new ComparisonImpl(null, null, null);
    c = new AndImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
}
Also used : ComparisonImpl(org.apache.jackrabbit.oak.query.ast.ComparisonImpl) ConstraintImpl(org.apache.jackrabbit.oak.query.ast.ConstraintImpl) FullTextSearchImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl) DescendantNodeImpl(org.apache.jackrabbit.oak.query.ast.DescendantNodeImpl) AndImpl(org.apache.jackrabbit.oak.query.ast.AndImpl) OrImpl(org.apache.jackrabbit.oak.query.ast.OrImpl) Test(org.junit.Test)

Aggregations

ConstraintImpl (org.apache.jackrabbit.oak.query.ast.ConstraintImpl)7 AndImpl (org.apache.jackrabbit.oak.query.ast.AndImpl)2 FullTextSearchImpl (org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl)2 LiteralImpl (org.apache.jackrabbit.oak.query.ast.LiteralImpl)2 OrImpl (org.apache.jackrabbit.oak.query.ast.OrImpl)2 StaticOperandImpl (org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)1 ColumnImpl (org.apache.jackrabbit.oak.query.ast.ColumnImpl)1 ComparisonImpl (org.apache.jackrabbit.oak.query.ast.ComparisonImpl)1 DescendantNodeImpl (org.apache.jackrabbit.oak.query.ast.DescendantNodeImpl)1 DynamicOperandImpl (org.apache.jackrabbit.oak.query.ast.DynamicOperandImpl)1 PropertyValueImpl (org.apache.jackrabbit.oak.query.ast.PropertyValueImpl)1 SourceImpl (org.apache.jackrabbit.oak.query.ast.SourceImpl)1 Test (org.junit.Test)1