/** * Get the logging blocks that need to be at the "head" of the log output. * * @param order Indication of order of the initial blocks. * * @return the blocks in order */ private static List<String> generateLogInfoOrder(String order) { return Arrays.stream(order.replaceAll("\\s+", "").split(",")) .filter(not(String::isEmpty)) .map(name -> "com.yahoo.bard.webservice.logging.blocks." + name) .collect(Collectors.toList()); } }
/** * Return a collector that creates a LinkedHashMap using the given key and value functions. * This collector assumes the elements being collected are distinct. * * @param <S> Type of the objects being collected * @param <K> Type of the keys * @param <V> Type of the values * @param keyMapper Mapping function for the key * @param valueMapper Mapping function for the value * * @return a collector that creates a LinkedHashMap using the given key and value functions. * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K, V> Collector<S, ?, LinkedHashMap<K, V>> toLinkedMap( Function<? super S, ? extends K> keyMapper, Function<? super S, ? extends V> valueMapper ) { return Collectors.toMap(keyMapper, valueMapper, StreamUtils.throwingMerger(), LinkedHashMap::new); }
/** * This method loads default grains and can be extended to add customer grain extensions. * <p> * @return A map of time grain api name to time grain instances. */ public static GranularityDictionary getDefaultGrainMap() { return Stream.concat( Stream.of(AllGranularity.INSTANCE), Arrays.stream(DefaultTimeGrain.values()) ).collect( StreamUtils.toDictionary( Granularity::getName, GranularityDictionary::new ) ); }
/** * Return a non delegating map which snapshots the data visible in this delegating map, disconnected from changes * to this and the underlying delegates. * * @return A non delegating plain-map copy of the data visible in this map */ public LinkedHashMap<K, V> flatView() { return entryStream() .collect(StreamUtils.toLinkedMap(Map.Entry::getKey, Map.Entry::getValue)); }
/** * Builds a set of only those metric columns which correspond to the metrics requested in the API. * * @param apiMetricColumnNames Set of Metric names extracted from the requested api metrics * * @return set of metric columns */ protected LinkedHashSet<MetricColumn> generateApiMetricColumns(Set<String> apiMetricColumnNames) { // Get the metric columns from the schema Map<String, MetricColumn> metricColumnMap = resultSet.getSchema().getColumns(MetricColumn.class).stream() .collect(StreamUtils.toLinkedDictionary(MetricColumn::getName)); // Select only api metrics from resultSet return apiMetricColumnNames.stream() .map(metricColumnMap::get) .collect(Collectors.toCollection(LinkedHashSet::new)); }
/** * Constructor. * * @param availabilityStream A potentially ordered stream of availabilities which supply this composite view */ protected BaseCompositeAvailability(Stream<Availability> availabilityStream) { sourceAvailabilities = StreamUtils.toUnmodifiableSet(availabilityStream); dataSourcesNames = StreamUtils.toUnmodifiableSet( sourceAvailabilities.stream().map(Availability::getDataSourceNames).flatMap(Set::stream) ); }
/** * Helper method to return request headers as a map of the same type with its keys lower cased. * * @param headers The request headers. * * @return The headers with their names lower cased. */ public static MultivaluedMap<String, String> headersToLowerCase(MultivaluedMap<String, String> headers) { return headers.entrySet().stream() .collect( StreamUtils.toMap( e -> e.getKey().toLowerCase(Locale.ENGLISH), Map.Entry::getValue, MultivaluedHashMap::new ) ); }
/** * Given a collection of objects which share the same super class, return the subset of objects that share a common * sub class. * * @param set Input set * @param <T> Input set type * @param type sub class * @param <K> sub class type * * @return ordered subset of objects that share a common sub class */ public static <T, K extends T> LinkedHashSet<K> getSubsetByType(Collection<T> set, Class<K> type) { return set.stream() .filter(member -> type.isAssignableFrom(member.getClass())) .map(StreamUtils.uncheckedCast(type)) .collect(Collectors.toCollection(LinkedHashSet::new)); }
/** * Check if for a given set of request filters, adding in the filters for this `DataSourceFilter` there is a * corresponding row. * This method should never be called with a dimension that isn't a key in {@link #dimensionKeySelectFilters} * * @param dimension The dimension whose rows are being tested on. * @param constraintFilters The api filters from the constraint * * @return true if for this dimension there are rows matching the query filters AND the embedded filters. */ protected boolean anyRowsMatch(@NotNull Dimension dimension, @NotNull Set<ApiFilter> constraintFilters) { if (!dimensionKeySelectFilters.containsKey(dimension)) { throw new IllegalArgumentException( "Any rows match should only be called with dimensions defined on this filter." ); } Set<ApiFilter> combinedFilters = StreamUtils.append( constraintFilters, dimensionKeySelectFilters.get(dimension) ); return dimension.getSearchProvider().hasAnyRows(combinedFilters); }
/** * Coerces the JobRow into a mapping from the names of JobFields to their values. * * @return A mapping from the name of each JobField to its associated value */ public Map<String, String> getRowMap() { return entrySet().stream() .collect(StreamUtils.toLinkedMap(entry -> entry.getKey().getName(), Map.Entry::getValue)); }
throws BadApiRequestException { Map<String, DimensionField> dimensionNameToFieldMap = dimension.getDimensionFields().stream() .collect(StreamUtils.toLinkedDictionary(DimensionField::getName));
/** * Get DimensionRows as a map of Field Name and Value. * * @return map of fieldname,value */ public LinkedHashMap<String, String> getRowMap() { return entrySet().stream() .collect(StreamUtils.toLinkedMap(entry -> entry.getKey().getName(), Map.Entry::getValue)); } }
/** * Gather duplicate names across the collection of Aggregations and PostAggregations. * * @param aggregations Set of Aggregations to inspect * @param postAggregations Set of PostAggregations to inspect * * @return Set of collided names (if any) */ private Set<String> getNameCollisions( Collection<Aggregation> aggregations, Collection<PostAggregation> postAggregations ) { Set<String> allNames = new HashSet<>(); return Stream.concat(aggregations.stream(), postAggregations.stream()) .map(MetricField::getName) .filter(not(allNames::add)) // Select names that already had been added to allNames .collect(Collectors.toSet()); }
/** * Return a collector that creates a LinkedHashMap dictionary using the given key function. * This collector assumes the elements being collected are distinct. * * @param <S> Type of the objects being collected and the values of the dictionary / map * @param <K> Type of the keys * @param keyMapper Mapping function for the key * * @return a collector that creates a LinkedHashMap dictionary using the given key function. * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K> Collector<S, ?, LinkedHashMap<K, S>> toLinkedDictionary( Function<? super S, ? extends K> keyMapper ) { return Collectors.toMap(keyMapper, Function.identity(), StreamUtils.throwingMerger(), LinkedHashMap::new); }
@Override protected Result check() throws Exception { // Gather information about what has been loaded and what hasn't Map<String, String> dimensionLastUpdated = dimensionDictionary.findAll().stream() .collect( StreamUtils.toLinkedMap( Dimension::getApiName, dim -> dim.getLastUpdated() == null ? NEVER : dim.getLastUpdated().toString() ) ); // Signal health if (dimensionLastUpdated.containsValue(NEVER)) { return Result.unhealthy( String.format( "These dimensions have not been loaded: %s", dimensionLastUpdated.entrySet().stream() .filter(entry -> NEVER.equals(entry.getValue())) .map(Map.Entry::getKey) .collect(Collectors.toSet()) ) ); } else { return Result.healthy(String.format("Dimensions have all been loaded: %s", dimensionLastUpdated)); } }
@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); }
/** * Return a collector that creates a {@link java.util.Map} using the given key and value functions. * This collector assumes the elements being collected are distinct. * <p> * The concrete type of the {@link java.util.Map} being created is given by a {@link java.util.function.Supplier}. * * @param <S> Type of the objects being collected * @param <K> Type of the keys * @param <V> Type of the values * @param <M> The type of Map being collected into * @param keyMapper Mapping function for the key * @param valueMapper Mapping function for the value * @param mapSupplier A {@link java.util.function.Supplier} which provides a new, empty {@link java.util.Map} into * which the results will be inserted * * @return a collector that creates a {@link java.util.Map} using the given key and value functions * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K, V, M extends Map<K, V>> Collector<S, ?, M> toMap( Function<? super S, ? extends K> keyMapper, Function<? super S, ? extends V> valueMapper, Supplier<M> mapSupplier ) { return Collectors.toMap(keyMapper, valueMapper, StreamUtils.throwingMerger(), mapSupplier); }
.collect(StreamUtils.toLinkedMap(Function.identity(), dimensionRow::get));
@Override public NoMatchFoundException noneFoundException() { Set<String> aggDimensions = requestConstraint.getRequestDimensions().stream() .filter(Dimension::isAggregatable) .map(Dimension::getApiName) .collect(Collectors.toSet()); Set<String> nonAggDimensions = requestConstraint.getRequestDimensions().stream() .filter(StreamUtils.not(Dimension::isAggregatable)) .map(Dimension::getApiName) .collect(Collectors.toSet()); LOG.error(MESSAGE_FORMAT.logFormat(nonAggDimensions, aggDimensions)); return new NoMatchFoundException(MESSAGE_FORMAT.format(nonAggDimensions, aggDimensions)); } }
/** * Return a collector that creates a dictionary using the given key function and the given map supplier. * This collector assumes the elements being collected are distinct. * * @param <S> Type of the objects being collected and the values of the dictionary / map * @param <K> Type of the keys * @param <M> The type of Map being collected into * @param keyMapper Mapping function for the key * @param mapSupplier A {@link java.util.function.Supplier} which provides a new, empty {@link java.util.Map} into * which the results will be inserted * * @return a {@link java.util.stream.Collector} that creates a dictionary using the given * {@link java.util.function.Function key function} and the given {@link java.util.function.Supplier map supplier} * @throws IllegalStateException if multiple values are associated with the same key * @see Collectors#toMap(Function, Function, BinaryOperator, java.util.function.Supplier) */ public static <S, K, M extends Map<K, S>> Collector<S, ?, M> toDictionary( Function<? super S, ? extends K> keyMapper, Supplier<M> mapSupplier ) { return Collectors.toMap(keyMapper, Function.identity(), StreamUtils.throwingMerger(), mapSupplier); }