nssalian commented on code in PR #15384:
URL: https://github.com/apache/iceberg/pull/15384#discussion_r3012071911
##########
api/src/main/java/org/apache/iceberg/expressions/PathUtil.java:
##########
@@ -83,6 +84,26 @@ public static String toNormalizedPath(Iterable<String>
fields) {
.collect(Collectors.joining(""));
}
+ /**
+ * Converts a normalized path (e.g. $['a']['b']) to dot notation (e.g.
$.a.b). Used when unbinding
+ * BoundExtract so the result can be passed to Expressions.extract().
+ */
+ static String toDotNotation(String normalizedPath) {
+ Preconditions.checkArgument(
+ normalizedPath != null && normalizedPath.startsWith(ROOT),
+ "Invalid normalized path: %s",
+ normalizedPath);
+ List<String> fields = Lists.newArrayList();
+ Matcher matcher =
Pattern.compile("\\['([^']*)'\\]").matcher(normalizedPath);
+ while (matcher.find()) {
+ fields.add(matcher.group(1));
+ }
+ if (fields.isEmpty()) {
+ return ROOT;
+ }
+ return ROOT + "." + String.join(".", fields);
Review Comment:
Can a field name ever contain a dot? If so, toDotNotation("$['user.name']")
breaks the round-trip. PathUtil.parse() would split it into two fields. If
that's possible, might be simpler to have unbind() pass the normalized path
directly instead of converting back to dot notation.
##########
api/src/main/java/org/apache/iceberg/expressions/PathUtil.java:
##########
@@ -83,6 +84,26 @@ public static String toNormalizedPath(Iterable<String>
fields) {
.collect(Collectors.joining(""));
}
+ /**
+ * Converts a normalized path (e.g. $['a']['b']) to dot notation (e.g.
$.a.b). Used when unbinding
+ * BoundExtract so the result can be passed to Expressions.extract().
+ */
+ static String toDotNotation(String normalizedPath) {
+ Preconditions.checkArgument(
+ normalizedPath != null && normalizedPath.startsWith(ROOT),
+ "Invalid normalized path: %s",
+ normalizedPath);
+ List<String> fields = Lists.newArrayList();
+ Matcher matcher =
Pattern.compile("\\['([^']*)'\\]").matcher(normalizedPath);
Review Comment:
Could you add this Pattern to a static field at the top like other Patterns?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]