andygrove commented on code in PR #6173:
URL: https://github.com/apache/datafusion-comet/pull/6173#discussion_r4092277035


##########
AGENTS.md:
##########
@@ -34,6 +34,12 @@ Relevant entry points:
 When opening a pull request, use the [PR 
template](.github/pull_request_template.md) and fill
 in every section.
 
+Use `git push` for normal updates to a PR branch. If a rebase or amend 
requires a force push,
+use `git push --force-with-lease`, never `--force` or `-f`, to reduce the risk 
of overwriting
+another maintainer's commits. If the lease check rejects the push, inspect and 
integrate the
+remote changes before retrying; do not bypass it with `--force`. See
+[Submitting a Pull 
Request](docs/source/contributor-guide/development.md#submitting-a-pull-request).

Review Comment:
   The `--force-with-lease` guidance here and in `development.md` looks 
unrelated to the regex fixtures. Could you move it to its own PR? `AGENTS.md` 
is the shared agent guidance file, so changes there are worth discussing on 
their own, and it keeps this PR focused on #5813.



##########
dev/GenerateRegexFixtures.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/** Generates the Java oracle for Comet's admitted RLIKE subset. Run with JDK 
17. */
+public class GenerateRegexFixtures {
+  private static final List<String> CASES = new ArrayList<>();
+
+  private static String quote(String value) {
+    StringBuilder result = new StringBuilder("\"");
+    for (int i = 0; i < value.length(); i++) {
+      char c = value.charAt(i);
+      if (c == '"' || c == '\\') {
+        result.append('\\').append(c);
+      } else if (c < 0x20 || c > 0x7e) {
+        result.append(String.format("\\u%04x", (int) c));
+      } else {
+        result.append(c);
+      }
+    }
+    return result.append('"').toString();
+  }
+
+  private static void add(String category, String pattern, String... subjects) 
{
+    Pattern compiled = Pattern.compile(pattern);
+    for (String subject : subjects) {
+      boolean expected = compiled.matcher(subject).find();
+      CASES.add(
+          "    {\"category\": "
+              + quote(category)
+              + ", \"pattern\": "
+              + quote(pattern)
+              + ", \"subject\": "
+              + quote(subject)
+              + ", \"expected\": "
+              + expected
+              + "}");
+    }
+  }
+
+  public static void main(String[] args) throws Exception {
+    if (args.length != 1 || Runtime.version().feature() != 17) {
+      throw new IllegalArgumentException(
+          "Run with JDK 17: java dev/GenerateRegexFixtures.java OUTPUT");
+    }
+    String[] subjects = {
+      "", "abc", "abc123", "ABC", "foo", "bar", "foobar", "xxbarxx", "a+b", 
"\\d", "a", "b", "aa",
+      "aaaa", "ab", "abab", "ac", "cd", "abcd", "xxabbxx", "def", "123", 
"(?=", ".", "-", "z",
+      "a b", "@", "[", "]", "A", "_", "~", "a-z",
+      // Escaped so the output does not depend on the JDK 17 default source 
encoding.
+      "\u03b1\u03b2\u03b3", "\u0661\u0662\u0663", "\u4f60\u597d", 
"\ud83d\ude00", "e\u0301",
+      "a\ud83d\ude00b", "\n",
+      "\r", "\r\n", "\t", "\u000b", "\f", "\u0000", "\u007f", "\u00a0", 
"\ufeff", "\u0085",
+      "\u2028", "\u2029", "\nabc", "abc\n", "\nabc\n"
+    };
+    String[][] groups = {
+      {"literal", "abc", "a b"},
+      {
+        "class",
+        "[0-9_]",
+        "[^0-9]",
+        "[a-zA-Z_][a-zA-Z0-9_]*",
+        "[^a]",
+        "[^;]+",
+        "[a-]",
+        "[-a]",
+        "[a\\-z]",
+        "[@-\\[]",

Review Comment:
   The whitelist admits ranges whose start is an escaped character, such as 
`[\.-9]`, `[\--/]` and `[\\-a]`, but the fixtures only cover an escaped end 
(`[@-\[]`). Could you add a few of those? I checked them against `regex` 1.13.1 
and they agree with Java today. Since the point of the table is to catch a 
future crate change, it would be good to have every admitted class shape in it.



##########
docs/source/contributor-guide/regex-fixtures.md:
##########
@@ -0,0 +1,81 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Java regex parity fixtures
+
+The committed `spark/src/test/resources/regex/rlike-java-fixtures.json` records
+Java `Pattern.compile(pattern).matcher(subject).find()` results for patterns
+admitted by `CometRegex`. Rust's `test_rlike_java_fixtures` exercises the 
actual
+`RLike` expression with scalar and UTF-8 array inputs against these answers.
+It neither starts a JVM nor generates expected results during the test. The
+crate's existing JNI build/link requirements still apply; see 
[Development](development.md).
+
+## Regenerating
+
+From the repository root, use JDK 17:
+
+```shell
+java dev/GenerateRegexFixtures.java 
spark/src/test/resources/regex/rlike-java-fixtures.json
+java dev/GenerateRegexFixtures.java /tmp/rlike-java-fixtures.json
+cmp spark/src/test/resources/regex/rlike-java-fixtures.json 
/tmp/rlike-java-fixtures.json

Review Comment:
   The first command overwrites the committed JSON before the `cmp`, so the 
comparison is between two fresh runs rather than against the committed file. 
Could you split this into two steps? First, generate to `/tmp` and `cmp` 
against the committed file to check it is current. Second, regenerate in place 
only when you mean to change the fixtures. That also makes it clearer which 
step to run after a JDK or generator change.



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