Skip to content

Commit 46b54bc

Browse files
authored
[FLINK-38607][table] Do not store plans with same name twice in plan test files
1 parent 9fcb46e commit 46b54bc

File tree

2 files changed

+36
-48
lines changed

2 files changed

+36
-48
lines changed

flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/DiffRepository.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.calcite.avatica.util.Spaces;
2121
import org.apache.calcite.util.Pair;
22+
import org.apache.calcite.util.Sources;
2223
import org.apache.calcite.util.Util;
2324
import org.apache.calcite.util.XmlOutput;
2425
import org.junit.jupiter.api.Assertions;
@@ -45,8 +46,10 @@
4546
import java.net.URL;
4647
import java.util.ArrayList;
4748
import java.util.HashMap;
49+
import java.util.HashSet;
4850
import java.util.List;
4951
import java.util.Map;
52+
import java.util.Set;
5053

5154
// THIS FILE IS COPIED FROM APACHE CALCITE
5255

@@ -232,14 +235,7 @@ private DiffRepository(
232235
flushDoc();
233236
}
234237
this.root = doc.getDocumentElement();
235-
if (!root.getNodeName().equals(ROOT_TAG)) {
236-
throw new RuntimeException(
237-
"expected root element of type '"
238-
+ ROOT_TAG
239-
+ "', but found '"
240-
+ root.getNodeName()
241-
+ "'");
242-
}
238+
validate(this.root);
243239
} catch (ParserConfigurationException | SAXException e) {
244240
throw new RuntimeException("error while creating xml parser", e);
245241
}
@@ -524,6 +520,32 @@ private void flushDoc() {
524520
}
525521
}
526522

523+
/** Validates the root element. */
524+
private static void validate(Element root) {
525+
if (!root.getNodeName().equals(ROOT_TAG)) {
526+
throw new RuntimeException(
527+
"expected root element of type '"
528+
+ ROOT_TAG
529+
+ "', but found '"
530+
+ root.getNodeName()
531+
+ "'");
532+
}
533+
534+
// Make sure that there are no duplicate test cases.
535+
final Set<String> testCases = new HashSet<>();
536+
final NodeList childNodes = root.getChildNodes();
537+
for (int i = 0; i < childNodes.getLength(); i++) {
538+
Node child = childNodes.item(i);
539+
if (child.getNodeName().equals(TEST_CASE_TAG)) {
540+
Element testCase = (Element) child;
541+
final String name = testCase.getAttribute(TEST_CASE_NAME_ATTR);
542+
if (!testCases.add(name)) {
543+
throw new RuntimeException("TestCase '" + name + "' is duplicate");
544+
}
545+
}
546+
}
547+
}
548+
527549
/**
528550
* Returns a given resource from a given test case.
529551
*
@@ -717,7 +739,12 @@ public static synchronized DiffRepository lookup(
717739
DiffRepository diffRepository = MAP_CLASS_TO_REPOSITORY.get(clazz);
718740
if (diffRepository == null) {
719741
final URL refFile = findFile(clazz, ".xml");
720-
final File logFile = new File(refFile.getFile().replace("test-classes", "surefire"));
742+
final File logFile =
743+
new File(
744+
Sources.of(refFile)
745+
.file()
746+
.getAbsolutePath()
747+
.replace("test-classes", "surefire"));
721748
diffRepository = new DiffRepository(refFile, logFile, baseRepository, filter);
722749
MAP_CLASS_TO_REPOSITORY.put(clazz, diffRepository);
723750
}

flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/FilterableSourceTest.xml

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,6 @@ LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3])
5050
<![CDATA[
5151
Calc(select=[a, b, c, d], where=[d IS NOT NULL])
5252
+- 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])
53-
]]>
54-
</Resource>
55-
</TestCase>
56-
<TestCase name="testPartialFilterMatchWithWatermark">
57-
<Resource name="sql">
58-
<![CDATA[SELECT * FROM MyTable WHERE LOWER(d) = 'h' AND d IS NOT NULL]]>
59-
</Resource>
60-
<Resource name="ast">
61-
<![CDATA[
62-
LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3])
63-
+- LogicalFilter(condition=[AND(=(LOWER($3), _UTF-16LE'h'), IS NOT NULL($3))])
64-
+- LogicalWatermarkAssigner(rowtime=[c], watermark=[$2])
65-
+- LogicalTableScan(table=[[default_catalog, default_database, MyTable]])
66-
]]>
67-
</Resource>
68-
<Resource name="optimized exec plan">
69-
<![CDATA[
70-
Calc(select=[a, b, c, d], where=[d IS NOT NULL])
71-
+- TableSourceScan(table=[[default_catalog, default_database, MyTable, watermark=[$2], filter=[equals(LOWER(d), 'h')]]], fields=[a, b, c, d])
7253
]]>
7354
</Resource>
7455
</TestCase>
@@ -145,26 +126,6 @@ LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3], f=[$4])
145126
<![CDATA[
146127
Calc(select=[a, b, Reinterpret(c) AS c, func(c, a) AS d, f])
147128
+- 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])
148-
]]>
149-
</Resource>
150-
</TestCase>
151-
<TestCase name="testFilterPushdownWithUdf">
152-
<Resource name="sql">
153-
<![CDATA[SELECT * FROM UdfTable WHERE UPPER(f) = 'welcome']]>
154-
</Resource>
155-
<Resource name="ast">
156-
<![CDATA[
157-
LogicalProject(a=[$0], b=[$1], c=[$2], d=[$3], f=[$4])
158-
+- LogicalFilter(condition=[=(UPPER($4), _UTF-16LE'welcome')])
159-
+- LogicalWatermarkAssigner(rowtime=[c], watermark=[func(func($3, $0), $0)])
160-
+- LogicalProject(a=[$0], b=[$1], c=[$2], d=[func($2, $0)], f=[$3])
161-
+- LogicalTableScan(table=[[default_catalog, default_database, UdfTable]])
162-
]]>
163-
</Resource>
164-
<Resource name="optimized exec plan">
165-
<![CDATA[
166-
Calc(select=[a, b, Reinterpret(c) AS c, func(c, a) AS d, f])
167-
+- 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])
168129
]]>
169130
</Resource>
170131
</TestCase>

0 commit comments

Comments
 (0)