Search in sources :

Example 11 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithShortDataType.

@Test
public void testEvaluateForNotInExpressionWithShortDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression left = new ColumnExpression("left_id", DataType.SHORT);
    left.setColIndex(0);
    ColumnExpression right = new ColumnExpression("right_id", DataType.SHORT);
    right.setColIndex(1);
    notInExpression = new NotInExpression(left, right);
    RowImpl value = new RowImpl();
    Short row = 15653;
    Short row1 = 15582;
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public Short getShort() {
            return 15582;
        }
    };
    ExpressionResult result = notInExpression.evaluate(value);
    assertEquals(result.getDataType(), DataType.BOOLEAN);
}
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 12 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithLeftAndRightDifferentDataType.

@Test
public void testEvaluateForNotInExpressionWithLeftAndRightDifferentDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("name", DataType.STRING);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("number", DataType.INT);
    left.setColIndex(1);
    notInExpression = new NotInExpression(left, right);
    RowImpl value = new RowImpl();
    String row1 = "String1";
    Integer row = 14523213;
    Object[] objectRow = { row1, row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public Integer getInt() {
            return 145232130;
        }
    };
    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 13 with ExpressionResult

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

the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithString.

@Test
public void testEvaluateForNotInExpressionWithString() 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);
    notInExpression = new NotInExpression(left, right);
    RowImpl value = new RowImpl();
    String row = "Row is for left";
    String row1 = "I am row 1";
    Object[] objectRow = { row, row1 };
    new MockUp<ExpressionResult>() {

        @Mock
        public DataType getDataType() {
            return DataType.STRING;
        }

        @Mock
        public String getString() {
            return "string1";
        }
    };
    value.setValues(objectRow);
    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 14 with ExpressionResult

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

the class GreaterThanExpressionUnitTest method testEvaluateForGreaterThanExpressionWithDoubleDataType.

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

        Boolean returnMockFlag = true;

        @Mock
        public Double getDouble() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return 44D;
            } else {
                return 20D;
            }
        }
    };
    ExpressionResult result = greaterThanExpression.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 15 with ExpressionResult

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

the class InExpressionUnitTest method testEvaluateForInExpressionWithTimestampDataType.

@Test
public void testEvaluateForInExpressionWithTimestampDataType() 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);
        inExpression = new InExpression(left, right);
        RowImpl value = new RowImpl();
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        Date date = dateFormat.parse("23/09/2007");
        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 18465213000000L;
            }
        };
        ExpressionResult result = inExpression.evaluate(value);
        assertFalse(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