/** * Returns a set of identifiers used by Fili to identify this data source's physical tables. * * @return The set of names used by Fili to identify this data source's physical tables */ @JsonInclude(JsonInclude.Include.NON_NULL) public Set<String> getNames() { return getPhysicalTable().getDataSourceNames().stream() .map(DataSourceName::asName) .collect( Collectors.collectingAndThen( Collectors.toCollection(LinkedHashSet::new), Collections::unmodifiableSet ) ); }
/** * Build a data source from a table. * * @param table A fact table or fact table view * * @return A table datasource for a fact table or a union data source for a fact table view */ private DataSource buildTableDataSource(ConstrainedTable table) { if (table.getDataSourceNames().size() == 1) { return new TableDataSource(table); } else { return new UnionDataSource(table); } }
/** * Constructor. * * @param physicalTable The physical table of the data source. It must have only 1 backing data source. */ public TableDataSource(ConstrainedTable physicalTable) { super(DefaultDataSourceType.TABLE, physicalTable); if (physicalTable.getDataSourceNames().size() > 1) { LOG.error(TOO_MANY_BACKING_DATA_SOURCES.logFormat(getPhysicalTable())); throw new IllegalArgumentException(TOO_MANY_BACKING_DATA_SOURCES.format(getPhysicalTable())); } }
public String getName() { return getPhysicalTable().getDataSourceNames().stream().findFirst() .orElseThrow(() -> { LOG.error(TOO_FEW_BACKING_DATA_SOURCES.logFormat(getPhysicalTable())); return new IllegalArgumentException(TOO_FEW_BACKING_DATA_SOURCES.format(getPhysicalTable())); }).asName(); }
@Override public Optional<Long> getSegmentSetId(DruidAggregationQuery<?> query) { // Gather the data source names backing the query Set<DataSourceName> dataSourceNames = query.getInnermostQuery() .getDataSource() .getPhysicalTable() .getDataSourceNames() .stream() .collect(Collectors.toSet()); // Get all the segments for the data sources of the query's physical tables Set<SortedMap<DateTime, Map<String, SegmentInfo>>> tableSegments = dataSourceMetadataService.getSegments( dataSourceNames ); // Check if we have no tables with segments if (tableSegments.isEmpty()) { LOG.warn(DRUID_METADATA_SEGMENTS_MISSING.logFormat(dataSourceNames)); return Optional.empty(); } // Get requested intervals, then their segments, and sum their hash codes into a long return getSegmentHash( requestedIntervalsQueryExtractionFunctions.get(query.getClass()).apply(query).stream() .flatMap(interval -> tableSegments.stream() .map(segments -> segments.subMap(interval.getStart(), interval.getEnd())) ) ); }
/** * Return the {@link TableName} of the dataSources which back the original source table given a constraint. * * @param constraint A constraint which may narrow the data sources participating. * * @return A set of tablenames for backing dataSources */ @Override public Set<DataSourceName> getDataSourceNames(DataSourceConstraint constraint) { if (getConstraint().equals(constraint)) { return getDataSourceNames(); } return getSourceTable().getDataSourceNames(constraint); }