Search in sources :

Example 1 with FilterUnsupportedException

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

the class RangeExpression method evaluate.

@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult resultLeft = left.evaluate(value);
    ExpressionResult resultRight = right.evaluate(value);
    switch(resultLeft.getDataType()) {
        case BOOLEAN:
            resultLeft.set(DataType.BOOLEAN, (resultLeft.getBoolean() && resultRight.getBoolean()));
            break;
        default:
            throw new FilterUnsupportedException("Incompatible datatype for applying RANGE Expression Filter");
    }
    return resultLeft;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 2 with FilterUnsupportedException

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

the class EqualToExpression 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 (isNull) {
            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()) {
        if (elRes.getDataType().getPrecedenceOrder() < erRes.getDataType().getPrecedenceOrder()) {
            val2 = elRes;
            val1 = erRes;
        }
    }
    switch(val1.getDataType()) {
        case STRING:
            result = val1.getString().equals(val2.getString());
            break;
        case SHORT:
            result = val1.getShort().equals(val2.getShort());
            break;
        case INT:
            result = val1.getInt().equals(val2.getInt());
            break;
        case DOUBLE:
            result = FilterUtil.nanSafeEqualsDoubles(val1.getDouble(), val2.getDouble());
            break;
        case DATE:
        case TIMESTAMP:
            result = val1.getTime().equals(val2.getTime());
            break;
        case LONG:
            result = val1.getLong().equals(val2.getLong());
            break;
        case DECIMAL:
            result = val1.getDecimal().compareTo(val2.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 3 with FilterUnsupportedException

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

the class FilterUtil method getNoDictionaryValKeyMemberForFilter.

/**
   * This method will get the no dictionary data based on filters and same
   * will be in DimColumnFilterInfo
   *
   * @param evaluateResultListFinal
   * @param isIncludeFilter
   * @return DimColumnFilterInfo
   */
public static DimColumnFilterInfo getNoDictionaryValKeyMemberForFilter(List<String> evaluateResultListFinal, boolean isIncludeFilter, DataType dataType) throws FilterUnsupportedException {
    List<byte[]> filterValuesList = new ArrayList<byte[]>(20);
    String result = null;
    try {
        int length = evaluateResultListFinal.size();
        for (int i = 0; i < length; i++) {
            result = evaluateResultListFinal.get(i);
            if (CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(result)) {
                filterValuesList.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL_ARRAY);
                continue;
            }
            filterValuesList.add(DataTypeUtil.getBytesBasedOnDataTypeForNoDictionaryColumn(result, dataType));
        }
    } catch (Throwable ex) {
        throw new FilterUnsupportedException("Unsupported Filter condition: " + result, ex);
    }
    Comparator<byte[]> filterNoDictValueComaparator = new Comparator<byte[]>() {

        @Override
        public int compare(byte[] filterMember1, byte[] filterMember2) {
            // TODO Auto-generated method stub
            return ByteUtil.UnsafeComparer.INSTANCE.compareTo(filterMember1, filterMember2);
        }
    };
    Collections.sort(filterValuesList, filterNoDictValueComaparator);
    DimColumnFilterInfo columnFilterInfo = null;
    if (filterValuesList.size() > 0) {
        columnFilterInfo = new DimColumnFilterInfo();
        columnFilterInfo.setIncludeFilter(isIncludeFilter);
        columnFilterInfo.setFilterListForNoDictionaryCols(filterValuesList);
    }
    return columnFilterInfo;
}
Also used : ArrayList(java.util.ArrayList) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException) Comparator(java.util.Comparator)

Example 4 with FilterUnsupportedException

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

the class OrExpression method evaluate.

@Override
public ExpressionResult evaluate(RowIntf value) throws FilterIllegalMemberException, FilterUnsupportedException {
    ExpressionResult resultLeft = left.evaluate(value);
    ExpressionResult resultRight = right.evaluate(value);
    switch(resultLeft.getDataType()) {
        case BOOLEAN:
            resultLeft.set(DataType.BOOLEAN, (resultLeft.getBoolean() || resultRight.getBoolean()));
            break;
        default:
            throw new FilterUnsupportedException("Incompatible datatype for applying OR Expression Filter");
    }
    return resultLeft;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 5 with FilterUnsupportedException

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

the class GreaterThanExpression method evaluate.

@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult exprLeftRes = left.evaluate(value);
    ExpressionResult exprRightRes = right.evaluate(value);
    ExpressionResult val1 = exprLeftRes;
    if (exprLeftRes.isNull() || exprRightRes.isNull()) {
        exprLeftRes.set(DataType.BOOLEAN, false);
        return exprLeftRes;
    }
    if (exprLeftRes.getDataType() != exprRightRes.getDataType()) {
        if (exprLeftRes.getDataType().getPrecedenceOrder() < exprRightRes.getDataType().getPrecedenceOrder()) {
            val1 = exprRightRes;
        }
    }
    boolean result = false;
    switch(val1.getDataType()) {
        case STRING:
            result = exprLeftRes.getString().compareTo(exprRightRes.getString()) > 0;
            break;
        case DOUBLE:
            result = exprLeftRes.getDouble() > (exprRightRes.getDouble());
            break;
        case SHORT:
            result = exprLeftRes.getShort() > (exprRightRes.getShort());
            break;
        case INT:
            result = exprLeftRes.getInt() > (exprRightRes.getInt());
            break;
        case DATE:
        case TIMESTAMP:
            result = exprLeftRes.getTime() > (exprRightRes.getTime());
            break;
        case LONG:
            result = exprLeftRes.getLong() > (exprRightRes.getLong());
            break;
        case DECIMAL:
            result = exprLeftRes.getDecimal().compareTo(exprRightRes.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)

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