Search in sources :

Example 1 with ExpressionResult

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

the class RangeExpression method getLiteralsResult.

private void getLiteralsResult(Expression expression, List<ExpressionResult> listOfExp) {
    for (Expression child : expression.getChildren()) {
        if (child instanceof LiteralExpression) {
            ExpressionResult colExp = ((LiteralExpression) child).getExpressionResult();
            listOfExp.add(colExp);
        } else {
            getLiteralsResult(child, listOfExp);
        }
    }
}
Also used : Expression(org.apache.carbondata.core.scan.expression.Expression) BinaryConditionalExpression(org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression)

Example 2 with ExpressionResult

use of org.apache.carbondata.core.scan.expression.ExpressionResult 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 3 with ExpressionResult

use of org.apache.carbondata.core.scan.expression.ExpressionResult 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 4 with ExpressionResult

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

the class FilterUtil method getFilterListForRS.

/**
   * Method will prepare the  dimfilterinfo instance by resolving the filter
   * expression value to its respective surrogates in the scenario of restructure.
   *
   * @param expression
   * @param columnExpression
   * @param defaultValues
   * @param defaultSurrogate
   * @return
   * @throws FilterUnsupportedException
   */
public static DimColumnFilterInfo getFilterListForRS(Expression expression, ColumnExpression columnExpression, String defaultValues, int defaultSurrogate) throws FilterUnsupportedException {
    List<Integer> filterValuesList = new ArrayList<Integer>(20);
    DimColumnFilterInfo columnFilterInfo = null;
    // List<byte[]> filterValuesList = new ArrayList<byte[]>(20);
    List<String> evaluateResultListFinal = new ArrayList<String>(20);
    // KeyGeneratorFactory.getKeyGenerator(new int[] { defaultSurrogate });
    try {
        List<ExpressionResult> evaluateResultList = expression.evaluate(null).getList();
        for (ExpressionResult result : evaluateResultList) {
            if (result.getString() == null) {
                evaluateResultListFinal.add(CarbonCommonConstants.MEMBER_DEFAULT_VAL);
                continue;
            }
            evaluateResultListFinal.add(result.getString());
        }
        for (int i = 0; i < evaluateResultListFinal.size(); i++) {
            if (evaluateResultListFinal.get(i).equals(defaultValues)) {
                filterValuesList.add(defaultSurrogate);
                break;
            }
        }
        if (filterValuesList.size() > 0) {
            columnFilterInfo = new DimColumnFilterInfo();
            columnFilterInfo.setFilterList(filterValuesList);
        }
    } catch (FilterIllegalMemberException e) {
        LOGGER.audit(e.getMessage());
    }
    return columnFilterInfo;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ArrayList(java.util.ArrayList) FilterIllegalMemberException(org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)

Example 5 with ExpressionResult

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

the class BinaryLogicalExpression method getExpressionResultList.

private void getExpressionResultList(Expression binaryConditionalExpression, List<ExpressionResult> listOfExp) {
    if (binaryConditionalExpression instanceof LiteralExpression) {
        ExpressionResult colExp = ((LiteralExpression) binaryConditionalExpression).getExpressionResult();
        listOfExp.add(colExp);
    }
    for (Expression child : binaryConditionalExpression.getChildren()) {
        getExpressionResultList(child, listOfExp);
    }
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) Expression(org.apache.carbondata.core.scan.expression.Expression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) BinaryExpression(org.apache.carbondata.core.scan.expression.BinaryExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression)

Aggregations

ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)99 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)81 Test (org.junit.Test)81 MockUp (mockit.MockUp)78 ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)77 FilterUnsupportedException (org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)14 BigDecimal (java.math.BigDecimal)8 Timestamp (java.sql.Timestamp)8 DateFormat (java.text.DateFormat)8 ParseException (java.text.ParseException)8 SimpleDateFormat (java.text.SimpleDateFormat)8 Date (java.util.Date)8 Decimal (org.apache.spark.sql.types.Decimal)8 ArrayList (java.util.ArrayList)6 FilterIllegalMemberException (org.apache.carbondata.core.scan.expression.exception.FilterIllegalMemberException)5 RowIntf (org.apache.carbondata.core.scan.filter.intf.RowIntf)4 Expression (org.apache.carbondata.core.scan.expression.Expression)3 BinaryConditionalExpression (org.apache.carbondata.core.scan.expression.conditional.BinaryConditionalExpression)3 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)2 DimColumnFilterInfo (org.apache.carbondata.core.scan.filter.DimColumnFilterInfo)2