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);
}
}
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);
}
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());
}
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());
}
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());
}
}
Aggregations