Skip to content

Commit 99acd75

Browse files
author
Dmitry Sysolyatin
committed
Addressed comments
1 parent f78a224 commit 99acd75

File tree

2 files changed

+49
-67
lines changed

2 files changed

+49
-67
lines changed

core/src/test/java/org/apache/calcite/sql/SqlNodeTest.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515
* limitations under the License.
1616
*/
1717
package org.apache.calcite.sql;
18+
19+
import org.apache.calcite.sql.parser.SqlParseException;
20+
import org.apache.calcite.sql.parser.SqlParser;
1821
import org.apache.calcite.sql.parser.SqlParserPos;
22+
import org.apache.calcite.util.Litmus;
23+
import org.apache.calcite.util.TestUtil;
1924
import org.apache.calcite.util.Util;
2025

26+
import org.hamcrest.CustomTypeSafeMatcher;
27+
import org.hamcrest.Matcher;
2128
import org.junit.jupiter.api.Test;
2229

2330
import java.util.ArrayList;
2431
import java.util.Arrays;
2532
import java.util.List;
2633

2734
import static org.hamcrest.CoreMatchers.is;
35+
import static org.hamcrest.CoreMatchers.not;
2836
import static org.hamcrest.CoreMatchers.sameInstance;
2937
import static org.hamcrest.MatcherAssert.assertThat;
3038
import static org.hamcrest.Matchers.hasSize;
@@ -44,6 +52,47 @@ class SqlNodeTest {
4452
new SqlIdentifier("y", zero))));
4553
}
4654

55+
/**
56+
* Test case for
57+
* <a href="https://issues.apache.org/jira/browse/CALCITE-4402">[CALCITE-4402]
58+
* SqlCall#equalsDeep does not take into account the function quantifier</a>.
59+
*/
60+
@Test void testCountEqualsDeep() {
61+
assertThat("count(a)", isEqualsDeep("count(a)"));
62+
assertThat("count(distinct a)", isEqualsDeep("count(distinct a)"));
63+
assertThat("count(distinct a)", not(isEqualsDeep("count(a)")));
64+
}
65+
66+
/**
67+
* Test case for
68+
* <a href="https://issues.apache.org/jira/browse/CALCITE-6100">[CALCITE-6100]
69+
* The equalsDeep of SqlRowTypeNameSpec should return true if two SqlRowTypeNameSpecs are
70+
* structurally equivalent</a>.
71+
*/
72+
@Test void testRowEqualsDeep() {
73+
assertThat("CAST(a AS ROW(field INTEGER))",
74+
isEqualsDeep("CAST(a AS ROW(field INTEGER))"));
75+
}
76+
77+
private static Matcher<String> isEqualsDeep(String sqlExpected) {
78+
return new CustomTypeSafeMatcher<String>("isDeepEqual") {
79+
@Override protected boolean matchesSafely(String sqlActual) {
80+
try {
81+
SqlNode sqlNodeActual = parseExpression(sqlActual);
82+
SqlNode sqlNodeExpected = parseExpression(sqlExpected);
83+
84+
return sqlNodeActual.equalsDeep(sqlNodeExpected, Litmus.IGNORE);
85+
} catch (SqlParseException e) {
86+
throw TestUtil.rethrow(e);
87+
}
88+
}
89+
};
90+
}
91+
92+
private static SqlNode parseExpression(String sql) throws SqlParseException {
93+
return SqlParser.create(sql).parseExpression();
94+
}
95+
4796
/** Compares a list to its own backing list. */
4897
private void checkList(SqlNodeList nodeList) {
4998
checkLists(nodeList, nodeList.getList(), 0);

core/src/test/java/org/apache/calcite/sql/test/SqlEqualsDeepTest.java

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)