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

dmsysolyatin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/main by this push:
     new 816edd1fa1 [CALCITE-6100] The equalsDeep of SqlRowTypeNameSpec should 
use equalsDeep for fieldTypes rather than reference comparison
816edd1fa1 is described below

commit 816edd1fa1a1d6af7e72416d791eb01d8c66b6ea
Author: Dmitry Sysolyatin <[email protected]>
AuthorDate: Thu Nov 9 21:34:09 2023 +0200

    [CALCITE-6100] The equalsDeep of SqlRowTypeNameSpec should use equalsDeep 
for fieldTypes rather than reference comparison
---
 .../org/apache/calcite/sql/SqlRowTypeNameSpec.java |  3 +-
 .../java/org/apache/calcite/sql/SqlNodeTest.java   | 49 ++++++++++++++++++++
 .../apache/calcite/sql/test/SqlEqualsDeepTest.java | 54 ----------------------
 3 files changed, 51 insertions(+), 55 deletions(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java 
b/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java
index 2e0d8ef02f..e23c406665 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlRowTypeNameSpec.java
@@ -110,7 +110,8 @@ public class SqlRowTypeNameSpec extends SqlTypeNameSpec {
         litmus.withMessageArgs("{} != {}", this, node))) {
       return litmus.fail("{} != {}", this, node);
     }
-    if (!this.fieldTypes.equals(that.fieldTypes)) {
+    if (!SqlNode.equalDeep(this.fieldTypes, that.fieldTypes,
+        litmus.withMessageArgs("{} != {}", this, node))) {
       return litmus.fail("{} != {}", this, node);
     }
     return litmus.succeed();
diff --git a/core/src/test/java/org/apache/calcite/sql/SqlNodeTest.java 
b/core/src/test/java/org/apache/calcite/sql/SqlNodeTest.java
index 459a11894c..220c5cb15b 100644
--- a/core/src/test/java/org/apache/calcite/sql/SqlNodeTest.java
+++ b/core/src/test/java/org/apache/calcite/sql/SqlNodeTest.java
@@ -15,9 +15,16 @@
  * limitations under the License.
  */
 package org.apache.calcite.sql;
+
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
 import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.util.Litmus;
+import org.apache.calcite.util.TestUtil;
 import org.apache.calcite.util.Util;
 
+import org.hamcrest.CustomTypeSafeMatcher;
+import org.hamcrest.Matcher;
 import org.junit.jupiter.api.Test;
 
 import java.util.ArrayList;
@@ -25,6 +32,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
 import static org.hamcrest.CoreMatchers.sameInstance;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.hasSize;
@@ -44,6 +52,47 @@ class SqlNodeTest {
                 new SqlIdentifier("y", zero))));
   }
 
+  /**
+   * Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-4402";>[CALCITE-4402]
+   * SqlCall#equalsDeep does not take into account the function quantifier</a>.
+   */
+  @Test void testCountEqualsDeep() {
+    assertThat("count(a)", isEqualsDeep("count(a)"));
+    assertThat("count(distinct a)", isEqualsDeep("count(distinct a)"));
+    assertThat("count(distinct a)", not(isEqualsDeep("count(a)")));
+  }
+
+  /**
+   * Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6100";>[CALCITE-6100]
+   * The equalsDeep of SqlRowTypeNameSpec should return true if two 
SqlRowTypeNameSpecs are
+   * structurally equivalent</a>.
+   */
+  @Test void testRowEqualsDeep() {
+    assertThat("CAST(a AS ROW(field INTEGER))",
+        isEqualsDeep("CAST(a AS ROW(field INTEGER))"));
+  }
+
+  private static Matcher<String> isEqualsDeep(String sqlExpected) {
+    return new CustomTypeSafeMatcher<String>("isDeepEqual") {
+      @Override protected boolean matchesSafely(String sqlActual) {
+        try {
+          SqlNode sqlNodeActual = parseExpression(sqlActual);
+          SqlNode sqlNodeExpected = parseExpression(sqlExpected);
+
+          return sqlNodeActual.equalsDeep(sqlNodeExpected, Litmus.IGNORE);
+        } catch (SqlParseException e) {
+          throw TestUtil.rethrow(e);
+        }
+      }
+    };
+  }
+
+  private static SqlNode parseExpression(String sql) throws SqlParseException {
+    return SqlParser.create(sql).parseExpression();
+  }
+
   /** Compares a list to its own backing list. */
   private void checkList(SqlNodeList nodeList) {
     checkLists(nodeList, nodeList.getList(), 0);
diff --git 
a/core/src/test/java/org/apache/calcite/sql/test/SqlEqualsDeepTest.java 
b/core/src/test/java/org/apache/calcite/sql/test/SqlEqualsDeepTest.java
deleted file mode 100644
index c6679bfb6f..0000000000
--- a/core/src/test/java/org/apache/calcite/sql/test/SqlEqualsDeepTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.calcite.sql.test;
-
-import org.apache.calcite.sql.SqlNode;
-import org.apache.calcite.sql.parser.SqlParseException;
-import org.apache.calcite.sql.parser.SqlParser;
-import org.apache.calcite.util.Litmus;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * Test case for
- * <a href="https://issues.apache.org/jira/browse/CALCITE-4402";>[CALCITE-4402]
- * SqlCall#equalsDeep does not take into account the function quantifier</a>.
- */
-class SqlEqualsDeepTest {
-
-  @Test void testCountEqualsDeep() throws SqlParseException {
-    assertEqualsDeep("count(a)", "count(a)", true);
-    assertEqualsDeep("count(distinct a)", "count(distinct a)", true);
-    assertEqualsDeep("count(distinct a)", "count(a)", false);
-  }
-
-  private void assertEqualsDeep(String expr0, String expr1, boolean expected)
-      throws SqlParseException {
-
-    SqlNode sqlNode0 = parseExpression(expr0);
-    SqlNode sqlNode1 = parseExpression(expr1);
-
-    assertEquals(expected, sqlNode0.equalsDeep(sqlNode1, Litmus.IGNORE),
-        () -> expr0 + " equalsDeep " + expr1);
-  }
-
-  private static SqlNode parseExpression(String sql) throws SqlParseException {
-    return SqlParser.create(sql).parseExpression();
-  }
-}

Reply via email to