protected static Map<String, Object> getLogicalTableFullView(LogicalTable logicalTable, UriInfo uriInfo) { Map<String, Object> resultRow = new LinkedHashMap<>(); resultRow.put("category", logicalTable.getCategory()); resultRow.put("name", logicalTable.getName()); resultRow.put("longName", logicalTable.getLongName()); resultRow.put("retention", logicalTable.getRetention().toString()); resultRow.put("granularity", logicalTable.getGranularity().getName()); resultRow.put("description", logicalTable.getDescription()); resultRow.put( "dimensions", DimensionsServlet.getDimensionListSummaryView(logicalTable.getDimensions(), uriInfo) ); resultRow.put( "metrics", MetricsServlet.getLogicalMetricListSummaryView(logicalTable.getLogicalMetrics(), uriInfo) ); resultRow.put(
/** * Returns union of availabilities of the logical table. * * @param logicalTable The logical table * * @return the union of availabilities of the logical table */ public static SimplifiedIntervalList logicalTableAvailability(LogicalTable logicalTable) { return logicalTable.getTableGroup().getPhysicalTables().stream() .map(PhysicalTable::getAllAvailableIntervals) .map(Map::entrySet) .flatMap(Set::stream) .map(Map.Entry::getValue) .reduce(new SimplifiedIntervalList(), SimplifiedIntervalList::union); } }
/** * Constructor. * * @param table Logical table for the table identifier */ public TableIdentifier(LogicalTable table) { this(table.getName(), table.getGranularity()); }
/** * Get the summary view of the logical table. * * @param logicalTable Logical table to get the view of * @param uriInfo UriInfo of the request * * @return Summary view of the logical table */ public static Map<String, String> getLogicalTableSummaryView(LogicalTable logicalTable, UriInfo uriInfo) { Map<String, String> resultRow = new LinkedHashMap<>(); resultRow.put("category", logicalTable.getCategory()); resultRow.put("name", logicalTable.getName()); resultRow.put("longName", logicalTable.getLongName()); resultRow.put("granularity", logicalTable.getGranularity().getName()); resultRow.put("uri", getLogicalTableUrl(logicalTable, uriInfo)); return resultRow; }
/** * Method to provide metadata of the table. * * @param logicalTable Logical Table Ex: Network, SpaceId * @param uriInfo Uri information to construct the uri's * * @return Meta data details of the given table */ @Override public TableView formatTable(LogicalTable logicalTable, UriInfo uriInfo) { TableView resultRow = new TableView(); resultRow.put("name", logicalTable.getName()); resultRow.put("longName", logicalTable.getLongName()); resultRow.put("description", logicalTable.getDescription()); resultRow.put("category", logicalTable.getCategory()); return resultRow; }
/** * Method to provide grain level details(with metrics and dimensions) of the given logical table. * * @param logicalTable Logical Table at the grain level * @param grain Table grain * @param uriInfo Uri information to construct the uri's * * @return logical table details at grain level with all the associated meta data */ @Override public TableGrainView formatTableGrain(LogicalTable logicalTable, String grain, UriInfo uriInfo) { TableGrainView resultRow = new TableGrainView(); resultRow.put("name", grain); resultRow.put("longName", StringUtils.capitalize(grain)); resultRow.put("description", "The " + logicalTable.getName() + " " + grain + " grain"); resultRow.put("retention", logicalTable.getRetention().toString()); resultRow.put("dimensions", getDimensionListFullView(logicalTable.getDimensions(), uriInfo)); resultRow.put( "metrics", MetricsServlet.getLogicalMetricListSummaryView(logicalTable.getLogicalMetrics(), uriInfo) ); return resultRow; }
@Override public T internalApply(T request, ContainerRequestContext context) throws RequestValidationException { SecurityContext securityContext = context.getSecurityContext(); if (!securityRules.getOrDefault(request.getTable().getName(), (ignored -> true)).test(securityContext)) { throw new RequestValidationException(Response.Status.FORBIDDEN, "Permission Denied", "Request cannot be completed as you do not have enough permission"); } return request; } }
/** * Ensure all request dimensions are part of the logical table. * * @param requestDimensions The dimensions being requested * @param table The logical table being checked * * @throws BadApiRequestException if any of the dimensions do not match the logical table */ protected void validateRequestDimensions(Set<Dimension> requestDimensions, LogicalTable table) throws BadApiRequestException { // Requested dimensions must lie in the logical table requestDimensions = new HashSet<>(requestDimensions); requestDimensions.removeAll(table.getDimensions()); if (!requestDimensions.isEmpty()) { List<String> dimensionNames = requestDimensions.stream() .map(Dimension::getApiName) .collect(Collectors.toList()); LOG.debug(DIMENSIONS_NOT_IN_TABLE.logFormat(dimensionNames, table.getName())); throw new BadApiRequestException(DIMENSIONS_NOT_IN_TABLE.format(dimensionNames, table.getName())); } }
/** * Validate that all metrics are part of the logical table. * * @param logicalMetrics The set of metrics being validated * @param table The logical table for the request * * @throws BadApiRequestException if the requested metrics are not in the logical table */ protected void validateMetrics(Set<LogicalMetric> logicalMetrics, LogicalTable table) throws BadApiRequestException { //get metric names from the logical table Set<String> validMetricNames = table.getLogicalMetrics().stream() .map(LogicalMetric::getName) .collect(Collectors.toSet()); //get metric names from logicalMetrics and remove all the valid metrics Set<String> invalidMetricNames = logicalMetrics.stream() .map(LogicalMetric::getName) .filter(it -> !validMetricNames.contains(it)) .collect(Collectors.toSet()); //requested metrics names are not present in the logical table metric names set if (!invalidMetricNames.isEmpty()) { LOG.debug(METRICS_NOT_IN_TABLE.logFormat(invalidMetricNames, table.getName())); throw new BadApiRequestException( METRICS_NOT_IN_TABLE.format(invalidMetricNames, table.getName()) ); } }
/** * Get the logical tables for which the given logical metric is valid. * * @param logicalMetric Logical Metric to look up Logical Tables by * * @return The list of logical tables that have the logical metric */ public List<LogicalTable> findByLogicalMetric(LogicalMetric logicalMetric) { return values() .stream() .filter(it -> it.getLogicalMetrics().contains(logicalMetric)) .collect(Collectors.toList()); }
/** * Get the logical tables for which the given logical dimension is valid. * * @param dimension Dimension to look up Logical Tables by * * @return The list of logical tables that have the dimension */ public List<LogicalTable> findByDimension(Dimension dimension) { return values() .stream() .filter(it -> it.getDimensions().contains(dimension)) .collect(Collectors.toList()); } }
/** * Load a logical table into the logicalDictionary. * <p> * Note: This builds the logical table as well. * * @param logicalTableName The logical table name * @param nameGroup The table group information for the logical table * @param validGrains The accepted grains for the logical table * @param tableDictionary The dictionary to load the logical table into * @param metricDictionary The dictionary to use when looking up metrics for this table */ public void loadLogicalTableWithGranularities( String logicalTableName, TableGroup nameGroup, Set<? extends Granularity> validGrains, LogicalTableDictionary tableDictionary, MetricDictionary metricDictionary ) { // For every legal grain for (Granularity grain : validGrains) { // Build the logical table LogicalTable logicalTable = new LogicalTable(logicalTableName, grain, nameGroup, metricDictionary); // Load it into the dictionary tableDictionary.put(new TableIdentifier(logicalTable), logicalTable); } }
/** * Get the URL of the logical table. * * @param logicalTable Logical table to get the URL of * @param uriInfo URI Info for the request * * @return The absolute URL for the logical table */ public static String getLogicalTableUrl(LogicalTable logicalTable, UriInfo uriInfo) { return uriInfo.getBaseUriBuilder() .path(TablesServlet.class) .path(TablesServlet.class, "getTableByGrain") .build(logicalTable.getName(), logicalTable.getGranularity().getName()) .toASCIIString(); }
/** * Extracts the list of logical table names from the url table path segment and generates a set of logical table * objects based on it. * * @param tableName logical table corresponding to the table name specified in the URL * @param tableDictionary Logical table dictionary contains the map of valid table names and table objects. * * @return Set of logical table objects. * @throws BadApiRequestException if an invalid table is requested or the logical table dictionary is empty. */ protected LinkedHashSet<LogicalTable> generateTables(String tableName, LogicalTableDictionary tableDictionary) throws BadApiRequestException { LinkedHashSet<LogicalTable> generated = tableDictionary.values().stream() .filter(logicalTable -> tableName == null || tableName.equals(logicalTable.getName())) .collect(Collectors.toCollection(LinkedHashSet::new)); // Check if logical tables exist with the requested logical table name if (generated.isEmpty()) { String msg; if (tableDictionary.isEmpty()) { msg = EMPTY_DICTIONARY.logFormat("Logical Table"); } else { msg = TABLE_UNDEFINED.logFormat(tableName); } LOG.error(msg); throw new BadApiRequestException(msg); } LOG.trace("Generated set of logical tables: {}", generated); return generated; }
if (!table.getDimensions().contains(newFilter.getDimension())) { String filterDimensionName = newFilter.getDimension().getApiName(); LOG.debug(FILTER_DIMENSION_NOT_IN_TABLE.logFormat(filterDimensionName, table)); String errorMessage = FILTER_DIMENSION_NOT_IN_TABLE.format( filterDimensionName, table.getName() ); throw new BadApiRequestException(errorMessage, new BadFilterException(errorMessage));
LogicalTable logicalTable = tablesApiRequest.getTable(); return Stream.of( new SimpleImmutableEntry<>("category", logicalTable.getCategory()), new SimpleImmutableEntry<>("name", logicalTable.getName()), new SimpleImmutableEntry<>("longName", logicalTable.getLongName()), new SimpleImmutableEntry<>("retention", logicalTable.getRetention().toString()), new SimpleImmutableEntry<>("granularity", logicalTable.getGranularity().getName()), new SimpleImmutableEntry<>("description", logicalTable.getDescription()), new SimpleImmutableEntry<>( "dimensions", DimensionsServlet.getDimensionListSummaryView(logicalTable.getDimensions(), uriInfo) ), new SimpleImmutableEntry<>( "metrics", MetricsServlet.getLogicalMetricListSummaryView(logicalTable.getLogicalMetrics(), uriInfo) ), new SimpleImmutableEntry<>(
/** * Method to provide full view of the tables which includes grains, metrics and dimensions. * * @param logicalTables Set of logical tables * @param uriInfo Uri information to construct the uri's * * @return List of table details with all the associated meta info */ @Override public List<TableView> formatTables(Set<LogicalTable> logicalTables, UriInfo uriInfo) { //Map to keep meta info of the logical table Map<String, TableView> tablesMeta = new HashMap<>(); //Map to keep list of time grain details for the logical table Map<String, List<TableGrainView>> grainsData = new HashMap<>(); for (LogicalTable logicalTable : logicalTables) { //An array list to store grain level definition of given logical table List<TableGrainView> grains = grainsData .computeIfAbsent(logicalTable.getName(), (ignore) -> new ArrayList<>()); grains.add(formatTableGrain(logicalTable, logicalTable.getGranularity().getName(), uriInfo)); tablesMeta.computeIfAbsent(logicalTable.getName(), k -> formatTable(logicalTable, uriInfo)); } List<TableView> tableViewList = new ArrayList<>(); Set<Map.Entry<String, TableView>> entrySet = tablesMeta.entrySet(); for (Map.Entry<String, TableView> entry : entrySet) { TableView tableView = entry.getValue(); tableView.put("timeGrains", grainsData.get(entry.getKey())); tableViewList.add(tableView); } return tableViewList; }
/** * Stores the request table name and intervals and creates a predicate to test a physical table based on request * intervals. * * @param requestConstraint Contains the request constraints extracted from DataApiRequest and TemplateDruidQuery */ public TimeAlignmentPhysicalTableMatcher(QueryPlanningConstraint requestConstraint) { if (requestConstraint.getIntervals().isEmpty()) { throw new IllegalStateException("Intervals cannot be empty"); } logicalTableName = requestConstraint.getLogicalTable().getName(); requestIntervals = requestConstraint.getIntervals(); isTableAligned = new IsTableStartAlignedWithIntervals(requestConstraint.getIntervals()); }
/** * 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); }
String format ) { this.table = table.getName(); this.timeGrain = table.getGranularity().toString(); this.numBuckets = 0;