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()); }
/** * Transform the given request into a request used for a nested route. For instance, * a path-based predicate can return a {@code ServerRequest} with a the path remaining * after a match. * <p>The default implementation returns an {@code Optional} wrapping the given path if * {@link #test(ServerRequest)} evaluates to {@code true}; or {@link Optional#empty()} * if it evaluates to {@code false}. * @param request the request to be nested * @return the nested request * @see RouterFunctions#nest(RequestPredicate, RouterFunction) */ default Optional<ServerRequest> nest(ServerRequest request) { return (test(request) ? Optional.of(request) : Optional.empty()); }
public Optional<HashComputation> translate(Function<Symbol, Optional<Symbol>> translator) { ImmutableList.Builder<Symbol> newSymbols = ImmutableList.builder(); for (Symbol field : fields) { Optional<Symbol> newSymbol = translator.apply(field); if (!newSymbol.isPresent()) { return Optional.empty(); } newSymbols.add(newSymbol.get()); } return computeHash(newSymbols.build()); }
private static Function<HiveColumnHandle, ColumnMetadata> columnMetadataGetter(Table table, TypeManager typeManager) table.getPartitionColumns().stream().map(Column::getName).forEach(columnNames::add); table.getDataColumns().stream().map(Column::getName).forEach(columnNames::add); List<String> allColumnNames = columnNames.build(); if (allColumnNames.size() > Sets.newHashSet(allColumnNames).size()) { throw new PrestoException(HIVE_INVALID_METADATA, format("Hive metadata for table %s is invalid: Table descriptor contains duplicate columns", table.getTableName())); ImmutableMap.Builder<String, Optional<String>> builder = ImmutableMap.builder(); for (Column field : concat(tableColumns, table.getPartitionColumns())) { if (field.getComment().isPresent() && !field.getComment().get().equals("from deserializer")) { builder.put(field.getName(), field.getComment()); builder.put(field.getName(), Optional.empty()); builder.put(PATH_COLUMN_NAME, Optional.empty()); if (table.getStorage().getBucketProperty().isPresent()) { builder.put(BUCKET_COLUMN_NAME, Optional.empty()); handle.getName(), typeManager.getType(handle.getTypeSignature()), columnComment.get(handle.getName()).orElse(null), columnExtraInfo(handle.isPartitionKey()), handle.isHidden());
private <T> Optional<Set<String>> filterString(TupleDomain<T> constraint, T column) { if (constraint.isNone()) { return Optional.of(ImmutableSet.of()); } Domain domain = constraint.getDomains().get().get(column); if (domain == null) { return Optional.empty(); } if (domain.isSingleValue()) { return Optional.of(ImmutableSet.of(((Slice) domain.getSingleValue()).toStringUtf8())); } else if (domain.getValues() instanceof EquatableValueSet) { Collection<Object> values = ((EquatableValueSet) domain.getValues()).getValues(); return Optional.of(values.stream() .map(Slice.class::cast) .map(Slice::toStringUtf8) .collect(toImmutableSet())); } return Optional.empty(); }
Optional<ConfigValue<T>> resolveOutboundOpName(RequestConfigCacheKey cacheKeyd, Map<Optional<String>, Map<Optional<String>, Map<Optional<String>, ConfigValue<T>>>> map) { if (map != null) { Optional<String> outboundOpName = cacheKeyd.getOutboundOpName(); if (outboundOpName.isPresent()) { Optional<ConfigValue<T>> value = resolveInboundOp(cacheKeyd, map.get(outboundOpName)); if (value.isPresent()) { return value; } } return resolveInboundOp(cacheKeyd, map.get(Optional.empty())); } else { return Optional.empty(); } }
@Test public void testCreateTableAsSelectDifferentCatalog() throws Exception { handle.execute("CREATE TABLE \"my_test_table2\" (column1 BIGINT, column2 DOUBLE)"); SqlParser parser = new SqlParser(); Query query = new Query(CATALOG, SCHEMA, ImmutableList.of(), "CREATE TABLE public.my_test_table2 AS SELECT 1 column1, 2E0 column2", ImmutableList.of(), null, null, ImmutableMap.of()); QueryRewriter rewriter = new QueryRewriter(parser, URL, QualifiedName.of("other_catalog", "other_schema", "tmp_"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), 1, new Duration(10, SECONDS)); Query rewrittenQuery = rewriter.shadowQuery(query); assertEquals(rewrittenQuery.getPreQueries().size(), 1); CreateTableAsSelect createTableAs = (CreateTableAsSelect) parser.createStatement(rewrittenQuery.getPreQueries().get(0)); assertEquals(createTableAs.getName().getParts().size(), 3); assertEquals(createTableAs.getName().getPrefix().get(), QualifiedName.of("other_catalog", "other_schema")); assertTrue(createTableAs.getName().getSuffix().startsWith("tmp_")); assertFalse(createTableAs.getName().getSuffix().contains("my_test_table")); }
@Override public Optional<ConfigMetadataNode> visitObjectMetadata(ConfigObjectMetadata metadata) { return metadata.getAllSubConfigs() .map(c -> c.accept(OBJECT_CONFIG_RESOLVER)) .filter(Optional::isPresent) .map(c -> c.get().getProperties()) .flatMap(Collection::stream) .filter(c -> c.getName().equals(split[0])) .map(c -> findConfig(c, split[1])) .findFirst().orElse(Optional.empty()); }
private Optional<Symbol> getAssignedSymbol(Map<Symbol, ColumnHandle> assignments, ColumnHandle columnHandle) { Optional<Symbol> result = Optional.empty(); for (Map.Entry<Symbol, ColumnHandle> entry : assignments.entrySet()) { if (entry.getValue().equals(columnHandle)) { checkState(!result.isPresent(), "Multiple ColumnHandles found for %s:%s in table scan assignments", tableName, columnName); result = Optional.of(entry.getKey()); } } return result; }
@Test @SuppressWarnings("unchecked") public void attributesAsOptionalEmpty() throws Exception { request.addParameter("name", "Patty"); mavContainer.getModel().put("testBean1", Optional.empty()); mavContainer.getModel().put("testBean2", Optional.empty()); mavContainer.getModel().put("testBean3", Optional.empty()); assertNull(processor.resolveArgument( testBeanModelAttr, mavContainer, webRequest, binderFactory)); assertNull(processor.resolveArgument( testBeanWithoutStringConstructorModelAttr, mavContainer, webRequest, binderFactory)); Optional<TestBean> testBean =(Optional<TestBean>) processor.resolveArgument( testBeanWithOptionalModelAttr, mavContainer, webRequest, binderFactory); assertFalse(testBean.isPresent()); }
private static Optional<InetAddress> toValidAddress(InetAddress address) { if (address instanceof Inet6Address) { Inet6Address v6Address = (Inet6Address) address; if (isValidV6Address(v6Address)) { return Optional.ofNullable(normalizeV6Address(v6Address)); } } if (isValidV4Address(address)) { return Optional.of(address); } return Optional.empty(); }
@Test @SuppressWarnings("rawtypes") public void resolveOptionalParamList() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, List.class); Object result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertEquals(Optional.empty(), result); request.addParameter("name", "123", "456"); result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertEquals(Optional.class, result.getClass()); assertEquals(Arrays.asList("123", "456"), ((Optional) result).get()); }
Optional<ConfigValue<T>> resolveInboundOp(RequestConfigCacheKey cacheKeyd, Map<Optional<String>, Map<Optional<String>, ConfigValue<T>>> map) { if (map != null) { Optional<String> inboundOp = cacheKeyd.getInboundOp(); if (inboundOp.isPresent()) { Optional<ConfigValue<T>> value = resolveInboundOpName(cacheKeyd, map.get(inboundOp)); if (value.isPresent()) { return value; } } return resolveInboundOpName(cacheKeyd, map.get(Optional.empty())); } else { return Optional.empty(); } }
/** * Can be used to collect objects from the Iterable. Is a terminating operation. * * @return an option of the first object of the Iterable */ @Override public final Optional<E> first() { Iterator<E> resultIterator = first(1).iterator(); return resultIterator.hasNext() ? Optional.of(resultIterator.next()) : Optional.empty(); }
@Test public void resolveOptionalParamValue() { ServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/")); MethodParameter param = this.testMethod.arg(forClassWithGenerics(Optional.class, Integer.class)); Object result = resolve(param, exchange); assertEquals(Optional.empty(), result); exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path?name=123")); result = resolve(param, exchange); assertEquals(Optional.class, result.getClass()); Optional<?> value = (Optional<?>) result; assertTrue(value.isPresent()); assertEquals(123, value.get()); }
@Test public void testNoMatch() { ResourceGroupIdTemplate template = new ResourceGroupIdTemplate("test.pipeline.${pipeline}.${USER}"); Pattern sourcePattern = Pattern.compile("scheduler.important.(?<pipeline>[^\\[]*).*"); StaticSelector selector = new StaticSelector(Optional.empty(), Optional.of(sourcePattern), Optional.empty(), Optional.empty(), Optional.empty(), template); SelectionCriteria context = new SelectionCriteria(true, "user", Optional.of("scheduler.testpipeline[5]"), ImmutableSet.of(), EMPTY_RESOURCE_ESTIMATES, Optional.empty()); assertFalse(selector.match(context).isPresent()); }
@Test @SuppressWarnings("rawtypes") public void missingOptionalParamValue() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class); Object result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertEquals(Optional.empty(), result); result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertEquals(Optional.class, result.getClass()); assertFalse(((Optional) result).isPresent()); }
private static Optional<InetAddress> toValidAddress(InetAddress address) { if (address instanceof Inet6Address) { Inet6Address v6Address = (Inet6Address) address; if (isValidV6Address(v6Address)) { return Optional.ofNullable(normalizeV6Address(v6Address)); } } if (isValidV4Address(address)) { return Optional.of(address); } return Optional.empty(); }
@Test @SuppressWarnings("rawtypes") public void resolveOptionalParamValue() throws Exception { ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer(); initializer.setConversionService(new DefaultConversionService()); WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer); MethodParameter param = this.testMethod.annotPresent(RequestParam.class).arg(Optional.class, Integer.class); Object result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertEquals(Optional.empty(), result); request.addParameter("name", "123"); result = resolver.resolveArgument(param, null, webRequest, binderFactory); assertEquals(Optional.class, result.getClass()); assertEquals(123, ((Optional) result).get()); }