Maytas Monsereenusorn
05/31/2024, 7:39 AMMaytas Monsereenusorn
05/31/2024, 9:05 AMMaytas Monsereenusorn
05/31/2024, 9:06 AMGian Merlino
06/05/2024, 7:34 AMGian Merlino
06/05/2024, 7:53 AMSpectatorHistogramAggregator code i think i see what you are talking about. it's a complex type, but it has isNull and getLong methods defined that do kind of allow it to act as the basis for a numeric selectorGian Merlino
06/05/2024, 7:59 AMSpectatorHistogram extends Number, so the result of get can also be interpreted numericallyGian Merlino
06/05/2024, 7:59 AMGian Merlino
06/05/2024, 8:02 AMSpectatorHistogramAggregatorTest, extending it to use both IncrementalIndexSegment as well as QueryableIndexSegmentGian Merlino
06/05/2024, 8:03 AMspectator-histogram.md so we should fix this so it worksGian Merlino
06/05/2024, 8:19 AMObjectColumnSelector
2) move the logic to a new subclass of ObjectColumnSelector used by IncrementalIndex for COMPLEX (i.e., if the object is an instance of Number, the selector has numeric methods that "work")
3) move the logic into the aggregators, so they check if their input is type COMPLEX, and if so, they call getObject and check if the returned thing is NumberGian Merlino
06/05/2024, 8:19 AMGian Merlino
06/05/2024, 8:23 AMZoltan Haindrich
06/05/2024, 10:36 AMget and getLong will probably hit back later - so I think this should be change to some other approach
there's also some comment about this [here](https://github.com/apache/druid/pull/15371#issuecomment-2145013508)
I'm not sure - but I hope that for (2) possibly [ObjectBasedColumnSelector](https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/ObjectBasedColumnSelector.java) could be utilized
I was thinking to move the non-object related stuff into some post-agg functions
a testcase would really help me understand how this supposed to work...Ben Sykes
06/05/2024, 7:43 PMGian Merlino
06/05/2024, 10:09 PMGian Merlino
06/05/2024, 10:51 PMGian Merlino
06/05/2024, 10:51 PMMaytas Monsereenusorn
06/05/2024, 10:53 PM@Test
public void testBuildingAndCountingHistogramsIncrementalIndex() throws Exception
{
List<String> dimensions = Collections.singletonList("d");
int n = 10;
List<InputRow> inputRows = new ArrayList<>(n);
for (int i = 1; i <= n; i++) {
String val = String.valueOf(i * 1.0d);
inputRows.add(new MapBasedInputRow(
DateTime.now(DateTimeZone.UTC),
dimensions,
ImmutableMap.of("x", i, "d", val)
));
}
IncrementalIndex index = AggregationTestHelper.createIncrementalIndex(
inputRows.iterator(),
new NoopInputRowParser(null),
new AggregatorFactory[]{
new CountAggregatorFactory("count"),
new SpectatorHistogramAggregatorFactory("histogram", "x")
},
0,
Granularities.NONE,
100,
false
);
ImmutableList<Segment> segments = ImmutableList.of(
new IncrementalIndexSegment(index, SegmentId.dummy("test")),
helper.persistIncrementalIndex(index, null)
);
GroupByQuery query = new GroupByQuery.Builder()
.setDataSource("test")
.setGranularity(Granularities.ALL)
.setInterval("1970/2050")
.setAggregatorSpecs(
new DoubleSumAggregatorFactory("doubleSum", "histogram")
).build();
Sequence<ResultRow> seq = helper.runQueryOnSegmentsObjs(segments, query);
List<ResultRow> results = seq.toList();
Assert.assertEquals(1, results.size());
// Check doubleSum
Assert.assertEquals((double) n * segments.size(), results.get(0).get(0));
}Maytas Monsereenusorn
06/05/2024, 10:54 PMBen Sykes
06/05/2024, 11:06 PMGian Merlino
06/06/2024, 5:04 AMZoltan Haindrich
06/06/2024, 8:03 AMBen Sykes
06/06/2024, 3:22 PMZoltan Haindrich
06/06/2024, 3:23 PMZoltan Haindrich
06/06/2024, 3:25 PMGian Merlino
06/06/2024, 4:09 PMlongSum or doubleSum. this is mostly for alignment with how it'd need to be exposed in sql (most of our users use sql so that's the main way i think about querying). in sql, you can't do SUM(histogram) since it wouldn't validate: SUM is a standard function that takes standard types. it would instead be something like SUM(SPECTATOR_HISTOGRAM_COUNT(histogram)). the native query version of that would be an expression function like spectator_histogram_count that could go in the expression parameter of longSum or doubleSum.
but since it's already released with docs that say you can use longSum or doubleSum directly (without an expression), i lean towards fixing things such that the docs are true (rather than changing the design and changing the docs)Zoltan Haindrich
06/06/2024, 4:34 PMBen Sykes
06/06/2024, 6:04 PMCannot apply 'SUM' to arguments of type 'SUM(<COMPLEX<SPECTATORHISTOGRAMDISTRIBUTION>>)'. Supported form(s): 'SUM(<NUMERIC>)'
I still like that in native queries we can use longSum directly without having to care to add a specific aggregator.
Would it ever be possible to use a plain SUM with columns like this?Ben Sykes
06/06/2024, 6:53 PMMaytas Monsereenusorn
06/06/2024, 6:53 PMGian Merlino
06/06/2024, 9:20 PMExprMacro). actually to expose in SQL, it's more important to have an ExprMacro than a PostAggregator anyway. post-aggs can only be used in a specific spot (post aggregation 😉) but exprs can be used anywhere (filtering, pre-agg, post-agg, join conditions, etc)Gian Merlino
06/26/2024, 6:21 PMMaytas Monsereenusorn
06/26/2024, 11:04 PM