use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class NotEqualsExpressionUnitTest method testEvaluateForNotEqualsExpressionWithBothStringISSame.
@Test
public void testEvaluateForNotEqualsExpressionWithBothStringISSame() 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);
notEqualsExpression = new NotEqualsExpression(left, right);
RowImpl value = new RowImpl();
String[] row = { "string1" };
String[] row1 = { "string2" };
Object[] objectRow = { row, row1 };
new MockUp<ExpressionResult>() {
Boolean returnMockFlag = true;
@Mock
public String getString() {
if (returnMockFlag) {
returnMockFlag = false;
return "string1";
} else {
return "string2";
}
}
};
value.setValues(objectRow);
ExpressionResult result = notEqualsExpression.evaluate(value);
assertTrue(result.getBoolean());
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class NotInExpressionUnitTest method testEvaluateForNotInExpressionWithDoubleDataType.
@Test
public void testEvaluateForNotInExpressionWithDoubleDataType() throws FilterUnsupportedException, FilterIllegalMemberException {
ColumnExpression left = new ColumnExpression("left_contact", DataType.DOUBLE);
left.setColIndex(0);
ColumnExpression right = new ColumnExpression("right_contact", DataType.DOUBLE);
right.setColIndex(1);
notInExpression = new NotInExpression(left, right);
RowImpl value = new RowImpl();
Double row = 44521D;
Double row1 = 44521.023D;
Object[] objectRow = { row, row1 };
value.setValues(objectRow);
new MockUp<ExpressionResult>() {
@Mock
public Double getDouble() {
return 44521.023D;
}
};
ExpressionResult result = notInExpression.evaluate(value);
assertTrue(result.getBoolean());
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class GreaterThanEqualToExpression method evaluate.
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
ExpressionResult elRes = left.evaluate(value);
ExpressionResult erRes = right.evaluate(value);
ExpressionResult exprResVal1 = elRes;
if (elRes.isNull() || erRes.isNull()) {
elRes.set(DataType.BOOLEAN, false);
return elRes;
}
if (elRes.getDataType() != erRes.getDataType()) {
if (elRes.getDataType().getPrecedenceOrder() < erRes.getDataType().getPrecedenceOrder()) {
exprResVal1 = erRes;
}
}
boolean result = false;
switch(exprResVal1.getDataType()) {
case STRING:
result = elRes.getString().compareTo(erRes.getString()) >= 0;
break;
case SHORT:
result = elRes.getShort() >= (erRes.getShort());
break;
case INT:
result = elRes.getInt() >= (erRes.getInt());
break;
case DOUBLE:
result = elRes.getDouble() >= (erRes.getDouble());
break;
case DATE:
case TIMESTAMP:
result = elRes.getTime() >= (erRes.getTime());
break;
case LONG:
result = elRes.getLong() >= (erRes.getLong());
break;
case DECIMAL:
result = elRes.getDecimal().compareTo(erRes.getDecimal()) >= 0;
break;
default:
throw new FilterUnsupportedException("DataType: " + exprResVal1.getDataType() + " not supported for the filter expression");
}
exprResVal1.set(DataType.BOOLEAN, result);
return exprResVal1;
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class InExpression method evaluate.
@Override
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
ExpressionResult leftRsult = left.evaluate(value);
if (setOfExprResult == null) {
ExpressionResult rightRsult = right.evaluate(value);
ExpressionResult val = null;
setOfExprResult = new HashSet<ExpressionResult>(10);
for (ExpressionResult expressionResVal : rightRsult.getList()) {
if (expressionResVal.getDataType().getPrecedenceOrder() < leftRsult.getDataType().getPrecedenceOrder()) {
val = leftRsult;
} else {
val = expressionResVal;
}
switch(val.getDataType()) {
case STRING:
val = new ExpressionResult(val.getDataType(), expressionResVal.getString());
break;
case SHORT:
val = new ExpressionResult(val.getDataType(), expressionResVal.getShort());
break;
case INT:
val = new ExpressionResult(val.getDataType(), expressionResVal.getInt());
break;
case DOUBLE:
val = new ExpressionResult(val.getDataType(), expressionResVal.getDouble());
break;
case LONG:
val = new ExpressionResult(val.getDataType(), expressionResVal.getLong());
break;
case DATE:
case TIMESTAMP:
val = new ExpressionResult(val.getDataType(), expressionResVal.getTime());
break;
case DECIMAL:
val = new ExpressionResult(val.getDataType(), expressionResVal.getDecimal());
break;
default:
throw new FilterUnsupportedException("DataType: " + val.getDataType() + " not supported for the filter expression");
}
setOfExprResult.add(val);
}
}
// Example: (null==null) -> Left null return false, (1==null) would automatically be false.
if (leftRsult.isNull()) {
leftRsult.set(DataType.BOOLEAN, false);
} else {
leftRsult.set(DataType.BOOLEAN, setOfExprResult.contains(leftRsult));
}
return leftRsult;
}
use of org.apache.carbondata.core.scan.expression.ExpressionResult in project carbondata by apache.
the class LessThanEqualToExpression method evaluate.
public ExpressionResult evaluate(RowIntf value) throws FilterUnsupportedException, FilterIllegalMemberException {
ExpressionResult elRes = left.evaluate(value);
ExpressionResult erRes = right.evaluate(value);
ExpressionResult exprResValue1 = elRes;
if (elRes.isNull() || erRes.isNull()) {
elRes.set(DataType.BOOLEAN, false);
return elRes;
}
if (elRes.getDataType() != erRes.getDataType()) {
if (elRes.getDataType().getPrecedenceOrder() < erRes.getDataType().getPrecedenceOrder()) {
exprResValue1 = erRes;
}
}
boolean result = false;
switch(exprResValue1.getDataType()) {
case STRING:
result = elRes.getString().compareTo(erRes.getString()) <= 0;
break;
case SHORT:
result = elRes.getShort() <= (erRes.getShort());
break;
case INT:
result = elRes.getInt() <= (erRes.getInt());
break;
case DOUBLE:
result = elRes.getDouble() <= (erRes.getDouble());
break;
case DATE:
case TIMESTAMP:
result = elRes.getTime() <= (erRes.getTime());
break;
case LONG:
result = elRes.getLong() <= (erRes.getLong());
break;
case DECIMAL:
result = elRes.getDecimal().compareTo(erRes.getDecimal()) <= 0;
break;
default:
throw new FilterUnsupportedException("DataType: " + exprResValue1.getDataType() + " not supported for the filter expression");
}
exprResValue1.set(DataType.BOOLEAN, result);
return exprResValue1;
}
Aggregations