RussellSpitzer commented on code in PR #11324: URL: https://github.com/apache/iceberg/pull/11324#discussion_r1811183149
########## api/src/test/java/org/apache/iceberg/TestHelpers.java: ########## @@ -402,6 +406,98 @@ public int hashCode() { } } + /** A VariantLike implementation for testing accepting JSON input */ + public static class JsonVariant implements VariantLike { + public static JsonVariant of(String json) { + return new JsonVariant(json); + } + + private final JsonNode node; + + private JsonVariant(String json) { + try { + ObjectMapper mapper = new ObjectMapper(); + this.node = mapper.readTree(json); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private JsonVariant(JsonNode node) { + this.node = node; + } + + @Override + public int size() { + return node.size(); + } + + @Override + public <T> T get(Class<T> javaClass) { + if (javaClass.equals(Boolean.class)) { + return (T) (Boolean) node.asBoolean(); + } else if (javaClass.equals(Integer.class)) { + return (T) (Integer) node.asInt(); + } else if (javaClass.equals(Long.class)) { + return (T) (Long) node.asLong(); + } else if (javaClass.equals(Float.class)) { + return (T) Float.valueOf((float) node.asDouble()); + } else if (javaClass.equals(Double.class)) { + return (T) (Double) (node.asDouble()); + } else if (CharSequence.class.isAssignableFrom(javaClass)) { + return (T) node.asText(); + } else if (javaClass.equals(ByteBuffer.class)) { + try { + return (T) ByteBuffer.wrap(node.binaryValue()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else if (javaClass.equals(BigDecimal.class)) { + return (T) node.decimalValue(); + } + + throw new IllegalArgumentException("Unsupported type: " + javaClass); + } + + @Override + public VariantLike get(String[] path) { + JsonNode childNode = node; + for (String pathElement : path) { + childNode = childNode.get(pathElement); + if (childNode == null) { + return null; + } + } + + return new JsonVariant(childNode); Review Comment: I don't think this matches the java doc above, If I provide an empty path I get "this" if I pass null I should get a NPE in the foreach. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org