Search in sources :

Example 1 with Navigation

use of com.cinchapi.concourse.util.Navigation in project concourse by cinchapi.

the class Operations method browseNavigationKeyOptionalAtomic.

/**
 * Perform "browse" functionality on a navigation key.
 *
 * @param key
 * @param timestamp
 * @param store
 * @return a mapping from each possible destination value for a given
 *         navigation {@code key} to the records where the navigation could
 *         begin to retrieve the value by selecting the navigation
 *         {@code key}
 */
public static Map<TObject, Set<Long>> browseNavigationKeyOptionalAtomic(String key, long timestamp, Store store) {
    String[] toks = key.split("\\.");
    if (toks.length == 1) {
        return timestamp == Time.NONE ? store.browse(key) : store.browse(key, timestamp);
    } else {
        String start = toks[0];
        StringBuilder $key = new StringBuilder();
        for (int i = 1; i < toks.length - 1; ++i) {
            $key.append(toks[i]).append('.');
        }
        $key.append(toks[toks.length - 1]);
        Map<TObject, Set<Long>> root = timestamp == Time.NONE ? store.browse(start) : store.browse(start, timestamp);
        Map<TObject, Set<Long>> index = Maps.newLinkedHashMap();
        root.entrySet().stream().filter(e -> e.getKey().getType() == Type.LINK).forEach(entry -> {
            Link link = (Link) Convert.thriftToJava(entry.getKey());
            Set<Long> nodes = entry.getValue();
            for (long node : nodes) {
                Set<TObject> values = traverseKeyRecordOptionalAtomic($key.toString(), link.longValue(), timestamp, store);
                for (TObject value : values) {
                    index.computeIfAbsent(value, ignore -> Sets.newLinkedHashSet()).add(node);
                }
            }
        });
        return index;
    }
}
Also used : Navigation(com.cinchapi.concourse.util.Navigation) Page(com.cinchapi.concourse.lang.paginate.Page) Numbers(com.cinchapi.concourse.util.Numbers) AtomicStateException(com.cinchapi.concourse.server.storage.AtomicStateException) Constants(com.cinchapi.concourse.Constants) Paging(com.cinchapi.concourse.server.query.paginate.Paging) Calculations(com.cinchapi.concourse.server.calculate.Calculations) KeyRecordCalculation(com.cinchapi.concourse.server.calculate.KeyRecordCalculation) MultimapViews(com.cinchapi.concourse.util.MultimapViews) Convert(com.cinchapi.concourse.util.Convert) Map(java.util.Map) Link(com.cinchapi.concourse.Link) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) ResolvableLink(com.cinchapi.concourse.util.Convert.ResolvableLink) Set(java.util.Set) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) AtomicOperation(com.cinchapi.concourse.server.storage.AtomicOperation) List(java.util.List) KeyCalculation(com.cinchapi.concourse.server.calculate.KeyCalculation) JsonArray(com.google.gson.JsonArray) Entry(java.util.Map.Entry) DeferredWrite(com.cinchapi.concourse.server.ConcourseServer.DeferredWrite) Type(com.cinchapi.concourse.thrift.Type) StringSplitter(com.cinchapi.common.base.StringSplitter) Sortable(com.cinchapi.concourse.data.sort.Sortable) Iterables(com.google.common.collect.Iterables) NoOrder(com.cinchapi.concourse.lang.sort.NoOrder) Sorting(com.cinchapi.concourse.server.query.sort.Sorting) Store(com.cinchapi.concourse.server.storage.Store) Multimap(com.google.common.collect.Multimap) Supplier(java.util.function.Supplier) ConcourseCompiler(com.cinchapi.concourse.lang.ConcourseCompiler) NoPage(com.cinchapi.concourse.lang.paginate.NoPage) LinkedHashMap(java.util.LinkedHashMap) JsonElement(com.google.gson.JsonElement) ParseException(com.cinchapi.concourse.thrift.ParseException) Lists(com.google.common.collect.Lists) TObject(com.cinchapi.concourse.thrift.TObject) GlobalState(com.cinchapi.concourse.server.GlobalState) TMaps(com.cinchapi.concourse.util.TMaps) NoSuchElementException(java.util.NoSuchElementException) Time(com.cinchapi.concourse.time.Time) Order(com.cinchapi.concourse.lang.sort.Order) Maps(com.google.common.collect.Maps) Finder(com.cinchapi.concourse.server.query.Finder) DataServices(com.cinchapi.concourse.util.DataServices) TObject(com.cinchapi.concourse.thrift.TObject) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Link(com.cinchapi.concourse.Link) ResolvableLink(com.cinchapi.concourse.util.Convert.ResolvableLink)

Aggregations

AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)1 StringSplitter (com.cinchapi.common.base.StringSplitter)1 Constants (com.cinchapi.concourse.Constants)1 Link (com.cinchapi.concourse.Link)1 Sortable (com.cinchapi.concourse.data.sort.Sortable)1 ConcourseCompiler (com.cinchapi.concourse.lang.ConcourseCompiler)1 NoPage (com.cinchapi.concourse.lang.paginate.NoPage)1 Page (com.cinchapi.concourse.lang.paginate.Page)1 NoOrder (com.cinchapi.concourse.lang.sort.NoOrder)1 Order (com.cinchapi.concourse.lang.sort.Order)1 DeferredWrite (com.cinchapi.concourse.server.ConcourseServer.DeferredWrite)1 GlobalState (com.cinchapi.concourse.server.GlobalState)1 Calculations (com.cinchapi.concourse.server.calculate.Calculations)1 KeyCalculation (com.cinchapi.concourse.server.calculate.KeyCalculation)1 KeyRecordCalculation (com.cinchapi.concourse.server.calculate.KeyRecordCalculation)1 Finder (com.cinchapi.concourse.server.query.Finder)1 Paging (com.cinchapi.concourse.server.query.paginate.Paging)1 Sorting (com.cinchapi.concourse.server.query.sort.Sorting)1 AtomicOperation (com.cinchapi.concourse.server.storage.AtomicOperation)1 AtomicStateException (com.cinchapi.concourse.server.storage.AtomicStateException)1