/** * Getter for dimension rows. * * @return Set of dimension rows the Search Provider has in it's indexes * */ default Set<DimensionRow> findAllDimensionRows() { return new LinkedHashSet<>( findAllDimensionRowsPaged(PaginationParameters.EVERYTHING_IN_ONE_PAGE).getPageOfData() ); }
/** * Determine if any rows match these filters. * * @param filters ApiFilters to use for finding matching dimension rows * * @return true if at least one row is returned. */ default boolean hasAnyRows(Set<ApiFilter> filters) { return findFilteredDimensionRowsPaged(filters, PaginationParameters.ONE_RESULT).getNumResults() > 0; }
/** * Gets the number of distinct dimension rows (assuming the key field is unique) in the index. * * @param refresh If true, clear any cached cardinality and recalculate before returning. * * @return The number of dimension rows for this dimension */ default int getDimensionCardinality(boolean refresh) { // If no caching is done, simply delegate return getDimensionCardinality(); }
/*** * Get the pagination of dimension rows. * <p> * if there is filter in API request, then apply the filter to the querying dimension rows, otherwise returns all * dimension rows. * * @param apiRequest The apiRequest * @param searchProvider The searchProvider * @param paginationParameters The pagination parameters * * @return Pagination of dimensionRow */ protected Pagination<DimensionRow> getPagedRows( DimensionsApiRequest apiRequest, SearchProvider searchProvider, PaginationParameters paginationParameters ) { return apiRequest.getFilters().isEmpty() ? searchProvider.findAllDimensionRowsPaged(paginationParameters) : searchProvider.findFilteredDimensionRowsPaged( apiRequest.getFilters(), paginationParameters ); }
this.searchProvider = searchProvider; this.searchProvider.setDimension(this); this.searchProvider.setKeyValueStore(keyValueStore);
/** * Check if for a given set of request filters, adding in the filters for this `DataSourceFilter` there is a * corresponding row. * This method should never be called with a dimension that isn't a key in {@link #dimensionKeySelectFilters} * * @param dimension The dimension whose rows are being tested on. * @param constraintFilters The api filters from the constraint * * @return true if for this dimension there are rows matching the query filters AND the embedded filters. */ protected boolean anyRowsMatch(@NotNull Dimension dimension, @NotNull Set<ApiFilter> constraintFilters) { if (!dimensionKeySelectFilters.containsKey(dimension)) { throw new IllegalArgumentException( "Any rows match should only be called with dimensions defined on this filter." ); } Set<ApiFilter> combinedFilters = StreamUtils.append( constraintFilters, dimensionKeySelectFilters.get(dimension) ); return dimension.getSearchProvider().hasAnyRows(combinedFilters); }
@Override protected Result check() throws Exception { if (searchProvider.isHealthy()) { return Result.healthy("SearchProvider is healthy."); } else { return Result.unhealthy("SearchProvider is not healthy."); } } }
/** * Resolves a set of ApiFilters into a list of dimension rows that need to be filtered in Druid. * * @param dimension The dimension being filtered * @param filters The filters being applied to the {@code dimension} * * @return A list of dimension rows that Druid needs to filter on * * @throws DimensionRowNotFoundException if the filters filter out all dimension rows */ protected Set<DimensionRow> getFilteredDimensionRows(Dimension dimension, Set<ApiFilter> filters) throws DimensionRowNotFoundException { Set<DimensionRow> rows = dimension.getSearchProvider().findFilteredDimensionRows(filters); if (rows.isEmpty()) { String msg = ErrorMessageFormat.DIMENSION_ROWS_NOT_FOUND.format(dimension.getApiName(), filters); LOG.debug(msg); throw new DimensionRowNotFoundException(msg); } return rows; }
/** * Internal method for cleaning the dimension rows. */ public void deleteAllDimensionRows() { try { String dimRowIndexes = keyValueStore.get(DimensionStoreKeyUtils.getAllValuesKey()); if (dimRowIndexes == null) { return; } String[] keys = objectMapper.readValue(dimRowIndexes, String[].class); LinkedHashSet<String> dimRowKeys = new LinkedHashSet<>(Arrays.asList(keys)); for (String dimRowKey : dimRowKeys) { keyValueStore.remove(dimRowKey); } searchProvider.setKeyValueStore(keyValueStore); // Reset cardinality to 0 keyValueStore.put(DimensionStoreKeyUtils.getCardinalityKey(), "0"); // Reset list to empty String allValuesKey = DimensionStoreKeyUtils.getAllValuesKey(); keyValueStore.put(allValuesKey, "[]"); } catch (IOException e) { LOG.error("Exception while reading dimension rows {}", e); throw new RuntimeException(e); } }
searchProvider.refreshIndex(indexRows);
@Override public int getCardinality() { return searchProvider.getDimensionCardinality(); }
/** * Get a set of dimension row(s) given a set of ApiFilters. * * @param filters ApiFilters to use for finding matching dimension rows * * @return set of dimension row(s) * */ default TreeSet<DimensionRow> findFilteredDimensionRows(Set<ApiFilter> filters) { return new TreeSet<>( findFilteredDimensionRowsPaged(filters, PaginationParameters.EVERYTHING_IN_ONE_PAGE).getPageOfData() ); }