sbroeder commented on code in PR #5297:
URL: https://github.com/apache/calcite/pull/5297#discussion_r4243926013


##########
core/src/test/java/org/apache/calcite/test/TypeCoercionTest.java:
##########
@@ -484,6 +486,71 @@ private static ImmutableList<RelDataType> combine(
         f.recordType("a", f.arrayType(f.nullableIntType)));
   }
 
+  /**
+   * Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7827";>[CALCITE-7827]
+   * Document precision loss in DECIMAL/REAL comparisons and how to widen them 
to DOUBLE</a>.
+   *
+   * <p>By default, comparing DECIMAL with REAL narrows to REAL. A custom
+   * {@link TypeCoercion} that overrides
+   * {@link TypeCoercion#commonTypeForBinaryComparison} can widen to DOUBLE,
+   * including for the element types of ARRAY and MAP and the fields of ROW. */
+  @Test void testComparisonCoercionDecimalWithApproximateNumericOverride() {
+    final Fixture f = fixture();
+    final RelDataType decimal54 = f.decimalType(5, 4);
+    final RelDataType nullableDecimal54 =
+        f.typeFactory.createTypeWithNullability(decimal54, true);
+
+    final SqlValidator validator = SqlTestFactory.INSTANCE.createValidator();
+    final Fixture w =
+        new Fixture(f.typeFactory,
+            new WideningTypeCoercion(f.typeFactory, validator));
+    w.comparisonCommonType(decimal54, f.realType, f.doubleType);
+    w.comparisonCommonType(nullableDecimal54, f.realType, 
f.nullableDoubleType);
+    w.comparisonCommonType(decimal54, f.nullableRealType, 
f.nullableDoubleType);
+    // No DECIMAL operand: unchanged.
+    w.comparisonCommonType(f.intType, f.realType, f.realType);

Review Comment:
   Done



-- 
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]

Reply via email to