}
@SuppressWarnings("unchecked")
private void binaryExpressionConstPrune(LogicalExpression parent)
throws FrontendException {
ConstantExpression rhs = result.pop(), lhs = result.pop();
if (rhs == null || lhs == null) {
result.push(null);
}
else {
ConstantExpression newExp = null;
if (parent instanceof AndExpression) newExp = new ConstantExpression(
plan,
(Boolean) rhs.getValue() && (Boolean) lhs.getValue());
else if (parent instanceof OrExpression) newExp = new ConstantExpression(
plan,
(Boolean) rhs.getValue() || (Boolean) lhs.getValue());
else if (parent instanceof EqualExpression) newExp = new ConstantExpression(
plan, rhs.isEqual(lhs));
else if (parent instanceof GreaterThanExpression) newExp = new ConstantExpression(
plan,
((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) > 0);
else if (parent instanceof GreaterThanEqualExpression) newExp = new ConstantExpression(
plan,
((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) >= 0);
else if (parent instanceof LessThanExpression) newExp = new ConstantExpression(
plan,
((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) < 0);
else if (parent instanceof LessThanExpression) newExp = new ConstantExpression(
plan,
((Comparable) rhs.getValue()).compareTo((Comparable) lhs.getValue()) <= 0);
else if (parent instanceof AddExpression) {
byte type = parent.getFieldSchema().type;
switch (type) {
case DataType.INTEGER:
newExp = new ConstantExpression(
plan,
(Integer) lhs.getValue() + (Integer) rhs.getValue());
break;
case DataType.LONG:
newExp = new ConstantExpression(
plan,
(Long) lhs.getValue() + (Long) rhs.getValue());
break;
case DataType.FLOAT:
newExp = new ConstantExpression(
plan,
(Float) lhs.getValue() + (Float) rhs.getValue());
break;
case DataType.DOUBLE:
newExp = new ConstantExpression(
plan,
(Double) lhs.getValue() + (Double) rhs.getValue());
break;
case DataType.BIGINTEGER:
newExp = new ConstantExpression(
plan,
((BigInteger) lhs.getValue()).add((BigInteger) rhs.getValue()));
break;
case DataType.BIGDECIMAL:
newExp = new ConstantExpression(
plan,
((BigDecimal) lhs.getValue()).add((BigDecimal) rhs.getValue()));
break;
default:
throw new FrontendException("Invalid type");
}
}
else if (parent instanceof SubtractExpression) {
byte type = parent.getFieldSchema().type;
switch (type) {
case DataType.INTEGER:
newExp = new ConstantExpression(
plan,
(Integer) lhs.getValue() - (Integer) rhs.getValue());
break;
case DataType.LONG:
newExp = new ConstantExpression(
plan,
(Long) lhs.getValue() - (Long) rhs.getValue());
break;
case DataType.FLOAT:
newExp = new ConstantExpression(
plan,
(Float) lhs.getValue() - (Float) rhs.getValue());
break;
case DataType.DOUBLE:
newExp = new ConstantExpression(
plan,
(Double) lhs.getValue() - (Double) rhs.getValue());
break;
case DataType.BIGINTEGER:
newExp = new ConstantExpression(
plan,
((BigInteger) lhs.getValue()).subtract((BigInteger) rhs.getValue()));
break;
case DataType.BIGDECIMAL:
newExp = new ConstantExpression(
plan,
((BigDecimal) lhs.getValue()).subtract((BigDecimal) rhs.getValue()));
break;
default:
throw new FrontendException("Invalid type");
}
}
else if (parent instanceof MultiplyExpression) {
byte type = parent.getFieldSchema().type;
switch (type) {
case DataType.INTEGER:
newExp = new ConstantExpression(
plan,
(Integer) lhs.getValue() * (Integer) rhs.getValue());
break;
case DataType.LONG:
newExp = new ConstantExpression(
plan,
(Long) lhs.getValue() * (Long) rhs.getValue());
break;
case DataType.FLOAT:
newExp = new ConstantExpression(
plan,
(Float) lhs.getValue() * (Float) rhs.getValue());
break;
case DataType.DOUBLE:
newExp = new ConstantExpression(
plan,
(Double) lhs.getValue() * (Double) rhs.getValue());
break;
case DataType.BIGINTEGER:
newExp = new ConstantExpression(
plan,
((BigInteger) lhs.getValue()).multiply((BigInteger) rhs.getValue()));
break;
case DataType.BIGDECIMAL:
newExp = new ConstantExpression(
plan,
((BigDecimal) lhs.getValue()).multiply((BigDecimal) rhs.getValue()));
break;
default:
throw new FrontendException("Invalid type");
}
}
else if (parent instanceof ModExpression) {
byte type = parent.getFieldSchema().type;
switch (type) {
case DataType.INTEGER:
newExp = new ConstantExpression(
plan,
(Integer) lhs.getValue() % (Integer) rhs.getValue());
break;
case DataType.LONG:
newExp = new ConstantExpression(
plan,
(Long) lhs.getValue() % (Long) rhs.getValue());
break;
case DataType.BIGINTEGER:
newExp = new ConstantExpression(
plan,
((BigInteger) lhs.getValue()).mod((BigInteger) rhs.getValue()));
break;
default:
throw new FrontendException("Invalid type");
}
}
else if (parent instanceof DivideExpression) {
byte type = parent.getFieldSchema().type;
switch (type) {
case DataType.INTEGER:
if ((Integer) rhs.getValue() != 0)
newExp = new ConstantExpression(
plan,
(Integer) lhs.getValue() / (Integer) rhs.getValue());
break;
case DataType.LONG:
if ((Long) rhs.getValue() != 0)
newExp = new ConstantExpression(
plan,
(Long) lhs.getValue() / (Long) rhs.getValue());
break;
case DataType.FLOAT:
if ((Float) rhs.getValue() != 0)
newExp = new ConstantExpression(
plan,
(Float) lhs.getValue() / (Float) rhs.getValue());
break;
case DataType.DOUBLE:
if ((Double) rhs.getValue() != 0)
newExp = new ConstantExpression(
plan,
(Double) lhs.getValue() / (Double) rhs.getValue());
break;
case DataType.BIGINTEGER:
newExp = new ConstantExpression(
plan,
((BigInteger) lhs.getValue()).divide((BigInteger) rhs.getValue()));
break;
case DataType.BIGDECIMAL:
newExp = new ConstantExpression(
plan,
((BigDecimal) lhs.getValue()).divide((BigDecimal) rhs.getValue()));
break;
default:
throw new FrontendException("Invalid type");