zapr-oss / druidry

Java based Druid Query Generator library
Apache License 2.0
193 stars 86 forks source link

In the examples, there is a bug around creating `DruidTopNQuery` #149

Open joybee-pp opened 3 years ago

joybee-pp commented 3 years ago

Screen Shot 2020-08-03 at 12 46 12

@GG-Zapr In the examples, there is a bug. When creating the DruidTopNQuery object, need to set the datasource. But it shouldn't be the String type. How can fix it?

abhi-zapr commented 3 years ago

Hey @joybee-pp Thanks for pointing this out, we need to update README for fixing this example. Previously dataSource was simply String but now with druid supporting multiple type of data sources now datSource is an object of in.zapr.druid.druidry.dataSource.DataSource.

To achieve top N query like example, you could use TableDataSource like :

DruidTopNQuery query = DruidTopNQuery.builder()
        .dataSource(new TableDataSource("sample_data"))
        .dimension(dimension)
        .threshold(5)
        .topNMetric(metric)
        .granularity(granularity)
        .filter(filter)
        .aggregators(Arrays.asList(aggregator1, aggregator2))
        .postAggregators(Collections.singletonList(postAggregator))
        .intervals(Collections.singletonList(interval))
        .build();