use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class OrExpression method evaluate.
@Override
public ExpressionResult evaluate(RowIntf value) throws FilterIllegalMemberException, FilterUnsupportedException {
ExpressionResult resultLeft = left.evaluate(value);
ExpressionResult resultRight = right.evaluate(value);
switch(resultLeft.getDataType()) {
case BOOLEAN:
resultLeft.set(DataType.BOOLEAN, (resultLeft.getBoolean() || resultRight.getBoolean()));
break;
default:
throw new FilterUnsupportedException("Incompatible datatype for applying OR Expression Filter");
}
return resultLeft;
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class GreaterThanExpression method evaluate.
@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
ExpressionResult exprLeftRes = left.evaluate(value);
ExpressionResult exprRightRes = right.evaluate(value);
ExpressionResult val1 = exprLeftRes;
if (exprLeftRes.isNull() || exprRightRes.isNull()) {
exprLeftRes.set(DataType.BOOLEAN, false);
return exprLeftRes;
}
if (exprLeftRes.getDataType() != exprRightRes.getDataType()) {
if (exprLeftRes.getDataType().getPrecedenceOrder() < exprRightRes.getDataType().getPrecedenceOrder()) {
val1 = exprRightRes;
}
}
boolean result = false;
switch(val1.getDataType()) {
case STRING:
result = exprLeftRes.getString().compareTo(exprRightRes.getString()) > 0;
break;
case DOUBLE:
result = exprLeftRes.getDouble() > (exprRightRes.getDouble());
break;
case SHORT:
result = exprLeftRes.getShort() > (exprRightRes.getShort());
break;
case INT:
result = exprLeftRes.getInt() > (exprRightRes.getInt());
break;
case DATE:
case TIMESTAMP:
result = exprLeftRes.getTime() > (exprRightRes.getTime());
break;
case LONG:
result = exprLeftRes.getLong() > (exprRightRes.getLong());
break;
case DECIMAL:
result = exprLeftRes.getDecimal().compareTo(exprRightRes.getDecimal()) > 0;
break;
default:
throw new FilterUnsupportedException("DataType: " + val1.getDataType() + " not supported for the filter expression");
}
val1.set(DataType.BOOLEAN, result);
return val1;
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithNullISTureWhileCreatingObject.
@Test
public void testEvaluateForNotEqualsExpressionWithNullISTureWhileCreatingObject() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression right = new ColumnExpression("id", DataType.SHORT);
right.setColIndex(0);
notEqualsExpression = new NotEqualsExpression(right, right, true);
RowImpl value = new RowImpl();
Short[] row = { 15 };
Object[] objectRow = { row };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
@Mock
public boolean isNull() {
return true;
}
};
ExpressionResult result = notEqualsExpression.evaluate(value);
assertEquals(DataType.BOOLEAN, result.getDataType());
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithLongDataType.
@Test
public void testEvaluateForNotInExpressionWithLongDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression left = new ColumnExpression("left_contact", DataType.LONG);
left.setColIndex(0);
ColumnExpression right = new ColumnExpression("right_contact", DataType.LONG);
right.setColIndex(1);
notInExpression = new NotInExpression(left, right);
RowImpl value = new RowImpl();
Long row = 123456256325632L;
Long row1 = 156212456245556L;
Object[] objectRow = { row, row1 };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
@Mock
public Long getLong() {
return 156212456245556L;
}
};
ExpressionResult result = notInExpression.evaluate(value);
assertTrue(result.getBoolean());
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithTimestampDataType.
@Test
public void testEvaluateForNotInExpressionWithTimestampDataType() 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);
notInExpression = new NotInExpression(right, right);
RowImpl value = new RowImpl();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
Date date = dateFormat.parse("2007/03/03");
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 1172860200000L;
}
};
ExpressionResult result = notInExpression.evaluate(value);
assertTrue(result.getBoolean());
} catch (ParseException e) {
System.out.println("Error while parsing " + e.getMessage());
}
}
Aggregations