dengzhhu653 commented on code in PR #3137:
URL: https://github.com/apache/hive/pull/3137#discussion_r1040592119
##########
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:
This function only compares the `histogram`, and does not tell much truth
when either `computedHasHistograms` or `expectedHasHistograms` is false. Cloud
we compare the `ColumnStatisticsData` by `Assert.assertEquals(expected,
computed);` as we did in Line 219?
--
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]