@Override public String getPhysicalColumnName(String logicalName) { if (!getSchema().containsLogicalName(logicalName)) { LOG.warn( "No mapping found for logical name '{}' to physical name on table '{}'. Will use logical name as " + "physical name. This is unexpected and should not happen for properly configured " + "dimensions.", logicalName, getName() ); } return getSchema().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); } }
/** * Create a physical table. * * @param name Fili name of the physical table * @param timeGrain time grain of the table * @param columns The columns for this physical table * @param logicalToPhysicalColumnNames Mappings from logical to physical names * @param availability The availability of columns in this table */ public BasePhysicalTable( @NotNull TableName name, @NotNull ZonedTimeGrain timeGrain, @NotNull Iterable<Column> columns, @NotNull Map<String, String> logicalToPhysicalColumnNames, @NotNull Availability availability ) { this.name = name.asName(); this.tableName = name; this.availability = availability; this.schema = new PhysicalTableSchema(timeGrain, columns, logicalToPhysicalColumnNames); }
/** * Map availabilities in schema-less columns to a {@link Column} keyed availability map for a given table. * * @param rawIntervals The map of physical name to {@link SimplifiedIntervalList}s as the source availability * @param schema The schema describing the columns of this table, which includes the logical -> physical * mappings * * @return map of column to set of available intervals */ default Map<Column, SimplifiedIntervalList> mapToSchemaAvailability( Map<String, SimplifiedIntervalList> rawIntervals, PhysicalTableSchema schema ) { return schema.getColumns().stream() .collect( Collectors.toMap( Function.identity(), column -> rawIntervals.getOrDefault( schema.getPhysicalColumnName(column.getName()), new SimplifiedIntervalList() ) ) ); } }
@Override public String apply(String input) { return physicalTableSchema.getPhysicalColumnName(input); }
@Override public boolean test(PhysicalTable table) { if (!requestConstraint.getMinimumGranularity().satisfiedBy(table.getSchema().getGranularity())) { return false; } Set<String> supplyNames = table.getSchema().getColumns().stream() .map(Column::getName) .collect(Collectors.toCollection(LinkedHashSet::new)); Set<String> columnNames = requestConstraint.getAllColumnNames(); return supplyNames.containsAll(columnNames); }
/** * 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(); }
/** * Finds the api name given a field name and if none are found then it returns the given input. * * @param input The string to attempt to unalias. * * @return the api name of the column or the original input if no mapping was found. */ public String unApply(String input) { return physicalTableSchema.getLogicalColumnNames(input).stream().findFirst().orElse(input); } }
/** * Ensure that the schema of the constraint is consistent with what the table supports. * * @param constraint The constraint being tested * * @throws IllegalArgumentException If there are columns referenced by the constraint unavailable in the table */ private void validateConstraintSchema(DataSourceConstraint constraint) throws IllegalArgumentException { Set<String> tableColumnNames = getSchema().getColumnNames(); // Validate that the requested columns are answerable by the current table if (!constraint.getAllColumnNames().stream().allMatch(tableColumnNames::contains)) { String message = String.format( "Received invalid request requesting for columns: %s that is not available in this table: %s", constraint.getAllColumnNames().stream() .filter(name -> !tableColumnNames.contains(name)) .collect(Collectors.joining(",")), getName() ); LOG.error(message); throw new IllegalArgumentException(message); } }
(ConfigPhysicalTable physicalTable) -> Sets.intersection( physicalTable.getSchema().getMetricColumnNames(), metricNames
.map(schema -> schema.getColumns(DimensionColumn.class)) .flatMap(Set::stream) .map(DimensionColumn::getDimension)
) throws IllegalArgumentException { Predicate<PhysicalTable> tableDoesNotSatisfy = physicalTable -> !physicalTable.getSchema() .getTimeGrain() .satisfies(timeGrain);
@Override public DateTime getTableAlignment() { return getSchema().getTimeGrain().roundFloor( IntervalUtils.firstMoment(getAllAvailableIntervals().values()).orElse(new DateTime()) ); }
/** * Constructor. * * @param name Name that represents set of fact table names that are put together under this table * @param timeGrain The time grain of the table. The time grain has to satisfy all grains of the tables * @param columns The columns for this table * @param physicalTables A set of PhysicalTables that are put together under this table. The * tables shall have zoned time grains that all satisfy the provided timeGrain * @param logicalToPhysicalColumnNames Mappings from logical to physical names * @param availability The Availability of this table */ public BaseCompositePhysicalTable( @NotNull TableName name, @NotNull ZonedTimeGrain timeGrain, @NotNull Set<Column> columns, @NotNull Set<? extends PhysicalTable> physicalTables, @NotNull Map<String, String> logicalToPhysicalColumnNames, @NotNull Availability availability ) { super( name, timeGrain, columns, logicalToPhysicalColumnNames, availability ); verifyGrainSatisfiesAllSourceTables(getSchema().getTimeGrain(), physicalTables); }
/** * Compare two physical tables identifying which one has fewer time buckets. * * @param table1 The first table * @param table2 The second table * * @return negative if table1 has coarser grain (i.e. fewer rows per time) than table2 */ @Override public int compare(final PhysicalTable table1, final PhysicalTable table2) { // compare to returns -1 if the timeGrain for table1 is finer (expressed in more milliseconds) than table2 int compare = table1.getSchema().getTimeGrain() .getEstimatedDuration() .compareTo(table2.getSchema().getTimeGrain().getEstimatedDuration()); LOG.trace("{} {} {}", table1, compare < 0 ? "<" : ">", table2); // shorter duration means more rows per time, so negate to order by fewer rows rather than shorter duration return -1 * compare; } }
res.put( "timeGrain", e.getValue().getSchema().getTimeGrain().getName().toLowerCase(Locale.ENGLISH) ); res.put("uri", SlicesServlet.getSliceDetailUrl(e.getKey(), uriInfo));
/** * Gets the timezone of the backing table for the given druid query. * * @param druidQuery The druid query to find the timezone for * * @return the {@link DateTimeZone} of the physical table for this query. */ private DateTimeZone getTimeZone(DruidAggregationQuery<?> druidQuery) { return druidQuery.getDataSource() .getPhysicalTable() .getSchema() .getTimeGrain() .getTimeZone(); }
"request.physical.table." + bestTable.getName() + "." + bestTable.getSchema().getTimeGrain() ).mark(); LOG.trace("Found best Table: {}", bestTable);
generated.put("timeGrain", table.getSchema().getTimeGrain().getName()); generated.put("timeZone", table.getSchema().getTimeGrain().getTimeZoneName()); generated.put("dimensions", dimensionsResult); generated.put("metrics", metricsResult);