@Test public void matchesDifferentTypes() { _thrown.expect(ClassCastException.class); _thrown.expectMessage("cannot be cast"); new Filter("col != true").matches(Row.builder().put("col", 42).build()); }
public boolean matches(Row row) { Object leftValue = extractValue(_leftOperand, row); Object rightValue = extractValue(_rightOperand, row); if (leftValue == null && rightValue == null) { return (_operator == Operator.IS); } else if (leftValue == null || rightValue == null) { return (_operator == Operator.ISNOT); } switch (_operator) { case EQ: case IS: return compareValues(leftValue, rightValue) == 0; case GE: return compareValues(leftValue, rightValue) >= 0; case GT: return compareValues(leftValue, rightValue) > 0; case LE: return compareValues(leftValue, rightValue) <= 0; case LT: return compareValues(leftValue, rightValue) < 0; case NE: case ISNOT: return compareValues(leftValue, rightValue) != 0; default: throw new BatfishException("Unhandled operator: " + _operator); } }
Filter { public boolean matches(Row row) { Object leftValue = extractValue(_leftOperand, row); Object rightValue = extractValue(_rightOperand, row); if (leftValue == null && rightValue == null) { return (_operator == Operator.IS); } else if (leftValue == null || rightValue == null) { return (_operator == Operator.ISNOT); } switch (_operator) { case EQ: case IS: return compareValues(leftValue, rightValue) == 0; case GE: return compareValues(leftValue, rightValue) >= 0; case GT: return compareValues(leftValue, rightValue) > 0; case LE: return compareValues(leftValue, rightValue) <= 0; case LT: return compareValues(leftValue, rightValue) < 0; case NE: case ISNOT: return compareValues(leftValue, rightValue) != 0; default: throw new BatfishException("Unhandled operator: " + _operator); } } }
Filter { public boolean matches(Row row) { Object leftValue = extractValue(_leftOperand, row); Object rightValue = extractValue(_rightOperand, row); if (leftValue == null && rightValue == null) { return (_operator == Operator.IS); } else if (leftValue == null || rightValue == null) { return (_operator == Operator.ISNOT); } switch (_operator) { case EQ: case IS: return compareValues(leftValue, rightValue) == 0; case GE: return compareValues(leftValue, rightValue) >= 0; case GT: return compareValues(leftValue, rightValue) > 0; case LE: return compareValues(leftValue, rightValue) <= 0; case LT: return compareValues(leftValue, rightValue) < 0; case NE: case ISNOT: return compareValues(leftValue, rightValue) != 0; default: throw new BatfishException("Unhandled operator: " + _operator); } } @JsonCreator  Filter(String filterStr); }
Filter { public boolean matches(Row row) { Object leftValue = extractValue(_leftOperand, row); Object rightValue = extractValue(_rightOperand, row); if (leftValue == null && rightValue == null) { return (_operator == Operator.IS); } else if (leftValue == null || rightValue == null) { return (_operator == Operator.ISNOT); } switch (_operator) { case EQ: case IS: return compareValues(leftValue, rightValue) == 0; case GE: return compareValues(leftValue, rightValue) >= 0; case GT: return compareValues(leftValue, rightValue) > 0; case LE: return compareValues(leftValue, rightValue) <= 0; case LT: return compareValues(leftValue, rightValue) < 0; case NE: case ISNOT: return compareValues(leftValue, rightValue) != 0; default: throw new BatfishException("Unhandled operator: " + _operator); } } @JsonCreator  Filter(String filterStr); Operand getLeftOperand(); @JsonValue String getExpression(); Operator getOperator(); Operand getRightOperand(); boolean matches(Row row); }
Filter { public boolean matches(Row row) { Object leftValue = extractValue(_leftOperand, row); Object rightValue = extractValue(_rightOperand, row); if (leftValue == null && rightValue == null) { return (_operator == Operator.IS); } else if (leftValue == null || rightValue == null) { return (_operator == Operator.ISNOT); } switch (_operator) { case EQ: case IS: return compareValues(leftValue, rightValue) == 0; case GE: return compareValues(leftValue, rightValue) >= 0; case GT: return compareValues(leftValue, rightValue) > 0; case LE: return compareValues(leftValue, rightValue) <= 0; case LT: return compareValues(leftValue, rightValue) < 0; case NE: case ISNOT: return compareValues(leftValue, rightValue) != 0; default: throw new BatfishException("Unhandled operator: " + _operator); } } @JsonCreator  Filter(String filterStr); Operand getLeftOperand(); @JsonValue String getExpression(); Operator getOperator(); Operand getRightOperand(); boolean matches(Row row);  }