Search in sources :

Example 61 with ColumnExpression

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

the class CarbonInputMapperTest method testInputFormatMapperReadAllRowsAndFewColumnsWithFilter.

@Test
public void testInputFormatMapperReadAllRowsAndFewColumnsWithFilter() throws Exception {
    try {
        String outPath = "target/output3";
        CarbonProjection carbonProjection = new CarbonProjection();
        carbonProjection.addColumn("ID");
        carbonProjection.addColumn("country");
        carbonProjection.addColumn("salary");
        Expression expression = new EqualToExpression(new ColumnExpression("country", DataType.STRING), new LiteralExpression("france", DataType.STRING));
        runJob(outPath, carbonProjection, expression);
        Assert.assertEquals("Count lines are not matching", 101, countTheLines(outPath));
        Assert.assertEquals("Column count are not matching", 3, countTheColumns(outPath));
    } catch (Exception e) {
        Assert.assertTrue("failed", false);
    }
}
Also used : CarbonProjection(org.apache.carbondata.hadoop.CarbonProjection) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) Expression(org.apache.carbondata.core.scan.expression.Expression) EqualToExpression(org.apache.carbondata.core.scan.expression.conditional.EqualToExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) ColumnExpression(org.apache.carbondata.core.scan.expression.ColumnExpression) LiteralExpression(org.apache.carbondata.core.scan.expression.LiteralExpression) IOException(java.io.IOException) Test(org.junit.Test)

Example 62 with ColumnExpression

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

the class LessThanEqualToExpressionUnitTest method testForLessThanEqualToExpressionWithGetString.

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

Example 63 with ColumnExpression

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

the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithShortDataType.

@Test
public void testEvaluateForLessThanEqualToExpressionWithShortDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("id", DataType.SHORT);
    left.setColIndex(1);
    lessThanEqualToExpression = new LessThanEqualToExpression(left, right);
    RowImpl value = new RowImpl();
    Short[] row = { 1550 };
    Short[] row1 = { 3365 };
    Object[] objectRow = { row, row1 };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public Short getShort() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return 1550;
            } else {
                return 3365;
            }
        }
    };
    ExpressionResult result = lessThanEqualToExpression.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 64 with ColumnExpression

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

the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithDecimalDataType.

@Test
public void testEvaluateForLessThanEqualToExpressionWithDecimalDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    ColumnExpression right = new ColumnExpression("right_contact", DataType.DECIMAL);
    right.setColIndex(0);
    ColumnExpression left = new ColumnExpression("left_contact", DataType.DECIMAL);
    left.setColIndex(1);
    lessThanEqualToExpression = new LessThanEqualToExpression(left, right);
    RowImpl value = new RowImpl();
    Decimal[] row = new Decimal[] { Decimal.apply(46851.2) };
    Decimal[] row1 = new Decimal[] { Decimal.apply(45821.02) };
    Object[] objectRow = { row1, row };
    value.setValues(objectRow);
    new MockUp<ExpressionResult>() {

        Boolean returnMockFlag = true;

        @Mock
        public BigDecimal getDecimal() {
            if (returnMockFlag) {
                returnMockFlag = false;
                return new BigDecimal(45821.02);
            } else {
                return new BigDecimal(46851.2);
            }
        }
    };
    ExpressionResult result = lessThanEqualToExpression.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 65 with ColumnExpression

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

the class LessThanEqualToExpressionUnitTest method testEvaluateForLessThanEqualToExpressionWithTimestampDataType.

@Test
public void testEvaluateForLessThanEqualToExpressionWithTimestampDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
    try {
        ColumnExpression left = new ColumnExpression("timestamp", DataType.TIMESTAMP);
        left.setColIndex(0);
        ColumnExpression right = new ColumnExpression("timestamp", DataType.TIMESTAMP);
        right.setColIndex(1);
        lessThanEqualToExpression = new LessThanEqualToExpression(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 = lessThanEqualToExpression.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

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