15
15
* limitations under the License.
16
16
*/
17
17
package org .apache .calcite .sql ;
18
+
19
+ import org .apache .calcite .sql .parser .SqlParseException ;
20
+ import org .apache .calcite .sql .parser .SqlParser ;
18
21
import org .apache .calcite .sql .parser .SqlParserPos ;
22
+ import org .apache .calcite .util .Litmus ;
23
+ import org .apache .calcite .util .TestUtil ;
19
24
import org .apache .calcite .util .Util ;
20
25
26
+ import org .hamcrest .CustomTypeSafeMatcher ;
27
+ import org .hamcrest .Matcher ;
21
28
import org .junit .jupiter .api .Test ;
22
29
23
30
import java .util .ArrayList ;
24
31
import java .util .Arrays ;
25
32
import java .util .List ;
26
33
27
34
import static org .hamcrest .CoreMatchers .is ;
35
+ import static org .hamcrest .CoreMatchers .not ;
28
36
import static org .hamcrest .CoreMatchers .sameInstance ;
29
37
import static org .hamcrest .MatcherAssert .assertThat ;
30
38
import static org .hamcrest .Matchers .hasSize ;
@@ -44,6 +52,47 @@ class SqlNodeTest {
44
52
new SqlIdentifier ("y" , zero ))));
45
53
}
46
54
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
+
47
96
/** Compares a list to its own backing list. */
48
97
private void checkList (SqlNodeList nodeList ) {
49
98
checkLists (nodeList , nodeList .getList (), 0 );
0 commit comments