liyafan82 commented on a change in pull request #2224:
URL: https://github.com/apache/calcite/pull/2224#discussion_r508963492
##########
File path: core/src/test/java/org/apache/calcite/plan/RelOptUtilTest.java
##########
@@ -130,6 +130,43 @@
Util.toLinux(RelOptUtil.dumpType(t2) + "\n"));
}
+ @Test void testTypeDifference() {
+ final RelDataTypeFactory typeFactory =
+ new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+ final RelDataType t1 =
+ typeFactory.builder()
+ .add("f0", SqlTypeName.DECIMAL, 5, 2)
+ .add("f1", SqlTypeName.VARCHAR, 10)
+ .build();
+
+ RelDataType t2 =
+ typeFactory.builder()
+ .add("f0", SqlTypeName.DECIMAL, 5, 2)
+ .add("f1", SqlTypeName.VARCHAR, 5)
+ .build();
+
+ TestUtil.assertEqualsVerbose(
+ TestUtil.fold(
+ "Type mismatch: ",
+ "f1: VARCHAR(10) NOT NULL -> VARCHAR(5) NOT NULL",
+ ""),
+ Util.toLinux(RelOptUtil.getFullTypeDifferenceString(t1, t2) + "\n"));
+
+ t2 =
+ typeFactory.builder()
+ .add("f0", SqlTypeName.DECIMAL, 4, 2)
+ .add("f1", SqlTypeName.BIGINT)
+ .build();
+
+ TestUtil.assertEqualsVerbose(
+ TestUtil.fold(
+ "Type mismatch: ",
+ "f0: DECIMAL(5, 2) NOT NULL -> DECIMAL(4, 2) NOT NULL",
+ "f1: VARCHAR(10) NOT NULL -> BIGINT NOT NULL",
+ ""),
+ Util.toLinux(RelOptUtil.getFullTypeDifferenceString(t1, t2) + "\n"));
+ }
Review comment:
Maybe we also need a test case for which the types are identical, and
the difference string is empty?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]