This is an automated email from the ASF dual-hosted git repository.

snuyanzin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 46b54bc8bcd [FLINK-38607][table] Do not store plans with same name 
twice in plan test files
46b54bc8bcd is described below

commit 46b54bc8bcd64aa8d5ab245820a5be9be926b1ba
Author: Sergey Nuyanzin <[email protected]>
AuthorDate: Sat Nov 1 12:41:33 2025 +0100

    [FLINK-38607][table] Do not store plans with same name twice in plan test 
files
---
 .../flink/table/planner/utils/DiffRepository.java  | 45 +++++++++++++++++-----
 .../plan/stream/sql/FilterableSourceTest.xml       | 39 -------------------
 2 files changed, 36 insertions(+), 48 deletions(-)

diff --git 
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/DiffRepository.java
 
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/DiffRepository.java
index 5506dc6a75b..4732e25a25c 100644
--- 
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/DiffRepository.java
+++ 
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/DiffRepository.java
@@ -19,6 +19,7 @@ package org.apache.flink.table.planner.utils;
 
 import org.apache.calcite.avatica.util.Spaces;
 import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Sources;
 import org.apache.calcite.util.Util;
 import org.apache.calcite.util.XmlOutput;
 import org.junit.jupiter.api.Assertions;
@@ -45,8 +46,10 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 // THIS FILE IS COPIED FROM APACHE CALCITE
 
@@ -232,14 +235,7 @@ public class DiffRepository {
                 flushDoc();
             }
             this.root = doc.getDocumentElement();
-            if (!root.getNodeName().equals(ROOT_TAG)) {
-                throw new RuntimeException(
-                        "expected root element of type '"
-                                + ROOT_TAG
-                                + "', but found '"
-                                + root.getNodeName()
-                                + "'");
-            }
+            validate(this.root);
         } catch (ParserConfigurationException | SAXException e) {
             throw new RuntimeException("error while creating xml parser", e);
         }
@@ -524,6 +520,32 @@ public class DiffRepository {
         }
     }
 
+    /** Validates the root element. */
+    private static void validate(Element root) {
+        if (!root.getNodeName().equals(ROOT_TAG)) {
+            throw new RuntimeException(
+                    "expected root element of type '"
+                            + ROOT_TAG
+                            + "', but found '"
+                            + root.getNodeName()
+                            + "'");
+        }
+
+        // Make sure that there are no duplicate test cases.
+        final Set<String> testCases = new HashSet<>();
+        final NodeList childNodes = root.getChildNodes();
+        for (int i = 0; i < childNodes.getLength(); i++) {
+            Node child = childNodes.item(i);
+            if (child.getNodeName().equals(TEST_CASE_TAG)) {
+                Element testCase = (Element) child;
+                final String name = testCase.getAttribute(TEST_CASE_NAME_ATTR);
+                if (!testCases.add(name)) {
+                    throw new RuntimeException("TestCase '" + name + "' is 
duplicate");
+                }
+            }
+        }
+    }
+
     /**
      * Returns a given resource from a given test case.
      *
@@ -717,7 +739,12 @@ public class DiffRepository {
         DiffRepository diffRepository = MAP_CLASS_TO_REPOSITORY.get(clazz);
         if (diffRepository == null) {
             final URL refFile = findFile(clazz, ".xml");
-            final File logFile = new 
File(refFile.getFile().replace("test-classes", "surefire"));
+            final File logFile =
+                    new File(
+                            Sources.of(refFile)
+                                    .file()
+                                    .getAbsolutePath()
+                                    .replace("test-classes", "surefire"));
             diffRepository = new DiffRepository(refFile, logFile, 
baseRepository, filter);
             MAP_CLASS_TO_REPOSITORY.put(clazz, diffRepository);
         }
diff --git 
a/flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/FilterableSourceTest.xml
 
b/flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/FilterableSourceTest.xml
index 10c9aa9461d..1316694494e 100644
--- 
a/flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/FilterableSourceTest.xml
+++ 
b/flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/FilterableSourceTest.xml
@@ -50,25 +50,6 @@ LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3])
       <![CDATA[
 Calc(select=[a, b, c, d], where=[d IS NOT NULL])
 +- TableSourceScan(table=[[default_catalog, default_database, MyTable, 
watermark=[c], watermarkEmitStrategy=[on-periodic], filter=[=(LOWER(d), 
_UTF-16LE'h':VARCHAR(2147483647) CHARACTER SET "UTF-16LE")]]], fields=[a, b, c, 
d])
-]]>
-    </Resource>
-  </TestCase>
-  <TestCase name="testPartialFilterMatchWithWatermark">
-    <Resource name="sql">
-      <![CDATA[SELECT * FROM MyTable WHERE LOWER(d) = 'h' AND d IS NOT NULL]]>
-    </Resource>
-    <Resource name="ast">
-      <![CDATA[
-LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3])
-+- LogicalFilter(condition=[AND(=(LOWER($3), _UTF-16LE'h'), IS NOT NULL($3))])
-   +- LogicalWatermarkAssigner(rowtime=[c], watermark=[$2])
-      +- LogicalTableScan(table=[[default_catalog, default_database, MyTable]])
-]]>
-    </Resource>
-    <Resource name="optimized exec plan">
-      <![CDATA[
-Calc(select=[a, b, c, d], where=[d IS NOT NULL])
-+- TableSourceScan(table=[[default_catalog, default_database, MyTable, 
watermark=[$2], filter=[equals(LOWER(d), 'h')]]], fields=[a, b, c, d])
 ]]>
     </Resource>
   </TestCase>
@@ -145,26 +126,6 @@ LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3], f=[$4])
       <![CDATA[
 Calc(select=[a, b, Reinterpret(c) AS c, func(c, a) AS d, f])
 +- TableSourceScan(table=[[default_catalog, default_database, UdfTable, 
watermark=[func(func(func(c, a), a), a)], watermarkEmitStrategy=[on-periodic], 
filter=[=(UPPER(f), _UTF-16LE'welcome':VARCHAR(2147483647) CHARACTER SET 
"UTF-16LE")]]], fields=[a, b, c, f])
-]]>
-    </Resource>
-  </TestCase>
-  <TestCase name="testFilterPushdownWithUdf">
-    <Resource name="sql">
-      <![CDATA[SELECT * FROM UdfTable WHERE UPPER(f) = 'welcome']]>
-    </Resource>
-    <Resource name="ast">
-      <![CDATA[
-LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3], f=[$4])
-+- LogicalFilter(condition=[=(UPPER($4), _UTF-16LE'welcome')])
-   +- LogicalWatermarkAssigner(rowtime=[c], watermark=[func(func($3, $0), $0)])
-      +- LogicalProject(a=[$0], b=[$1], c=[$2], d=[func($2, $0)], f=[$3])
-         +- LogicalTableScan(table=[[default_catalog, default_database, 
UdfTable]])
-]]>
-    </Resource>
-    <Resource name="optimized exec plan">
-      <![CDATA[
-Calc(select=[a, b, Reinterpret(c) AS c, func(c, a) AS d, f])
-+- TableSourceScan(table=[[default_catalog, default_database, UdfTable, 
watermark=[func(func(func(c, a), a), a)], filter=[=(UPPER(f), 
_UTF-16LE'welcome':VARCHAR(2147483647) CHARACTER SET "UTF-16LE")]]], fields=[a, 
b, c, f])
 ]]>
     </Resource>
   </TestCase>

Reply via email to