You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2021/01/20 13:19:26 UTC

[GitHub] [calcite] vlsi commented on a change in pull request #2330: [CALCITE-4465] Estimate the number of distinct values by predicates

vlsi commented on a change in pull request #2330:
URL: https://github.com/apache/calcite/pull/2330#discussion_r560953103



##########
File path: core/src/test/java/org/apache/calcite/rex/RexProgramTest.java
##########
@@ -2857,6 +2857,108 @@ private void checkSarg(String message, Sarg sarg,
         is(2), is("Sarg[[3..8], [10..20]]"));
   }
 
+  /** Tests {@link Sarg#numDistinctVals(RelDataType)}. */
+  @Test void testSargNdv() {
+    RelDataType nonNullableInt = typeFactory.createSqlType(SqlTypeName.INTEGER);
+    RelDataType nullableInt = typeFactory.createTypeWithNullability(nonNullableInt, true);
+
+    RelDataType nonNullableFloat = typeFactory.createSqlType(SqlTypeName.FLOAT);
+    RelDataType nullableFloat = typeFactory.createTypeWithNullability(nonNullableFloat, true);
+
+    // point: 10 (non-nullable)
+    Sarg sarg = Sarg.of(false,
+        ImmutableRangeSet.of(Range.closed(10, 10)));
+    assertThat(sarg.numDistinctVals(nonNullableInt), is(1.0));

Review comment:
       Could you please factor this to a helper method that receives `sarg`, `type`, and the expected matcher?
   
   Then the error message could include `sarg + ".numDistinctVals(" + type + ")"` so the developers could see the inputs that produced invalid output.
   
   The current assertion failures would look like "expected 1.0 got 1.5", and it would be hard to tell what is going on.
   
   
   An alternative option is to split assertions to individual tests (e.g. parameterized)




----------------------------------------------------------------
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:
users@infra.apache.org