Search in sources :

Example 91 with ExpressionResult

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

the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithBothStringISSame.

@Test
public void testEvaluateForNotEqualsExpressionWithBothStringISSame() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression left = new ColumnExpression("left_name", DataType.STRING);
    left.setColIndex(0);
    ColumnExpression right = new ColumnExpression("right_name", DataType.STRING);
    right.setColIndex(1);
    notEqualsExpression = new NotEqualsExpression(left, right);
    RowImpl value = new RowImpl();
    String[] row = { "string1" };
    String[] row1 = { "string2" };
    Object[] objectRow = { row, row1 };
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public String getString() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return "string1";
            } else {
                return "string2";
            }
        }
    };
    value.setValues(objectRow);
    ExpressionResult result = notEqualsExpression.evaluate(value);
    assertTrue(result.getBoolean());
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 92 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithDoubleDataType.

@Test
public void testEvaluateForNotInExpressionWithDoubleDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE);
    left.setColIndex(0);
    ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE);
    right.setColIndex(1);
    notInExpression = new NotInExpression(left, right);
    RowImpl value = new RowImpl();
    Double row = 44521D;
    Double row1 = 44521.023D;
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public Double getDouble() {
            return 44521.023D;
        }
    };
    ExpressionResult result = notInExpression.evaluate(value);
    assertTrue(result.getBoolean());
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 93 with ExpressionResult

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

the class GreaterThanEqualToExpression method evaluate.

public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
    ExpressionResult elRes = left.evaluate(value);
    ExpressionResult erRes = right.evaluate(value);
    ExpressionResult exprResVal1 = 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()) {
            exprResVal1 = erRes;
        }
    }
    boolean result = false;
    switch(exprResVal1.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: " + exprResVal1.getDataType() + " not supported for the filter expression");
    }
    exprResVal1.set(DataType.BOOLEAN, result);
    return exprResVal1;
}
Also used : ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) FilterUnsupportedException(org.apache.carbondata.core.scan.expression.exception.FilterUnsupportedException)

Example 94 with ExpressionResult

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

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

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