/** Returns document counts for each partition. */ Map<Object, Integer> getDocumentCountByPartition(List<Document> documents) { return ImmutableMap.copyOf( Maps.transformValues( getDocumentsByPartition(documents).asMap(), new Function<Collection<Document>, Integer>() { public Integer apply(Collection<Document> documents) { return documents.size(); } })); }
public OptiqSchema(OptiqSchema parent, final Schema schema, String name) { this.parent = parent; this.schema = schema; this.name = name; assert (parent == null) == (this instanceof OptiqRootSchema); //noinspection unchecked this.compositeTableMap = CompositeMap.of( Maps.transformValues( tableMap, new com.google.common.base.Function<TableEntry, Table>() { public Table apply(TableEntry input) { return input.getTable(); } }), Maps.transformValues( Multimaps.filterEntries( functionMap, new Predicate<Map.Entry<String, FunctionEntry>>() { public boolean apply(Map.Entry<String, FunctionEntry> entry) { final Function function = entry.getValue().getFunction(); return function instanceof TableMacro && function.getParameters().isEmpty(); } }) .asMap(), new com.google.common.base.Function<Collection<FunctionEntry>, Table>() { public Table apply(Collection<FunctionEntry> input) { // At most one function with zero parameters. final TableMacro tableMacro = (TableMacro) input.iterator().next().getFunction(); return tableMacro.apply(ImmutableList.of()); } }), Compatible.INSTANCE.asMap( schema.getTableNames(), new com.google.common.base.Function<String, Table>() { public Table apply(String input) { return schema.getTable(input); } })); // TODO: include schema's functions in this map. this.compositeFunctionMap = Multimaps.transformValues( functionMap, new com.google.common.base.Function<FunctionEntry, Function>() { public Function apply(FunctionEntry input) { return input.getFunction(); } }); //noinspection unchecked this.compositeSubSchemaMap = CompositeMap.of( subSchemaMap, Compatible.INSTANCE.asMap( schema.getSubSchemaNames(), new com.google.common.base.Function<String, OptiqSchema>() { public OptiqSchema apply(String name) { return add(name, schema.getSubSchema(name)); } })); }