/** * Return a view of the available intervals. * * @return The widest set of intervals that the table can report on */ default SimplifiedIntervalList getAvailableIntervals() { // By default union all available columns return getAllAvailableIntervals().values().stream() .reduce(SimplifiedIntervalList::union) .orElse(new SimplifiedIntervalList()); }
/** * Return a view of the available intervals for this table given a constraint. * * @param constraint The constraint which limits available intervals * * @return The widest set of intervals that the table can report on, given the constraints */ default SimplifiedIntervalList getAvailableIntervals(DataSourceConstraint constraint) { // Default to unconstrained return getAvailableIntervals(); }
/** * Return the {@link DataSourceName} of the dataSources which back this table given a constraint. * * @param constraint A constraint which may narrow the data sources participating. * * @return A set of names for backing dataSources, given the constraints */ default Set<DataSourceName> getDataSourceNames(DataSourceConstraint constraint) { return getDataSourceNames(); }
Map<Column, SimplifiedIntervalList> columnCache = table.getAllAvailableIntervals(); Set<Map<String, Object>> dimensionsResult = new LinkedHashSet<>(); Set<Map<String, Object>> metricsResult = new LinkedHashSet<>(); String dimensionApiName = dimension.getApiName(); row.put("name", dimensionApiName); row.put("factName", table.getPhysicalColumnName(dimensionApiName)); row.put("uri", DimensionsServlet.getDimensionUrl(dimension, uriInfo)); dimensionsResult.add(row); table.getDataSourceNames() ); generated.put("timeGrain", table.getSchema().getTimeGrain().getName()); generated.put("timeZone", table.getSchema().getTimeGrain().getTimeZoneName()); generated.put("dimensions", dimensionsResult); generated.put("metrics", metricsResult);
/** * 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()) ); }
/** * Get the columns from the schema for this physical table. * * @return The columns of this physical table * * @deprecated In favor of getting the columns directly from the schema */ @Deprecated default Set<Column> getColumns() { return getSchema().getColumns(); }
/** * Create a constrained copy of the source table. * * @param constraint The dataSourceConstraint which narrows the view of the underlying availability * * @return a constrained table whose availability and serialization are narrowed by this constraint */ @Override public ConstrainedTable withConstraint(DataSourceConstraint constraint) { return getSourceTable().withConstraint(constraint); } }
/** * Use a default function with overrides for particular tables. * * @param defaultIntervalsFunction The volatile intervals function to apply to physical tables * @param intervalsFunctions A map of functions to provide volatile intervals for physical tables */ public DefaultingVolatileIntervalsService( VolatileIntervalsFunction defaultIntervalsFunction, Map<PhysicalTable, VolatileIntervalsFunction> intervalsFunctions ) { this.defaultIntervals = defaultIntervalsFunction; this.intervalsFunctions = Collections.unmodifiableMap( intervalsFunctions.entrySet().stream() .collect(Collectors.toMap(entry -> entry.getKey().getName(), Map.Entry::getValue)) ); }
/** * 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 TableName getTableName() { return getSourceTable().getTableName(); }
@Override public DateTime getTableAlignment() { return getSourceTable().getTableAlignment(); }
@Override public String getPhysicalColumnName(String logicalName) { return getSourceTable().getPhysicalColumnName(logicalName); }
/** * Test whether table aligns with the interval collection supplied. * * @param table The table whose alignment is under test * * @return true if this physical table's buckets can align to the request. */ @Override public boolean test(PhysicalTable table) { return alignsTo.stream().allMatch(table.getSchema().getTimeGrain()::aligns); } }
/** * Returns union of constrained availabilities of constrained logical table. * * @param logicalTable The constrained logical table * @param queryPlanningConstraint The constraint * * @return the union of constrained availabilities of constrained logical table */ public static SimplifiedIntervalList getConstrainedLogicalTableAvailability( LogicalTable logicalTable, QueryPlanningConstraint queryPlanningConstraint ) { return logicalTable.getTableGroup().getPhysicalTables().stream() .map(physicalTable -> physicalTable.withConstraint(queryPlanningConstraint)) .map(PhysicalTable::getAvailableIntervals) .reduce(new SimplifiedIntervalList(), SimplifiedIntervalList::union); }
@Override public String getName() { return getSourceTable().getName(); }
@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); }
@Override public PhysicalTableSchema getSchema() { return getSourceTable().getSchema(); }
/** * Return a view of the available intervals for the original source table given a constraint. * * @param constraint The constraint which limits available intervals * * @return The intervals that the table can report on */ @Override public SimplifiedIntervalList getAvailableIntervals(DataSourceConstraint constraint) { if (getConstraint().equals(constraint)) { return getAvailableIntervals(); } return getSourceTable().getAvailableIntervals(constraint); }
ConstrainedTable table = resolver.resolve(group.getPhysicalTables(), constraint).withConstraint(constraint); Filter filter = druidFilterBuilder.buildFilters(request.getApiFilters());