From 8f16e4024997cdd2ec6bd51a83644bb00ede355a Mon Sep 17 00:00:00 2001 From: Esteban Zimanyi Date: Sun, 25 Oct 2026 14:00:53 +0100 Subject: [PATCH] Read the summary statistics through their accessors The summary cases of AggregatesCatalogTest read the summarystats record summaryStatsAgg answers field by field through its accessors, summarystatsCount to summarystatsMax, and a further case reads the record summaryStats answers for the first raster of the raster cases the same way. Measured: over the catalog and libmeos of MobilityDB #3177 and the generators of JMEOS with structure rows, AggregatesCatalogTest passes its 296 tests. The first raster's statistics, 8, 40, 5, 2.7386127875258306, 1 and 9, follow from MobilityDB's over the two rasters, 16, 80, 5, 2.7386127875258306, 1 and 9: the rasters hold the same values and share no pixel. --- .../spark/AggregatesCatalogTest.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/mobilitydb/spark/AggregatesCatalogTest.java b/src/test/java/org/mobilitydb/spark/AggregatesCatalogTest.java index 6827e146..2a4ecc20 100644 --- a/src/test/java/org/mobilitydb/spark/AggregatesCatalogTest.java +++ b/src/test/java/org/mobilitydb/spark/AggregatesCatalogTest.java @@ -70,9 +70,14 @@ static void stopSpark() { } } + /** The query's first row. */ + private static org.apache.spark.sql.Row row(String sql) { + return spark.sql(sql).collectAsList().get(0); + } + /** The value of the query's first row. */ private static Object value(String sql) { - return spark.sql(sql).collectAsList().get(0).get(0); + return row(sql).get(0); } private static String answer(String sql) { @@ -926,23 +931,27 @@ Stream theOverloadAnswersWhatMobilityDBAnswers() { /** Each overload of summaryStatsAgg: its query over the two rasters of the raster cases * of #OVERLOADS and the six fields of the summarystats record MobilityDB answers, count, - * sum, mean, standard deviation, minimum and maximum, read here in the order of the - * record, as no SQL function of the surface reads a field of it. */ + * sum, mean, standard deviation, minimum and maximum, each read by its accessor, + * summarystatsCount to summarystatsMax; and those of summaryStats over the first. */ private static final Object[][] SUMMARIES = { {"summaryStatsAgg(raster, BOOLEAN)", - "SELECT summaryStatsAgg(v, true) FROM (SELECT /*+ REPARTITION(2) */ rasterFromHexWKB(s) AS v FROM VALUES ('0100000200000000000000F03F000000000000F0BF0000000000000000000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00'), ('0100000200000000000000F03F000000000000F0BF0000000000000840000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00') AS t(s))", + "SELECT summarystatsCount(s), summarystatsSum(s), summarystatsMean(s), summarystatsStddev(s), summarystatsMin(s), summarystatsMax(s) FROM (SELECT summaryStatsAgg(v, true) AS s FROM (SELECT /*+ REPARTITION(2) */ rasterFromHexWKB(s) AS v FROM VALUES ('0100000200000000000000F03F000000000000F0BF0000000000000000000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00'), ('0100000200000000000000F03F000000000000F0BF0000000000000840000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00') AS t(s)))", new double[] {16, 80, 5, 2.7386127875258306, 1, 9}}, {"summaryStatsAgg(raster, INT, BOOLEAN)", - "SELECT summaryStatsAgg(v, 2, true) FROM (SELECT /*+ REPARTITION(2) */ rasterFromHexWKB(s) AS v FROM VALUES ('0100000200000000000000F03F000000000000F0BF0000000000000000000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00'), ('0100000200000000000000F03F000000000000F0BF0000000000000840000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00') AS t(s))", - new double[] {18, 900, 50, 25.81988897471611, 10, 90}}}; + "SELECT summarystatsCount(s), summarystatsSum(s), summarystatsMean(s), summarystatsStddev(s), summarystatsMin(s), summarystatsMax(s) FROM (SELECT summaryStatsAgg(v, 2, true) AS s FROM (SELECT /*+ REPARTITION(2) */ rasterFromHexWKB(s) AS v FROM VALUES ('0100000200000000000000F03F000000000000F0BF0000000000000000000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00'), ('0100000200000000000000F03F000000000000F0BF0000000000000840000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00') AS t(s)))", + new double[] {18, 900, 50, 25.81988897471611, 10, 90}}, + {"summaryStats(raster)", + "SELECT summarystatsCount(s), summarystatsSum(s), summarystatsMean(s), summarystatsStddev(s), summarystatsMin(s), summarystatsMax(s) FROM (SELECT summaryStats(rasterFromHexWKB('0100000200000000000000F03F000000000000F0BF0000000000000000000000000000084000000000000000000000000000000000110F0000030003004A003C1CC60000803F000000400000404000008040003C1CC60000C0400000E04000000041000010410600000A0014001E00280032003C00460050005A00')) AS s)", + new double[] {8, 40, 5, 2.7386127875258306, 1, 9}}}; @TestFactory Stream theSummaryAnswersWhatMobilityDBAnswers() { return Stream.of(SUMMARIES) .map(c -> DynamicTest.dynamicTest((String) c[0], () -> { double[] expected = (double[]) c[2]; + org.apache.spark.sql.Row got = row((String) c[1]); for (int i = 0; i < expected.length; i++) { - assertEquals(expected[i], ((Number) ((org.apache.spark.sql.Row) value((String) c[1])).get(i)).doubleValue(), "field " + i); + assertEquals(expected[i], ((Number) got.get(i)).doubleValue(), "field " + i); } })); }