use of org.apache.carbondata.core.scan.expression.ColumnExpression in project carbondata by apache.
the class ListExpressionUnitTest method test.
@Test
public void test() 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);
List<Expression> children = new ArrayList<>();
children.add(left);
children.add(right);
listExpression = new ListExpression(children);
RowImpl value = new RowImpl();
String row = "Row is for left";
String row1 = "I am row 1";
Object[] objectRow = { row, row1 };
value.setValues(objectRow);
String expected_value = "Row is for left";
ExpressionResult result = listExpression.evaluate(value);
assertThat(expected_value, is(equalTo(result.getList().get(0).getString())));
}
use of org.apache.carbondata.core.scan.expression.ColumnExpression in project carbondata by apache.
the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithTimestampDataType.
@Test
public void testEvaluateForNotEqualsExpressionWithTimestampDataType() 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);
notEqualsExpression = new NotEqualsExpression(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 = { row1, row };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
Boolean returnMockFlag = true;
@Mock
public Long getTime() {
if (returnMockFlag) {
returnMockFlag = false;
return 1190592000L;
} else {
return 1190505600L;
}
}
};
ExpressionResult result = notEqualsExpression.evaluate(value);
assertTrue(result.getBoolean());
} catch (ParseException e) {
System.out.println("Error while parsing " + e.getMessage());
}
}
use of org.apache.carbondata.core.scan.expression.ColumnExpression in project carbondata by apache.
the class NotEqualsExpressionUnitTest method testForNotEqualsExpressionWithDefaultCase.
@Test(expected = FilterUnsupportedException.class)
public void testForNotEqualsExpressionWithDefaultCase() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression right = new ColumnExpression("contact", DataType.BOOLEAN);
right.setColIndex(0);
notEqualsExpression = new NotEqualsExpression(right, right);
RowImpl value = new RowImpl();
Boolean[] row = { true };
Object[] objectRow = { row };
value.setValues(objectRow);
notEqualsExpression.evaluate(value);
}
use of org.apache.carbondata.core.scan.expression.ColumnExpression in project carbondata by apache.
the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithIsNullReturnTrue.
@Test
public void testEvaluateForNotEqualsExpressionWithIsNullReturnTrue() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
right.setColIndex(0);
notEqualsExpression = new NotEqualsExpression(right, right);
RowImpl value = new RowImpl();
Short[] row = { 150 };
Object[] objectRow = { row };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
@Mock
public boolean isNull() {
return true;
}
};
new MockUp<ExpressionResult>() {
@Mock
public Short getShort() {
return 150;
}
};
ExpressionResult result = notEqualsExpression.evaluate(value);
assertFalse(result.getBoolean());
}
use of org.apache.carbondata.core.scan.expression.ColumnExpression in project carbondata by apache.
the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithLeftAndRightDifferentDataType.
@Test
public void testEvaluateForNotEqualsExpressionWithLeftAndRightDifferentDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression left = new ColumnExpression("name", DataType.STRING);
left.setColIndex(0);
ColumnExpression right = new ColumnExpression("number", DataType.INT);
right.setColIndex(1);
notEqualsExpression = new NotEqualsExpression(left, right);
RowImpl value = new RowImpl();
String[] row1 = { "S" };
Integer[] row = { 14 };
Object[] objectRow = { row, row1 };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
Boolean returnMockFlag = true;
@Mock
public Integer getInt() {
if (returnMockFlag) {
returnMockFlag = false;
return 84;
} else {
return 14;
}
}
};
ExpressionResult result = notEqualsExpression.evaluate(value);
assertTrue(result.getBoolean());
}
Aggregations