Search in sources :

Example 46 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class SpellcheckImpl method restrict.

@Override
public void restrict(FilterImpl f) {
    if (f.getSelector().equals(selector)) {
        PropertyValue p = expression.currentValue();
        String term = p.getValue(Type.STRING);
        String query = SPELLCHECK_PREFIX + term;
        PropertyValue v = PropertyValues.newString(query);
        f.restrictProperty(NativeFunctionImpl.NATIVE_PREFIX + NATIVE_LUCENE_LANGUAGE, Operator.EQUAL, v);
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 47 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class SQL2Parser method parseStaticOperand.

private StaticOperandImpl parseStaticOperand() throws ParseException {
    if (currentTokenType == PLUS) {
        read();
        if (currentTokenType != VALUE) {
            throw getSyntaxError("number");
        }
        int valueType = currentValue.getType().tag();
        switch(valueType) {
            case PropertyType.LONG:
                currentValue = PropertyValues.newLong(currentValue.getValue(Type.LONG));
                break;
            case PropertyType.DOUBLE:
                currentValue = PropertyValues.newDouble(currentValue.getValue(Type.DOUBLE));
                break;
            case PropertyType.DECIMAL:
                currentValue = PropertyValues.newDecimal(currentValue.getValue(Type.DECIMAL).negate());
                break;
            default:
                throw getSyntaxError("Illegal operation: + " + currentValue);
        }
    } else if (currentTokenType == MINUS) {
        read();
        if (currentTokenType != VALUE) {
            throw getSyntaxError("number");
        }
        int valueType = currentValue.getType().tag();
        switch(valueType) {
            case PropertyType.LONG:
                currentValue = PropertyValues.newLong(-currentValue.getValue(Type.LONG));
                break;
            case PropertyType.DOUBLE:
                currentValue = PropertyValues.newDouble(-currentValue.getValue(Type.DOUBLE));
                break;
            case PropertyType.BOOLEAN:
                currentValue = PropertyValues.newBoolean(!currentValue.getValue(Type.BOOLEAN));
                break;
            case PropertyType.DECIMAL:
                currentValue = PropertyValues.newDecimal(currentValue.getValue(Type.DECIMAL).negate());
                break;
            default:
                throw getSyntaxError("Illegal operation: -" + currentValue);
        }
    }
    if (currentTokenType == VALUE) {
        LiteralImpl literal = getUncastLiteral(currentValue);
        read();
        return literal;
    } else if (currentTokenType == PARAMETER) {
        read();
        String name = readName();
        if (readIf(":")) {
            name = name + ':' + readName();
        }
        BindVariableValueImpl var = bindVariables.get(name);
        if (var == null) {
            var = factory.bindVariable(name);
            bindVariables.put(name, var);
        }
        return var;
    } else if (readIf("TRUE")) {
        LiteralImpl literal = getUncastLiteral(PropertyValues.newBoolean(true));
        return literal;
    } else if (readIf("FALSE")) {
        LiteralImpl literal = getUncastLiteral(PropertyValues.newBoolean(false));
        return literal;
    } else if (readIf("CAST")) {
        read("(");
        StaticOperandImpl op = parseStaticOperand();
        if (!(op instanceof LiteralImpl)) {
            throw getSyntaxError("literal");
        }
        LiteralImpl literal = (LiteralImpl) op;
        PropertyValue value = literal.getLiteralValue();
        read("AS");
        value = parseCastAs(value);
        read(")");
        // CastLiteral
        literal = factory.literal(value);
        return literal;
    } else {
        if (supportSQL1) {
            if (readIf("TIMESTAMP")) {
                StaticOperandImpl op = parseStaticOperand();
                if (!(op instanceof LiteralImpl)) {
                    throw getSyntaxError("literal");
                }
                LiteralImpl literal = (LiteralImpl) op;
                PropertyValue value = literal.getLiteralValue();
                value = PropertyValues.newDate(value.getValue(Type.DATE));
                literal = factory.literal(value);
                return literal;
            }
        }
        throw getSyntaxError("static operand");
    }
}
Also used : LiteralImpl(org.apache.jackrabbit.oak.query.ast.LiteralImpl) BindVariableValueImpl(org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl) StaticOperandImpl(org.apache.jackrabbit.oak.query.ast.StaticOperandImpl) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 48 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class ComparisonImpl method restrict.

@Override
public void restrict(FilterImpl f) {
    PropertyValue v = operand2.currentValue();
    if (!PropertyValues.canConvert(operand2.getPropertyType(), operand1.getPropertyType())) {
        throw new IllegalArgumentException("Unsupported conversion from property type " + PropertyType.nameFromValue(operand2.getPropertyType()) + " to property type " + PropertyType.nameFromValue(operand1.getPropertyType()));
    }
    if (v != null) {
        if (operator == Operator.LIKE) {
            String pattern;
            pattern = v.getValue(Type.STRING);
            LikePattern p = new LikePattern(pattern);
            String lowerBound = p.getLowerBound();
            if (lowerBound != null) {
                String upperBound = p.getUpperBound();
                if (lowerBound.equals(upperBound)) {
                    // no wildcards: equality comparison
                    // but v may contain escaped wildcards, so we can't use it
                    PropertyValue pv = PropertyValues.newString(lowerBound);
                    operand1.restrict(f, Operator.EQUAL, pv);
                } else if (operand1.supportsRangeConditions()) {
                    if (lowerBound != null) {
                        PropertyValue pv = PropertyValues.newString(lowerBound);
                        operand1.restrict(f, Operator.GREATER_OR_EQUAL, pv);
                    }
                    if (upperBound != null) {
                        PropertyValue pv = PropertyValues.newString(upperBound);
                        operand1.restrict(f, Operator.LESS_OR_EQUAL, pv);
                    }
                } else {
                    // path conditions
                    operand1.restrict(f, operator, v);
                }
            } else {
                // like '%' conditions
                operand1.restrict(f, operator, v);
            }
        } else {
            operand1.restrict(f, operator, v);
        }
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) LikePattern(org.apache.jackrabbit.oak.query.fulltext.LikePattern)

Example 49 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class EquiJoinConditionImpl method restrict.

@Override
public void restrict(FilterImpl f) {
    if (f.getSelector().equals(selector1)) {
        PropertyValue p2 = selector2.currentProperty(property2Name);
        if (p2 == null && f.isPreparing() && f.isPrepared(selector2)) {
            // during the prepare phase, if the selector is already
            // prepared, then we would know the value
            p2 = PropertyValues.newString(KNOWN_VALUE);
        }
        if (p2 != null) {
            if (p2.isArray()) {
                // TODO support join on multi-valued properties
                p2 = null;
            }
        }
        String p1n = normalizePropertyName(property1Name);
        if (p2 == null) {
            // always set the condition, 
            // even if unknown (in which case it is converted to "is not null")
            f.restrictProperty(p1n, Operator.NOT_EQUAL, null);
        } else {
            f.restrictProperty(p1n, Operator.EQUAL, p2);
        }
    }
    if (f.getSelector().equals(selector2)) {
        PropertyValue p1 = selector1.currentProperty(property1Name);
        if (p1 == null && f.isPreparing() && f.isPrepared(selector1)) {
            // during the prepare phase, if the selector is already
            // prepared, then we would know the value
            p1 = PropertyValues.newString(KNOWN_VALUE);
        }
        if (p1 != null) {
            if (p1.isArray()) {
                // TODO support join on multi-valued properties
                p1 = null;
            }
        }
        // always set the condition, even if unkown ( -> is not null)
        String p2n = normalizePropertyName(property2Name);
        f.restrictProperty(p2n, Operator.EQUAL, p1);
    }
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Example 50 with PropertyValue

use of org.apache.jackrabbit.oak.api.PropertyValue in project jackrabbit-oak by apache.

the class EquiJoinConditionImpl method evaluate.

@Override
public boolean evaluate() {
    // 6.7.8 EquiJoinCondition
    // A node-tuple satisfies the constraint only if:
    PropertyValue p1 = selector1.currentProperty(property1Name);
    if (p1 == null) {
        // the selector1Name node has a property named property1Name, and
        return false;
    }
    PropertyValue p2 = selector2.currentProperty(property2Name);
    if (p2 == null) {
        // the selector2Name node has a property named property2Name, and
        return false;
    }
    // See OAK-3416
    if (!p1.isArray() && !p2.isArray()) {
        // both are single valued
        // "the value of operand2 is converted to the
        // property type of the value of operand1"
        p2 = convertValueToType(p2, p1);
        return PropertyValues.match(p1, p2);
    }
    // TODO what is the expected result of an equi join for multi-valued properties?
    if (!p1.isArray() && p2.isArray()) {
        p1 = convertValueToType(p1, p2);
        if (p1 != null && PropertyValues.match(p1, p2)) {
            return true;
        }
        return false;
    } else if (p1.isArray() && !p2.isArray()) {
        p2 = convertValueToType(p2, p1);
        if (p2 != null && PropertyValues.match(p1, p2)) {
            return true;
        }
        return false;
    }
    return PropertyValues.match(p1, p2);
}
Also used : PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue)

Aggregations

PropertyValue (org.apache.jackrabbit.oak.api.PropertyValue)57 Test (org.junit.Test)28 ResultRow (org.apache.jackrabbit.oak.api.ResultRow)26 RemoteValue (org.apache.jackrabbit.oak.remote.RemoteValue)24 Tree (org.apache.jackrabbit.oak.api.Tree)5 ParseException (java.text.ParseException)4 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)4 ArrayList (java.util.ArrayList)3 Result (org.apache.jackrabbit.oak.api.Result)3 Date (java.util.Date)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 LiteralImpl (org.apache.jackrabbit.oak.query.ast.LiteralImpl)2 StaticOperandImpl (org.apache.jackrabbit.oak.query.ast.StaticOperandImpl)2 FulltextQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.FulltextQueryIndex)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 InvalidQueryException (javax.jcr.query.InvalidQueryException)1