Search in sources :

Example 11 with FilterUnsupportedException

use of org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException in project carbondata by apache.

the class InExpression method evaluate.

@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult leftRsult = left.evaluate(value);
    if (setOfExprResult == null) {
        ExpressionResult rightRsult = right.evaluate(value);
        ExpressionResult val = null;
        setOfExprResult = new HashSet<ExpressionResult>(10);
        for (ExpressionResult expressionResVal : rightRsult.getList()) {
            if (expressionResVal.getDataType().getPrecedenceOrder() < leftRsult.getDataType().getPrecedenceOrder()) {
                val = leftRsult;
            } else {
                val = expressionResVal;
            }
            switch(val.getDataType()) {
                case STRING:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getString());
                    break;
                case SHORT:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getShort());
                    break;
                case INT:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getInt());
                    break;
                case DOUBLE:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getDouble());
                    break;
                case LONG:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getLong());
                    break;
                case DATE:
                case TIMESTAMP:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getTime());
                    break;
                case DECIMAL:
                    val = new ExpressionResult(val.getDataType(), expressionResVal.getDecimal());
                    break;
                default:
                    throw new FilterUnsupportedException("DataType: " + val.getDataType() + " not supported for the filter expression");
            }
            setOfExprResult.add(val);
        }
    }
    // Example: (null==null) -> Left null return false, (1==null) would automatically be false.
    if (leftRsult.isNull()) {
        leftRsult.set(DataType.BOOLEAN, false);
    } else {
        leftRsult.set(DataType.BOOLEAN, setOfExprResult.contains(leftRsult));
    }
    return leftRsult;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 12 with FilterUnsupportedException

use of org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException in project carbondata by apache.

the class LessThanEqualToExpression method evaluate.

public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult elRes = left.evaluate(value);
    ExpressionResult erRes = right.evaluate(value);
    ExpressionResult exprResValue1 = elRes;
    if (elRes.isNull() || erRes.isNull()) {
        elRes.set(DataType.BOOLEAN, false);
        return elRes;
    }
    if (elRes.getDataType() != erRes.getDataType()) {
        if (elRes.getDataType().getPrecedenceOrder() < erRes.getDataType().getPrecedenceOrder()) {
            exprResValue1 = erRes;
        }
    }
    boolean result = false;
    switch(exprResValue1.getDataType()) {
        case STRING:
            result = elRes.getString().compareTo(erRes.getString()) <= 0;
            break;
        case SHORT:
            result = elRes.getShort() <= (erRes.getShort());
            break;
        case INT:
            result = elRes.getInt() <= (erRes.getInt());
            break;
        case DOUBLE:
            result = elRes.getDouble() <= (erRes.getDouble());
            break;
        case DATE:
        case TIMESTAMP:
            result = elRes.getTime() <= (erRes.getTime());
            break;
        case LONG:
            result = elRes.getLong() <= (erRes.getLong());
            break;
        case DECIMAL:
            result = elRes.getDecimal().compareTo(erRes.getDecimal()) <= 0;
            break;
        default:
            throw new FilterUnsupportedException("DataType: " + exprResValue1.getDataType() + " not supported for the filter expression");
    }
    exprResValue1.set(DataType.BOOLEAN, result);
    return exprResValue1;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 13 with FilterUnsupportedException

use of org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException in project carbondata by apache.

the class LessThanExpression method evaluate.

public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult erRes = right.evaluate(value);
    ExpressionResult elRes = left.evaluate(value);
    ExpressionResult val1 = elRes;
    boolean result = false;
    if (elRes.isNull() || erRes.isNull()) {
        elRes.set(DataType.BOOLEAN, false);
        return elRes;
    }
    if (elRes.getDataType() != erRes.getDataType()) {
        if (elRes.getDataType().getPrecedenceOrder() < erRes.getDataType().getPrecedenceOrder()) {
            val1 = erRes;
        }
    }
    switch(val1.getDataType()) {
        case STRING:
            result = elRes.getString().compareTo(erRes.getString()) < 0;
            break;
        case SHORT:
            result = elRes.getShort() < (erRes.getShort());
            break;
        case INT:
            result = elRes.getInt() < (erRes.getInt());
            break;
        case DOUBLE:
            result = elRes.getDouble() < (erRes.getDouble());
            break;
        case DATE:
        case TIMESTAMP:
            result = elRes.getTime() < (erRes.getTime());
            break;
        case LONG:
            result = elRes.getLong() < (erRes.getLong());
            break;
        case DECIMAL:
            result = elRes.getDecimal().compareTo(erRes.getDecimal()) < 0;
            break;
        default:
            throw new FilterUnsupportedException("DataType: " + val1.getDataType() + " not supported for the filter expression");
    }
    val1.set(DataType.BOOLEAN, result);
    return val1;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 14 with FilterUnsupportedException

use of org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException in project carbondata by apache.

the class NotEqualsExpression method evaluate.

@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult elRes = left.evaluate(value);
    ExpressionResult erRes = right.evaluate(value);
    boolean result = false;
    ExpressionResult val1 = elRes;
    ExpressionResult val2 = erRes;
    if (elRes.isNull() || erRes.isNull()) {
        if (isNotNull) {
            elRes.set(DataType.BOOLEAN, elRes.isNull() != erRes.isNull());
        } else {
            elRes.set(DataType.BOOLEAN, false);
        }
        return elRes;
    }
    //default implementation if the data types are different for the resultsets
    if (elRes.getDataType() != erRes.getDataType()) {
        //            result = elRes.getString().equals(erRes.getString());
        if (elRes.getDataType().getPrecedenceOrder() < erRes.getDataType().getPrecedenceOrder()) {
            val1 = erRes;
            val2 = elRes;
        }
    }
    switch(val1.getDataType()) {
        case STRING:
            result = !val1.getString().equals(val2.getString());
            break;
        case SHORT:
            result = val1.getShort().shortValue() != val2.getShort().shortValue();
            break;
        case INT:
            result = val1.getInt().intValue() != val2.getInt().intValue();
            break;
        case DOUBLE:
            result = val1.getDouble().doubleValue() != val2.getDouble().doubleValue();
            break;
        case DATE:
        case TIMESTAMP:
            result = val1.getTime().longValue() != val2.getTime().longValue();
            break;
        case LONG:
            result = elRes.getLong().longValue() != (erRes.getLong()).longValue();
            break;
        case DECIMAL:
            result = elRes.getDecimal().compareTo(erRes.getDecimal()) != 0;
            break;
        default:
            throw new FilterUnsupportedException("DataType: " + val1.getDataType() + " not supported for the filter expression");
    }
    val1.set(DataType.BOOLEAN, result);
    return val1;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 15 with FilterUnsupportedException

use of org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException in project carbondata by apache.

the class NotInExpression method evaluate.

@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    // we will return false for each of them.
    if (nullValuePresent != null) {
        return nullValuePresent;
    }
    ExpressionResult leftRsult = left.evaluate(value);
    if (leftRsult.isNull()) {
        leftRsult.set(DataType.BOOLEAN, false);
        return leftRsult;
    }
    if (setOfExprResult == null) {
        ExpressionResult val = null;
        ExpressionResult rightRsult = right.evaluate(value);
        setOfExprResult = new HashSet<ExpressionResult>(10);
        for (ExpressionResult exprResVal : rightRsult.getList()) {
            if (exprResVal.isNull()) {
                nullValuePresent = new ExpressionResult(DataType.BOOLEAN, false);
                leftRsult.set(DataType.BOOLEAN, false);
                return leftRsult;
            }
            if (exprResVal.getDataType().getPrecedenceOrder() < leftRsult.getDataType().getPrecedenceOrder()) {
                val = leftRsult;
            } else {
                val = exprResVal;
            }
            switch(val.getDataType()) {
                case STRING:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getString());
                    break;
                case SHORT:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getShort());
                    break;
                case INT:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getInt());
                    break;
                case DOUBLE:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getDouble());
                    break;
                case DATE:
                case TIMESTAMP:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getTime());
                    break;
                case LONG:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getLong());
                    break;
                case DECIMAL:
                    val = new ExpressionResult(val.getDataType(), exprResVal.getDecimal());
                    break;
                default:
                    throw new FilterUnsupportedException("DataType: " + val.getDataType() + " not supported for the filter expression");
            }
            setOfExprResult.add(val);
        }
    }
    leftRsult.set(DataType.BOOLEAN, !setOfExprResult.contains(leftRsult));
    return leftRsult;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Aggregations

FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)18 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)14 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)6 DimColumnFilterInfo (org.apache.carbondata.core.scan.filter.DimColumnFilterInfo)5 ArrayList (java.util.ArrayList)4 Comparator (java.util.Comparator)1 DirectDictionaryGenerator (org.apache.carbondata.core.keygenerator.directdictionary.DirectDictionaryGenerator)1 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)1 EqualToExpression (org.apache.carbondata.core.scan.expression.conditional.EqualToExpression)1 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)1