This is an automated email from the ASF dual-hosted git repository.
jhyde pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new ee83efd [CALCITE-3009] DiffRepository should ensure that XML resource
file does not contain duplicate test names
ee83efd is described below
commit ee83efd360793ef4201f4cdfc2af8d837b76ca69
Author: Chunwei Lei <[email protected]>
AuthorDate: Wed Apr 17 14:49:14 2019 +0800
[CALCITE-3009] DiffRepository should ensure that XML resource file does not
contain duplicate test names
Close apache/calcite#1167
---
.../org/apache/calcite/test/DiffRepository.java | 29 +++++++++++++++++++---
.../org/apache/calcite/test/RelOptRulesTest.xml | 29 ----------------------
2 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/core/src/test/java/org/apache/calcite/test/DiffRepository.java
b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
index 075a91e..1212563 100644
--- a/core/src/test/java/org/apache/calcite/test/DiffRepository.java
+++ b/core/src/test/java/org/apache/calcite/test/DiffRepository.java
@@ -40,8 +40,10 @@ import java.io.Writer;
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;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -210,10 +212,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);
}
@@ -533,6 +532,28 @@ 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.
*
diff --git
a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
index 6520204..6c849c1 100644
--- a/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/RelOptRulesTest.xml
@@ -9487,35 +9487,6 @@ LogicalProject(NAME=[$0], ENAME=[$2])
]]>
</Resource>
</TestCase>
- <TestCase name="testProjectCorrelateTranspose">
- <Resource name="sql">
- <![CDATA[select t1.name, t2.ename
-from DEPT_NESTED as t1,
-unnest(t1.employees) as t2]]>
- </Resource>
- <Resource name="planBefore">
- <![CDATA[
-LogicalProject(NAME=[$1], ENAME=[$5])
- LogicalCorrelate(correlation=[$cor0], joinType=[inner],
requiredColumns=[{3}])
- LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
- Uncollect
- LogicalProject(EMPLOYEES=[$cor0.EMPLOYEES])
- LogicalValues(tuples=[[{ 0 }]])
-]]>
- </Resource>
- <Resource name="planAfter">
- <![CDATA[
-LogicalProject(NAME=[$0], ENAME=[$2])
- LogicalCorrelate(correlation=[$cor1], joinType=[inner],
requiredColumns=[{1}])
- LogicalProject(NAME=[$1], EMPLOYEES=[$3])
- LogicalTableScan(table=[[CATALOG, SALES, DEPT_NESTED]])
- LogicalProject(ENAME=[$1])
- Uncollect
- LogicalProject(EMPLOYEES=[$cor1.EMPLOYEES])
- LogicalValues(tuples=[[{ 0 }]])
-]]>
- </Resource>
- </TestCase>
<TestCase name="testProjectCorrelateTransposeRuleLeftCorrelate">
<Resource name="planBefore">
<![CDATA[