/** * Compare two Physical Tables based on their number of dimensions. * * @param table1 The first table * @param table2 The second table * * @return negative if table1 has fewer dimensions than table2 */ @Override public int compare(PhysicalTable table1, PhysicalTable table2) { return table1.getDimensions().size() - table2.getDimensions().size(); } }
@Override public boolean test(PhysicalTable table) { Set<String> columnNames = requestConstraint.getAllColumnNames(); // If table contains non-agg dimensions, query must contain all these non-agg dimensions to use this table. return table.getDimensions().stream() .filter(StreamUtils.not(Dimension::isAggregatable)) .map(Dimension::getApiName) .allMatch(columnNames::contains); }
/** * Build a constraint which should not filter away any part of a given table. * * @param table The table whose dimensions and metrics are to be queried * * @return a constraint which should provide no restrictions */ public static DataSourceConstraint unconstrained(PhysicalTable table) { return new DataSourceConstraint( table.getDimensions(), Collections.emptySet(), Collections.emptySet(), table.getSchema().getMetricColumnNames(), table.getDimensions(), table.getDimensions().stream() .map(Dimension::getApiName) .collect(Collectors.toSet()), table.getSchema().getColumnNames(), new ApiFilters(Collections.emptyMap()) ); }