Search in sources :

Example 66 with ColumnExpression

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

the class LessThanExpressionUnitTest method testEvaluateForLessThanExpressionWithLongDataType.

@Test
public void testEvaluateForLessThanExpressionWithLongDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("contact", DataType.LONG);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("contact", DataType.LONG);
    left.setColIndex(1);
    lessThanExpression = new LessThanExpression(left, right);
    RowImpl value = new RowImpl();
    Long[] row = { 14523656L };
    Long[] row1 = { 12456325L };
    Object[] objectRow = { row1, row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public Long getLong() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return 12456325L;
            } else {
                return 14523656L;
            }
        }
    };
    ExpressionResult result = lessThanExpression.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 67 with ColumnExpression

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

the class LessThanExpressionUnitTest method testEvaluateForLessThanExpressionWithTimestampDataType.

@Test
public void testEvaluateForLessThanExpressionWithTimestampDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    try {
        ColumnExpression left = new ColumnExpression("timestamp", DataType.TIMESTAMP);
        left.setColIndex(0);
        ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP);
        right.setColIndex(1);
        lessThanExpression = new LessThanExpression(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) };
        Date date1 = dateFormat.parse("24/09/2007");
        long time1 = date1.getTime();
        Timestamp[] row1 = { new Timestamp(time1) };
        Object[] objectRow = { row, row1 };
        value.setValues(objectRow);
        new MockUp<ExpressionResult>() {

            Boolean returnMockFlag = true;

            @Mock
            public Long getTime() {
                if (returnMockFlag) {
                    returnMockFlag = false;
                    return 1190505600L;
                } else {
                    return 1190592000L;
                }
            }
        };
        ExpressionResult result = lessThanExpression.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)

Example 68 with ColumnExpression

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

the class LessThanExpressionUnitTest method testEvaluateForLessThanExpressionWithDoubleDataType.

@Test
public void testEvaluateForLessThanExpressionWithDoubleDataType() 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);
    lessThanExpression = new LessThanExpression(left, right);
    RowImpl value = new RowImpl();
    Double[] row = { 2087D };
    Double[] row1 = { 4454D };
    Object[] objectRow = { row1, row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public Double getDouble() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return 2087D;
            } else {
                return 4454D;
            }
        }
    };
    ExpressionResult result = lessThanExpression.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 69 with ColumnExpression

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

the class GreaterThanEqualToExpressionUnitTest method testEvaluateForGreaterThanEqualToExpressionWithDecimalDataType.

@Test
public void testEvaluateForGreaterThanEqualToExpressionWithDecimalDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("contact", DataType.DECIMAL);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("contact", DataType.DECIMAL);
    left.setColIndex(1);
    greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
    RowImpl value = new RowImpl();
    Decimal[] row = new Decimal[] { Decimal.apply(12345.0) };
    Object[] objectRow = { row, row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        @Mock
        public BigDecimal getDecimal() {
            return new BigDecimal(12345.0);
        }
    };
    ExpressionResult result = greaterThanEqualToExpression.evaluate(value);
    assertTrue(result.getBoolean());
}
Also used : RowImpl(org.apache.carbondata.core.scan.filter.intf.RowImpl) Decimal(org.apache.spark.sql.types.Decimal) BigDecimal(java.math.BigDecimal) ExpressionResult(org.apache.carbondata.core.scan.expression.ExpressionResult) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) MockUp(mockit.MockUp) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 70 with ColumnExpression

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

the class GreaterThanEqualToExpressionUnitTest method testForGreaterThanEqualToExpressionWithGetString.

@Test
public void testForGreaterThanEqualToExpressionWithGetString() throws Exception {
    ColumnExpression left = new ColumnExpression("left_name", DataType.STRING);
    left.setColIndex(0);
    ColumnExpression right = new ColumnExpression("right_name", DataType.STRING);
    right.setColIndex(1);
    greaterThanEqualToExpression = new GreaterThanEqualToExpression(left, right);
    String expected_result = "GreaterThanEqualTo(ColumnExpression(left_name),ColumnExpression(right_name))";
    String result = greaterThanEqualToExpression.getString();
    assertEquals(expected_result, result);
}
Also used : ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) Test(org.junit.Test)

Aggregations

ColumnExpression (org.apache.carbondata.core.scan.expression.ColumnExpression)119 Test (org.junit.Test)107 RowImpl (org.apache.carbondata.core.scan.filter.intf.RowImpl)83 MockUp (mockit.MockUp)77 ExpressionResult (org.apache.carbondata.core.scan.expression.ExpressionResult)76 Expression (org.apache.carbondata.core.scan.expression.Expression)20 LiteralExpression (org.apache.carbondata.core.scan.expression.LiteralExpression)18 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 AbstractDictionaryCacheTest (org.apache.carbondata.core.cache.dictionary.AbstractDictionaryCacheTest)8 BigDecimal (java.math.BigDecimal)7 ListExpression (org.apache.carbondata.core.scan.expression.conditional.ListExpression)7 Decimal (org.apache.spark.sql.types.Decimal)7 ColumnSchema (org.apache.carbondata.core.metadata.schema.table.column.ColumnSchema)6 AndExpression (org.apache.carbondata.core.scan.expression.logical.AndExpression)6 OrExpression (org.apache.carbondata.core.scan.expression.logical.OrExpression)6 RangeExpression (org.apache.carbondata.core.scan.expression.logical.RangeExpression)6