@Test public void extractValueBaseCase() { assertThat( Filter.extractValue(new Operand(Type.NULL, null), Row.builder().build()), equalTo(null)); assertThat( Filter.extractValue(new Operand(Type.INTEGER, 42), Row.builder().build()), equalTo(42)); }
@VisibleForTesting static Object extractValue(Operand operand, Row row) { if (operand.getType() == Operand.Type.COLUMN) { @SuppressWarnings("unchecked") List<String> columns = (List<String>) operand.getValue(); JsonNode object = BatfishObjectMapper.mapper().valueToTree(row.get(columns.get(0))); try { return extractValue(object, columns, 1); } catch (BatfishException | JsonProcessingException e) { throw new NoSuchElementException( String.format( "Could not extract value from '\"%s\":%s' using column specification '%s': %s", columns.get(0), object, columns, e.getMessage())); } } return operand.getValue(); }
Filter { @VisibleForTesting static Object extractValue(Operand operand, Row row) { if (operand.getType() == Operand.Type.COLUMN) { @SuppressWarnings("unchecked") List<String> columns = (List<String>) operand.getValue(); JsonNode object = BatfishObjectMapper.mapper().valueToTree(row.get(columns.get(0))); try { return extractValue(object, columns, 1); } catch (BatfishException | JsonProcessingException e) { throw new NoSuchElementException( String.format( "Could not extract value from '\"%s\":%s' using column specification '%s': %s", columns.get(0), object, columns, e.getMessage())); } } return operand.getValue(); } }
Filter { @VisibleForTesting static Object extractValue(Operand operand, Row row) { if (operand.getType() == Operand.Type.COLUMN) { @SuppressWarnings("unchecked") List<String> columns = (List<String>) operand.getValue(); JsonNode object = BatfishObjectMapper.mapper().valueToTree(row.get(columns.get(0))); try { return extractValue(object, columns, 1); } catch (BatfishException | JsonProcessingException e) { throw new NoSuchElementException( String.format( "Could not extract value from '\"%s\":%s' using column specification '%s': %s", columns.get(0), object, columns, e.getMessage())); } } return operand.getValue(); } @JsonCreator  Filter(String filterStr); }
Filter { @VisibleForTesting static Object extractValue(Operand operand, Row row) { if (operand.getType() == Operand.Type.COLUMN) { @SuppressWarnings("unchecked") List<String> columns = (List<String>) operand.getValue(); JsonNode object = BatfishObjectMapper.mapper().valueToTree(row.get(columns.get(0))); try { return extractValue(object, columns, 1); } catch (BatfishException | JsonProcessingException e) { throw new NoSuchElementException( String.format( "Could not extract value from '\"%s\":%s' using column specification '%s': %s", columns.get(0), object, columns, e.getMessage())); } } return operand.getValue(); } @JsonCreator  Filter(String filterStr); Operand getLeftOperand(); @JsonValue String getExpression(); Operator getOperator(); Operand getRightOperand(); boolean matches(Row row); }
Filter { @VisibleForTesting static Object extractValue(Operand operand, Row row) { if (operand.getType() == Operand.Type.COLUMN) { @SuppressWarnings("unchecked") List<String> columns = (List<String>) operand.getValue(); JsonNode object = BatfishObjectMapper.mapper().valueToTree(row.get(columns.get(0))); try { return extractValue(object, columns, 1); } catch (BatfishException | JsonProcessingException e) { throw new NoSuchElementException( String.format( "Could not extract value from '\"%s\":%s' using column specification '%s': %s", columns.get(0), object, columns, e.getMessage())); } } return operand.getValue(); } @JsonCreator  Filter(String filterStr); Operand getLeftOperand(); @JsonValue String getExpression(); Operator getOperator(); Operand getRightOperand(); boolean matches(Row row);  }