@Test public void extractValueColumnCase() { assertThat( Filter.extractValue( new Operand(Type.COLUMN, Arrays.asList("col")), Row.builder().put("col", 42).build()), equalTo(42)); JsonNode object = BatfishObjectMapper.mapper().createObjectNode().set("c2", null); assertThat( Filter.extractValue( new Operand(Type.COLUMN, Arrays.asList("c1", "c2")), Row.builder().put("c1", object).build()), equalTo(null)); ((ObjectNode) object) .set( "c2", BatfishObjectMapper.mapper() .createObjectNode() .set("c3", BatfishObjectMapper.mapper().valueToTree(42))); assertThat( Filter.extractValue( new Operand(Type.COLUMN, Arrays.asList("c1", "c2", "c3")), Row.builder().put("c1", object).build()), equalTo(42)); _thrown.expect(NoSuchElementException.class); _thrown.expectMessage("Could not extract"); Filter.extractValue( new Operand(Type.COLUMN, Arrays.asList("c1", "c2", "c4")), Row.builder().put("c1", object).build()); }
@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);  }