Search in sources :

Example 1 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method explore.

@Override
public Map<Long, Set<TObject>> explore(String key, Aliases aliases, long timestamp) {
    Text L = Text.wrapCached(key);
    IndexRecord index = getIndexRecord(L);
    Value[] Ks = Transformers.transformArray(aliases.values(), Value::wrap, Value.class);
    Map<Identifier, Set<Value>> map = index.findAndGet(timestamp, aliases.operator(), Ks);
    return Transformers.transformTreeMapSet(map, Identifier::longValue, Value::getTObject, Long::compare);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 2 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class IndexRecord method findAndGet.

/**
 * Explore this record and return a mapping from PrimaryKey to the Values
 * that cause the corresponding records to satisfy {@code operator} in
 * relation to the specified {@code values} (and at the specified
 * {@code timestamp} if {@code historical} is {@code true}).
 *
 * @param historical - if {@code true} query the history, otherwise query
 *            the current state
 * @param timestamp - this value is ignored if {@code historical} is
 *            {@code false}, otherwise this value is the historical
 *            timestamp at which to query the field
 * @param operator
 * @param values
 * @return the relevant data that causes the matching records to satisfy the
 *         criteria
 */
private Map<Identifier, Set<Value>> findAndGet(boolean historical, long timestamp, Operator operator, Value... values) {
    /* Authorized */
    // CON-667: Value ordering for Strings is such that uppercase characters
    // are "smaller" than lowercase ones. Concourse uses case insensitive
    // matching, so we sometimes must modify the input #values in order to
    // ensure that all equal forms of a value are captured or excluded as
    // necessary.
    read.lock();
    try {
        Map<Identifier, Set<Value>> data = Maps.newHashMap();
        Value value = values[0];
        if (operator == Operator.EQUALS) {
            for (Entry<Value, Set<Identifier>> entry : (historical ? coalesce(value, timestamp) : coalesce(value)).entrySet()) {
                Value stored = entry.getKey();
                for (Identifier record : entry.getValue()) {
                    MultimapViews.put(data, record, stored);
                }
            }
        } else if (operator == Operator.NOT_EQUALS) {
            for (Value stored : historical ? history.keySet() : present.keySet()) {
                if (!value.equalsIgnoreCase(stored)) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.GREATER_THAN) {
            // CON-667
            value = value.toLowerCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).tailSet(value, false)) {
                if (!historical || stored.compareToIgnoreCase(value) > 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.GREATER_THAN_OR_EQUALS) {
            // CON-667
            value = value.toUpperCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).tailSet(value, true)) {
                if (!historical || stored.compareToIgnoreCase(value) >= 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.LESS_THAN) {
            // CON-667
            value = value.toUpperCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).headSet(value, false)) {
                if (!historical || stored.compareToIgnoreCase(value) < 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.LESS_THAN_OR_EQUALS) {
            // CON-667
            value = value.toLowerCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).headSet(value, true)) {
                if (!historical || stored.compareToIgnoreCase(value) <= 0) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.BETWEEN) {
            Preconditions.checkArgument(values.length > 1);
            Value value2 = values[1];
            // CON-667
            value = value.toUpperCase();
            // CON-667
            value2 = value2.toUpperCase();
            for (Value stored : historical ? history.keySet() : ((NavigableSet<Value>) present.keySet()).subSet(value, true, value2, false)) {
                if (!historical || (stored.compareTo(value) >= 0 && stored.compareTo(value2) < 0)) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.REGEX) {
            Pattern p = Pattern.compile(value.getObject().toString());
            for (Value stored : historical ? history.keySet() : present.keySet()) {
                Matcher m = p.matcher(stored.getObject().toString());
                if (m.matches()) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else if (operator == Operator.NOT_REGEX) {
            Pattern p = Pattern.compile(value.getObject().toString());
            for (Value stored : historical ? history.keySet() : present.keySet()) {
                Matcher m = p.matcher(stored.getObject().toString());
                if (!m.matches()) {
                    for (Identifier record : historical ? get(stored, timestamp) : get(stored)) {
                        MultimapViews.put(data, record, stored);
                    }
                }
            }
        } else {
            throw new UnsupportedOperationException();
        }
        return data;
    } finally {
        read.unlock();
    }
}
Also used : Pattern(java.util.regex.Pattern) NavigableSet(java.util.NavigableSet) Identifier(com.cinchapi.concourse.server.model.Identifier) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LazyTransformSet(com.cinchapi.common.collect.lazy.LazyTransformSet) Matcher(java.util.regex.Matcher) Value(com.cinchapi.concourse.server.model.Value)

Example 3 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method contains.

@Override
public boolean contains(long record) {
    Identifier L = Identifier.of(record);
    TableRecord table = getTableRecord(L);
    return !table.isEmpty();
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier)

Example 4 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method verify.

@Override
public boolean verify(Write write, long timestamp) {
    Identifier L = write.getRecord();
    Text K = write.getKey();
    Value V = write.getValue();
    TableRecord table = getTableRecord(L, K);
    return table.contains(K, V, timestamp);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Example 5 with Identifier

use of com.cinchapi.concourse.server.model.Identifier in project concourse by cinchapi.

the class Database method gather.

@Override
public Set<TObject> gather(String key, long record, long timestamp) {
    Text L = Text.wrapCached(key);
    Identifier V = Identifier.of(record);
    IndexRecord index = getIndexRecord(L);
    Set<Value> Ks = index.gather(V, timestamp);
    return Transformers.transformSet(Ks, Value::getTObject);
}
Also used : Identifier(com.cinchapi.concourse.server.model.Identifier) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text)

Aggregations

Identifier (com.cinchapi.concourse.server.model.Identifier)40 Text (com.cinchapi.concourse.server.model.Text)28 Value (com.cinchapi.concourse.server.model.Value)25 Test (org.junit.Test)18 Set (java.util.Set)13 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)9 LinkedHashSet (java.util.LinkedHashSet)7 ByteBuffer (java.nio.ByteBuffer)6 Path (java.nio.file.Path)6 Write (com.cinchapi.concourse.server.storage.temp.Write)4 List (java.util.List)4 LazyTransformSet (com.cinchapi.common.collect.lazy.LazyTransformSet)3 Position (com.cinchapi.concourse.server.model.Position)3 Action (com.cinchapi.concourse.server.storage.Action)3 Range (com.cinchapi.concourse.server.storage.db.kernel.Manifest.Range)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 NavigableSet (java.util.NavigableSet)3 CoalescableTreeMap (com.cinchapi.common.collect.CoalescableTreeMap)2 Composite (com.cinchapi.concourse.server.io.Composite)2 CorpusRecord (com.cinchapi.concourse.server.storage.db.CorpusRecord)2