asolimando commented on code in PR #3137:
URL: https://github.com/apache/hive/pull/3137#discussion_r1041223672


##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/StatisticsTestUtils.java:
##########
@@ -109,4 +135,116 @@ public static HyperLogLog createHll(String... values) {
     }
     return hll;
   }
+
+  /**
+   * Creates an HLL object initialized with the given values.
+   * @param values the values to be added
+   * @return an HLL object initialized with the given values.
+   */
+  public static HyperLogLog createHll(double... values) {
+    HyperLogLog hll = HyperLogLog.builder().build();
+    Arrays.stream(values).forEach(hll::addDouble);
+    return hll;
+  }
+
+  /**
+   * Creates a KLL object initialized with the given values.
+   * @param values the values to be added
+   * @return a KLL object initialized with the given values.
+   */
+  public static KllFloatsSketch createKll(float... values) {
+    KllFloatsSketch kll = new KllFloatsSketch();
+    for (float value : values) {
+      kll.update(value);
+    }
+    return kll;
+  }
+
+  /**
+   * Creates a KLL object initialized with the given values.
+   * @param values the values to be added
+   * @return a KLL object initialized with the given values.
+   */
+  public static KllFloatsSketch createKll(double... values) {
+    KllFloatsSketch kll = new KllFloatsSketch();
+    for (double value : values) {
+      kll.update(Double.valueOf(value).floatValue());
+    }
+    return kll;
+  }
+
+  /**
+   * Creates a KLL object initialized with the given values.
+   * @param values the values to be added
+   * @return a KLL object initialized with the given values.
+   */
+  public static KllFloatsSketch createKll(long... values) {
+    KllFloatsSketch kll = new KllFloatsSketch();
+    for (long value : values) {
+      kll.update(value);
+    }
+    return kll;
+  }
+
+  /**
+   * Checks if expected and computed statistics data are equal.
+   * @param expected expected statistics data
+   * @param computed computed statistics data
+   */
+  public static void assertEqualStatistics(ColumnStatisticsData expected, 
ColumnStatisticsData computed) {
+    if (expected.getSetField() != computed.getSetField()) {
+      throw new IllegalArgumentException("Expected data is of type " + 
expected.getSetField()
+          + " while computed data is of type " + computed.getSetField());
+    }
+
+    Class<?> dataClass = null;
+    switch (expected.getSetField()) {
+    case DATE_STATS:
+      dataClass = DateColumnStatsData.class;
+      break;
+    case LONG_STATS:
+      dataClass = LongColumnStatsData.class;
+      break;
+    case DOUBLE_STATS:
+      dataClass = DoubleColumnStatsData.class;
+      break;
+    case DECIMAL_STATS:
+      dataClass = DecimalColumnStatsData.class;
+      break;
+    case TIMESTAMP_STATS:
+      dataClass = TimestampColumnStatsData.class;
+      break;
+    default:
+      // it's an unsupported class for KLL, no special treatment needed
+      Assert.assertEquals(expected, computed);
+      return;
+    }
+    assertEqualStatistics(expected, computed, dataClass);
+  }
+
+  private static <X> void assertEqualStatistics(

Review Comment:
   Unfortunately `KllFloatSketch`'s serialization to byte is sensitive to data 
insertion order (and therefore sketch merging order), even if two sketches are 
functionally the same (the cumulative distribution function results are 
identical, as well as that of any other method), the two byte arrays will 
differ.
   
   The only reason for having created this method is to circumvent that, and 
compare the sketches via their string representation, which is stable w.r.t. 
insertion order etc.
   
   But please note that we do call `Assert.assertEquals(expected, computed)`, 
we do that after comparing the string representation of the two sketches, and 
setting them equal (we restore them back to not alter the input), so we fully 
check everything.
   
   Your comment made me notice that we were not checking anything if one of the 
two input had no histogram, I have handled that case now.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to