moomindani commented on code in PR #15558:
URL: https://github.com/apache/iceberg/pull/15558#discussion_r2934490053


##########
core/src/test/java/org/apache/iceberg/util/TestPropertyUtil.java:
##########
@@ -25,6 +25,37 @@
 
 public class TestPropertyUtil {
 
+  @Test
+  void propertiesWithPrefixStripsLiterally() {
+    // The prefix contains dots which are regex wildcards. Using 
replaceFirst(prefix, "")
+    // would treat dots as regex "any char", which is incorrect. 
substring(prefix.length())
+    // strips the prefix literally.
+    Map<String, String> properties =
+        Map.of(
+            "write.parquet.column.int_field", "false",
+            "write.parquet.column.string_field", "true",
+            "unrelated.key", "value");
+
+    Map<String, String> result =
+        PropertyUtil.propertiesWithPrefix(properties, "write.parquet.column.");
+
+    assertThat(result)
+        .containsExactlyInAnyOrderEntriesOf(
+            Map.of("int_field", "false", "string_field", "true"));
+  }
+
+  @Test
+  void propertiesWithPrefixHandlesRegexSpecialChars() {
+    // Prefix with regex-special characters that would cause 
PatternSyntaxException
+    // with replaceFirst but work correctly with substring
+    Map<String, String> properties = Map.of("prefix[0].key", "value");
+
+    Map<String, String> result =
+        PropertyUtil.propertiesWithPrefix(properties, "prefix[0].");

Review Comment:
   Good catch — you're right that `prefix[0].` doesn't throw 
`PatternSyntaxException`. Fixed the comment to clarify the actual behavior: 
`replaceFirst` silently fails to strip the prefix since regex `[0]` matches 
char `0`, not literal `[`. Also added a new test 
`propertiesWithPrefixHandlesUnclosedRegexChars` with `prefix[0.` which does 
throw `PatternSyntaxException`. Verified both tests fail with the old 
`replaceFirst` code and pass with the `substring` fix.



-- 
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]

Reply via email to