/** * Reads the results of a Druid GroupBy Query to find dimension values. * * @param dimension The dimension to load values for. * * @return the callback to load dimension values. */ private SuccessCallback buildSuccessCallback(Dimension dimension) { return rootNode -> { rootNode.forEach(row -> { JsonNode eventRow = row.get("event"); String dimensionValue = eventRow.get(dimension.getApiName()).asText(); if (dimension.findDimensionRowByKeyValue(dimensionValue) == null) { DimensionRow dimensionRow = dimension.createEmptyDimensionRow(dimensionValue); updateDimensionWithValue(dimension, dimensionRow); } }); updateDimension(dimension); }; }
@Override public void query(Dimension dimension, DataSource dataSource) { SuccessCallback successCallback = buildSuccessCallback(dimension); SqlPhysicalTable sqlTable = (SqlPhysicalTable) dataSource.getPhysicalTable().getSourceTable(); GroupByQuery groupByQuery = new GroupByQuery( dataSource, AllGranularity.INSTANCE, Collections.singletonList(dimension), null, null, Collections.emptyList(), Collections.emptyList(), Collections.singletonList(INTERVAL), new LimitSpec(Utils.asLinkedHashSet(), OptionalInt.of(ROW_LIMIT)) ); sqlBackedClient.executeQuery(groupByQuery, successCallback, failureCallback); }