/** * Constructor. * * @param table Logical table for the table identifier */ public TableIdentifier(LogicalTable table) { this(table.getName(), table.getGranularity()); }
/** * 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(); }
@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()) ); } }
/** * 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; }
String format ) { this.table = table.getName(); this.timeGrain = table.getGranularity().toString(); this.numBuckets = 0;
/** * 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; }
/** * 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; }
/** * 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()); }
/** * Builder. * * @param request API Request for which to build a table identifier * * @return the table identifier for the request */ public static TableIdentifier create(DataApiRequest request) { return new TableIdentifier(request.getTable().getName(), getGranularityPeriod(request.getGranularity())); }
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());
@Override public NoMatchFoundException noneFoundException() { String logicalTableName = requestConstraint.getLogicalTable().getName(); Set<String> logicalMetrics = requestConstraint.getLogicalMetricNames(); Set<String> dimensions = requestConstraint.getAllDimensionNames(); String grainName = requestConstraint.getMinimumGranularity().getName(); LOG.error(MESSAGE_FORMAT.logFormat(logicalTableName, dimensions, logicalMetrics, grainName)); return new NoMatchFoundException( MESSAGE_FORMAT.format(logicalTableName, dimensions, logicalMetrics, grainName)); } }
return Stream.of( new SimpleImmutableEntry<>("category", logicalTable.getCategory()), new SimpleImmutableEntry<>("name", logicalTable.getName()), new SimpleImmutableEntry<>("longName", logicalTable.getLongName()), new SimpleImmutableEntry<>("retention", logicalTable.getRetention().toString()),
REGISTRY.meter("request.logical.table." + table.getName() + "." + table.getGranularity()).mark();
String errorMessage = FILTER_DIMENSION_NOT_IN_TABLE.format( filterDimensionName, table.getName() ); throw new BadApiRequestException(errorMessage, new BadFilterException(errorMessage));
/** * 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; }
" Pagination: {}", granularity, table.getName(), dimensions, perDimensionFields,