Search in sources :

Example 6 with ExpressionResult

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

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

Example 8 with ExpressionResult

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

the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithNullISTureWhileCreatingObject.

@Test
public void testEvaluateForNotEqualsExpressionWithNullISTureWhileCreatingObject() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
    right.setColIndex(0);
    notEqualsExpression = new NotEqualsExpression(right, right, true);
    RowImpl value = new RowImpl();
    Short[] row = { 15 };
    Object[] objectRow = { row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public boolean isNull() {
            return true;
        }
    };
    ExpressionResult result = notEqualsExpression.evaluate(value);
    assertEquals(DataType.BOOLEAN, result.getDataType());
}
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 9 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithLongDataType.

@Test
public void testEvaluateForNotInExpressionWithLongDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression left = new ColumnExpression("left_contact", DataType.LONG);
    left.setColIndex(0);
    ColumnExpression right = new ColumnExpression("right_contact", DataType.LONG);
    right.setColIndex(1);
    notInExpression = new NotInExpression(left, right);
    RowImpl value = new RowImpl();
    Long row = 123456256325632L;
    Long row1 = 156212456245556L;
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public Long getLong() {
            return 156212456245556L;
        }
    };
    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 10 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithTimestampDataType.

@Test
public void testEvaluateForNotInExpressionWithTimestampDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    try {
        ColumnExpression left = new ColumnExpression("left_timestamp", DataType.TIMESTAMP);
        left.setColIndex(0);
        ColumnExpression right = new ColumnExpression("right_timestamp", DataType.TIMESTAMP);
        right.setColIndex(1);
        notInExpression = new NotInExpression(right, right);
        RowImpl value = new RowImpl();
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        Date date = dateFormat.parse("2007/03/03");
        long time = date.getTime();
        Timestamp row = new Timestamp(time);
        Timestamp row1 = new Timestamp(time);
        Object[] objectRow = { row, row1 };
        value.setValues(objectRow);
        new MockUp<ExpressionResult>() {

            @Mock
            public Long getTime() {
                return 1172860200000L;
            }
        };
        ExpressionResult result = notInExpression.evaluate(value);
        assertTrue(result.getBoolean());
    } catch (ParseException e) {
        System.out.println("Error while parsing " + e.getMessage());
    }
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) MockUp(mockit.MockUp) Timestamp(java.sql.Timestamp) Date(java.util.Date) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

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