private static Optional<List<Symbol>> translateSymbols(Iterable<Symbol> partitioning, Function<Symbol, Optional<Symbol>> translator) { ImmutableList.Builder<Symbol> newPartitioningColumns = ImmutableList.builder(); for (Symbol partitioningColumn : partitioning) { Optional<Symbol> translated = translator.apply(partitioningColumn); if (!translated.isPresent()) { return Optional.empty(); } newPartitioningColumns.add(translated.get()); } return Optional.of(newPartitioningColumns.build()); }
@Override public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) { InformationSchemaTableHandle informationSchemaTableHandle = checkTableHandle(tableHandle); ConnectorTableMetadata tableMetadata = TABLES.get(informationSchemaTableHandle.getSchemaTableName()); return tableMetadata.getColumns().stream() .map(ColumnMetadata::getName) .collect(toMap(identity(), InformationSchemaColumnHandle::new)); }
/** * Constructor with externally managed Reactor Netty resources, including * {@link LoopResources} for event loop threads, and {@link ConnectionProvider} * for the connection pool. * <p>This constructor should be used only when you don't want the client * to participate in the Reactor Netty global resources. By default the * client participates in the Reactor Netty global resources held in * {@link reactor.netty.http.HttpResources}, which is recommended since * fixed, shared resources are favored for event loop concurrency. However, * consider declaring a {@link ReactorResourceFactory} bean with * {@code globalResources=true} in order to ensure the Reactor Netty global * resources are shut down when the Spring ApplicationContext is closed. * @param factory the resource factory to obtain the resources from * @param mapper a mapper for further initialization of the created client * @since 5.1 */ public ReactorClientHttpConnector(ReactorResourceFactory factory, Function<HttpClient, HttpClient> mapper) { this.httpClient = defaultInitializer.andThen(mapper).apply(initHttpClient(factory)); }
private static <T, S extends Publisher<T>> S readWithMessageReaders( ReactiveHttpInputMessage message, BodyExtractor.Context context, ResolvableType elementType, Function<HttpMessageReader<T>, S> readerFunction, Function<UnsupportedMediaTypeException, S> errorFunction, Supplier<S> emptySupplier) { if (VOID_TYPE.equals(elementType)) { return emptySupplier.get(); } MediaType contentType = Optional.ofNullable(message.getHeaders().getContentType()) .orElse(MediaType.APPLICATION_OCTET_STREAM); return context.messageReaders().stream() .filter(reader -> reader.canRead(elementType, contentType)) .findFirst() .map(BodyExtractors::<T>cast) .map(readerFunction) .orElseGet(() -> { List<MediaType> mediaTypes = context.messageReaders().stream() .flatMap(reader -> reader.getReadableMediaTypes().stream()) .collect(Collectors.toList()); return errorFunction.apply( new UnsupportedMediaTypeException(contentType, mediaTypes, elementType)); }); }
private List<Tag> tags(RouteMethod route, Function<String, Tag> tagFactory) { String[] tags = arrayAttribute(route, "tags"); if (tags != null) { List<Tag> result = Stream.of(tags) .filter(it -> it.length() > 0) .map(tagFactory) .collect(Collectors.toList()); if (result.size() > 0) { return result; } } Tag tag = tagFactory.apply(tagger.apply(route)); route.summary().ifPresent(tag::description); return ImmutableList.of(tag); }
private ConnectorTableMetadata getTableMetadata(SchemaTableName tableName) if (!table.isPresent() || table.get().getTableType().equals(TableType.VIRTUAL_VIEW.name())) { throw new TableNotFoundException(tableName); Function<HiveColumnHandle, ColumnMetadata> metadataGetter = columnMetadataGetter(table.get(), typeManager); ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder(); for (HiveColumnHandle columnHandle : hiveColumnHandles(table.get())) { columns.add(metadataGetter.apply(columnHandle)); ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder(); if (table.get().getTableType().equals(EXTERNAL_TABLE.name())) { properties.put(EXTERNAL_LOCATION_PROPERTY, table.get().getStorage().getLocation()); List<String> partitionedBy = table.get().getPartitionColumns().stream() .map(Column::getName) .collect(toList()); if (!partitionedBy.isEmpty()) { properties.put(PARTITIONED_BY_PROPERTY, partitionedBy); Optional<String> comment = Optional.ofNullable(table.get().getParameters().get(TABLE_COMMENT)); return new ConnectorTableMetadata(tableName, columns.build(), properties.build(), comment);
if (!driverOptions.suites.isEmpty()) { suites = suites.stream() .filter(suite -> driverOptions.suites.contains(suite.getName())) .collect(Collectors.toList()); suites = ImmutableList.copyOf(suites); if (driverOptions.queries.isEmpty()) { queries = suites.stream() .map(suite -> suite.selectQueries(allQueries)) .flatMap(List::stream) .collect(Collectors.toSet()); .map(Pattern::compile) .map(pattern -> allQueries.stream().filter(query -> pattern.matcher(query.getName()).matches())) .flatMap(identity()) .collect(Collectors.toSet()); driverOptions.debug, driverOptions.maxFailures, Optional.ofNullable(driverOptions.socksProxy))) { for (Suite suite : suites) { benchmarkDriver.run(suite);
return ImmutableMap.of(); CacheKey anyKey = stream(keys).findAny().get(); if (stream(keys).anyMatch(k -> !k.getSchema().equals(anyKey.getSchema()) || !k.getTable().equals(anyKey.getTable()) || !k.getFamily().equals(anyKey.getFamily()) || !k.getQualifier().equals(anyKey.getQualifier()))) { throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, "loadAll called with a non-homogeneous collection of cache keys"); Map<Range, CacheKey> rangeToKey = stream(keys).collect(Collectors.toMap(CacheKey::getRange, Function.identity())); LOG.debug("rangeToKey size is %s", rangeToKey.size()); scanner.setRanges(stream(keys).map(CacheKey::getRange).collect(Collectors.toList())); scanner.fetchColumn(columnFamily, CARDINALITY_CQ_AS_TEXT);
ImmutableMap.Builder<StageId, StageLinkage> stageLinkages) ImmutableList.Builder<SqlStageExecution> stages = ImmutableList.builder(); schedulerStats); stages.add(stage); bucketToPartition = Optional.of(new int[1]); bucketToPartition = Optional.of(new int[1]); NodePartitionMap nodePartitionMap = partitioningCache.apply(plan.getFragment().getPartitioning()); if (groupedExecutionForStage) { checkState(connectorPartitionHandles.size() == nodePartitionMap.getBucketToPartition().length); NodePartitionMap nodePartitionMap = partitioningCache.apply(plan.getFragment().getPartitioning()); List<Node> partitionToNode = nodePartitionMap.getPartitionToNode(); stageSchedulers, stageLinkages); stages.addAll(subTree); .map(RemoteTask::getTaskStatus) .collect(toList()); return stages.build();
public static Optional<SortExpressionContext> extractSortExpression(Set<Symbol> buildSymbols, Expression filter) { List<Expression> filterConjuncts = ExpressionUtils.extractConjuncts(filter); SortExpressionVisitor visitor = new SortExpressionVisitor(buildSymbols); List<SortExpressionContext> sortExpressionCandidates = filterConjuncts.stream() .filter(DeterminismEvaluator::isDeterministic) .map(visitor::process) .filter(Optional::isPresent) .map(Optional::get) .collect(toMap(SortExpressionContext::getSortExpression, identity(), SortExpressionExtractor::merge)) .values() .stream() .collect(toImmutableList()); // For now heuristically pick sort expression which has most search expressions assigned to it. // TODO: make it cost based decision based on symbol statistics return sortExpressionCandidates.stream() .sorted(comparing(context -> -1 * context.getSearchExpressions().size())) .findFirst(); }
@Override public SearchResponse decorate(SearchResponse searchResponse, Optional<String> streamId) { try { final List<SearchResponseDecorator> searchResponseDecorators = streamId.isPresent() ? decoratorResolver.searchResponseDecoratorsForStream(streamId.get()) : decoratorResolver.searchResponseDecoratorsForGlobal(); final Optional<SearchResponseDecorator> metaDecorator = searchResponseDecorators.stream() .reduce((f, g) -> (v) -> g.apply(f.apply(v))); if (metaDecorator.isPresent()) { final Map<String, ResultMessageSummary> originalMessages = searchResponse.messages() .stream() .collect(Collectors.toMap(this::getMessageKey, Function.identity())); final SearchResponse newSearchResponse = metaDecorator.get().apply(searchResponse); final Set<String> newFields = extractFields(newSearchResponse.messages()); .map(resultMessage -> { final ResultMessageSummary originalMessage = originalMessages.get(getMessageKey(resultMessage)); if (originalMessage != null) { .collect(Collectors.toList());
@Override public Optional<Handler> buildHandler(Class<?> sqlObjectType, Method method) { if (!method.isBridge()) { return Optional.empty(); } return Stream.of(sqlObjectType.getMethods()) .filter(candidate -> !candidate.isBridge() && Objects.equals(candidate.getName(), method.getName()) && candidate.getParameterCount() == method.getParameterCount()) .filter(candidate -> { Class<?>[] candidateParamTypes = candidate.getParameterTypes(); Class<?>[] methodParamTypes = method.getParameterTypes(); return IntStream.range(0, method.getParameterCount()) .allMatch(i -> methodParamTypes[i].isAssignableFrom(candidateParamTypes[i])); }) .<Handler>map(m -> { final MethodHandle mh = unreflect(sqlObjectType, m); return (target, args, handle) -> Unchecked.<Object[], Object>function(mh.bindTo(target)::invokeWithArguments).apply(args); }) .findFirst(); }
.map(function -> (session, addresses, pages) -> new StandardJoinFilterFunction(function, addresses, pages)); LocalExchangeSinkOperatorFactory sinkOperatorFactory = new LocalExchangeSinkOperatorFactory(localExchangeFactory, 1, new PlanNodeId("sink"), localExchangeSinkFactoryId, Function.identity()); Driver sourceDriver = Driver.createDriver(collectDriverContext, valuesOperatorFactory.createOperator(collectDriverContext), buildPages.getTypes(), rangeList(buildPages.getTypes().size()).stream() .map(buildPages.getTypes()::get) .collect(toImmutableList()), hashChannels.stream() .map(buildPages.getTypes()::get) .collect(toImmutableList()), partitionCount, requireNonNull(ImmutableMap.of(), "layout is null"), false)); hashChannels, buildPages.getHashChannel() .map(OptionalInt::of).orElse(OptionalInt.empty()), filterFunctionFactory, Optional.empty(), ImmutableList.of(), 100, new PagesIndex.TestingFactory(false),
private static Map<String, Method> load(Class<?> type) { if (Modifier.isPublic(type.getModifiers())) { return Arrays.stream(type.getMethods()) .filter(m -> m.getParameterCount() == 0) .collect(Collectors.toMap(Method::getName, Function.identity(), ObjectMethodArguments::bridgeMethodMerge)); } else { final HashMap<String, Method> methodMap = new HashMap<>(); Optional.ofNullable(type.getSuperclass()).ifPresent(superclass -> methodMap.putAll(load(superclass))); Arrays.stream(type.getInterfaces()).forEach(interfaceClass -> methodMap.putAll(load(interfaceClass))); return methodMap; } }
protected <RemoteInterfaceType, FinalResponseType, RemoteCallResponseType> Map<String, Optional<FinalResponseType>> getForAllNodes(Function<RemoteInterfaceType, Call<RemoteCallResponseType>> fn, Function<String, Optional<RemoteInterfaceType>> interfaceProvider, Function<RemoteCallResponseType, FinalResponseType> transformer) { final Map<String, Future<Optional<FinalResponseType>>> futures = this.nodeService.allActive().keySet().stream() .collect(Collectors.toMap(Function.identity(), node -> interfaceProvider.apply(node) .map(r -> executor.submit(() -> { final Call<RemoteCallResponseType> call = fn.apply(r); try { final Response<RemoteCallResponseType> response = call.execute(); if (response.isSuccessful()) { return Optional.of(transformer.apply(response.body())); } else { LOG.warn("Unable to call {} on node <{}>, result: {}", call.request().url(), node, response.message()); return Optional.<FinalResponseType>empty(); .entrySet() .stream() .collect(Collectors.toMap(Map.Entry::getKey, entry -> { try { return entry.getValue().get();
public static Optional<HiveBucketHandle> getHiveBucketHandle(Table table) { Optional<HiveBucketProperty> hiveBucketProperty = table.getStorage().getBucketProperty(); if (!hiveBucketProperty.isPresent()) { return Optional.empty(); } Map<String, HiveColumnHandle> map = getRegularColumnHandles(table).stream() .collect(Collectors.toMap(HiveColumnHandle::getName, identity())); ImmutableList.Builder<HiveColumnHandle> bucketColumns = ImmutableList.builder(); for (String bucketColumnName : hiveBucketProperty.get().getBucketedBy()) { HiveColumnHandle bucketColumnHandle = map.get(bucketColumnName); if (bucketColumnHandle == null) { throw new PrestoException( HIVE_INVALID_METADATA, format("Table '%s.%s' is bucketed on non-existent column '%s'", table.getDatabaseName(), table.getTableName(), bucketColumnName)); } bucketColumns.add(bucketColumnHandle); } int bucketCount = hiveBucketProperty.get().getBucketCount(); return Optional.of(new HiveBucketHandle(bucketColumns.build(), bucketCount, bucketCount)); }
.addAll(baseExceptionHandlers).add(defaultExceptionHandler).build(); final List<RequestConverterFunction> req = getAnnotatedInstances(method, clazz, RequestConverter.class, RequestConverterFunction.class) resolvers = ImmutableList.of(); final Set<String> requiredParamNames = resolvers.stream() .filter(AnnotatedValueResolver::isPathVariable) .map(AnnotatedValueResolver::httpElementName) .collect(Collectors.toSet()); .map(code -> { final int statusCode = code.value(); checkArgument(statusCode >= 0, ? extends Service<HttpRequest, HttpResponse>> initialDecorator; if (methods.contains(HttpMethod.OPTIONS)) { initialDecorator = Function.identity(); } else { initialDecorator = delegate -> new SimpleDecoratingService<HttpRequest, HttpResponse>(delegate) {
VirtualHost decorate(@Nullable Function<Service<HttpRequest, HttpResponse>, Service<HttpRequest, HttpResponse>> decorator) { if (decorator == null) { return this; } final List<ServiceConfig> services = this.services.stream().map(cfg -> { final PathMapping pathMapping = cfg.pathMapping(); final Service<HttpRequest, HttpResponse> service = decorator.apply(cfg.service()); final String loggerName = cfg.loggerName().orElse(null); return new ServiceConfig(pathMapping, service, loggerName); }).collect(Collectors.toList()); return new VirtualHost(defaultHostname(), hostnamePattern(), sslContext(), services, producibleMediaTypes()); }