vlsi commented on code in PR #5281:
URL: https://github.com/apache/calcite/pull/5281#discussion_r4349838890
##########
core/src/test/java/org/apache/calcite/sql/type/SqlTypeFactoryTest.java:
##########
@@ -36,16 +40,61 @@
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasToString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
Review Comment:
The existing tests compare values with Hamcrest `assertThat` (87 uses);
`assertEquals` and `assertSame` were not imported before. Please use
`assertThat(..., is(...))` and `assertThat(..., sameInstance(...))` (static
import from `org.hamcrest.CoreMatchers`) in the new tests. At lines 93-94,
`assertThat(coercible.getCollation(), sameInstance(SqlCollation.COERCIBLE))`
also pins the exact instance the caller passed and drops the `requireNonNull`.
##########
core/src/test/java/org/apache/calcite/sql/type/SqlTypeFactoryTest.java:
##########
@@ -36,16 +40,61 @@
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasToString;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
+import static java.util.Objects.requireNonNull;
+
/**
* Test for {@link SqlTypeFactoryImpl}.
*/
class SqlTypeFactoryTest {
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7807">[CALCITE-7807]
+ * Reuse unchanged SQL types during least-restrictive inference</a>. */
+ @Test void testUnchangedCharsetAndCollationReturnsSameType() {
+ final BasicSqlType type = (BasicSqlType) new SqlTypeFixture().sqlVarchar;
+ final Charset charset = requireNonNull(type.getCharset());
+ final SqlCollation collation = requireNonNull(type.getCollation());
+
+ assertSame(type,
+ type.createWithCharsetAndCollation(charset, collation),
+ "createWithCharsetAndCollation(" + charset + ", " + collation + ")");
+ }
+
+ @Test void testDifferentCharsetIsAppliedToNewType() {
+ final BasicSqlType type =
+ new BasicSqlType(RelDataTypeSystem.DEFAULT, SqlTypeName.VARCHAR, 10)
+ .createWithCharsetAndCollation(
+ StandardCharsets.ISO_8859_1, SqlCollation.IMPLICIT);
+ final BasicSqlType utf16Type =
+ type.createWithCharsetAndCollation(StandardCharsets.UTF_16,
SqlCollation.IMPLICIT);
+
+ assertEquals(StandardCharsets.UTF_16, utf16Type.getCharset());
+ assertSame(SqlCollation.IMPLICIT, utf16Type.getCollation());
+ }
+
+ /** {@link SqlCollation#equals} ignores coercibility, so COERCIBLE equals
+ * IMPLICIT; the type must still be rebuilt. */
Review Comment:
"the type must still be rebuilt" describes the implementation, and the test
does not check it. The test checks the coercibility of the result, so the
comment could read: "The result carries the requested coercibility, although
{@link SqlCollation#equals} treats COERCIBLE and IMPLICIT as equal."
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]