use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class ConcourseServer method selectKeysCclTimeOrder.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, Set<TObject>>> selectKeysCclTimeOrder(List<String> keys, String ccl, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
try {
AbstractSyntaxTree ast = compiler.parse(ccl);
AtomicSupport store = getStore(transaction, environment);
SortableTable<Set<TObject>> result = emptySortableResultDataset();
AtomicOperations.executeWithRetry(store, atomic -> Operations.selectKeysAstAtomic(keys, ast, timestamp, result, null, $result -> $result.sort(Sorting.byValues(Orders.from(order), atomic), timestamp), atomic));
return result;
} catch (Exception e) {
throw new ParseException(e.getMessage());
}
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class Buffer method chronologize.
@Override
public Map<Long, Set<TObject>> chronologize(String key, long record, long start, long end, Map<Long, Set<TObject>> context) {
Set<TObject> snapshot = Iterables.getLast(context.values(), Sets.<TObject>newLinkedHashSet());
if (snapshot.isEmpty() && !context.isEmpty()) {
// CON-474: Empty set is placed in the context if it was the last
// snapshot known to the database
context.remove(Time.NONE);
}
Iterator<Write> it = iterator(key, record, end - 1);
try {
while (it.hasNext()) {
Write write = it.next();
long timestamp = write.getVersion();
Text $key = write.getKey();
long $record = write.getRecord().longValue();
Action action = write.getType();
if ($key.toString().equals(key) && $record == record) {
snapshot = Sets.newLinkedHashSet(snapshot);
Value value = write.getValue();
if (action == Action.ADD) {
snapshot.add(value.getTObject());
} else if (action == Action.REMOVE) {
snapshot.remove(value.getTObject());
}
if (timestamp >= start) {
context.put(timestamp, snapshot);
}
}
}
return Maps.filterValues(context, emptySetFilter);
} finally {
Iterators.close(it);
}
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class Limbo method explore.
/**
* This is an implementation of the
* {@link #explore(long, String, Operator, TObject...)} routine that takes
* in a prior {@code context} and will return a mapping from
* records that match a criteria (expressed as {@code key} filtered by
* {@code operator} in relation to one or more {@code values}) to the set of
* values that caused that record to match the criteria {@code timestamp}.
*
* @param context
* @param timestamp
* @param key
* @param operator
* @param values
* @return the relevant data for the records that satisfy the find query
*/
public Map<Long, Set<TObject>> explore(Map<Long, Set<TObject>> context, String key, Aliases aliases, long timestamp) {
if (timestamp >= getOldestWriteTimestamp()) {
Operator operator = aliases.operator();
TObject[] values = aliases.values();
for (Iterator<Write> it = iterator(); it.hasNext(); ) {
Write write = it.next();
long record = write.getRecord().longValue();
if (write.getVersion() <= timestamp) {
if (write.getKey().toString().equals(key) && matches(write.getValue(), operator, values)) {
if (write.getType() == Action.ADD) {
MultimapViews.put(context, record, write.getValue().getTObject());
} else {
MultimapViews.remove(context, record, write.getValue().getTObject());
}
}
} else {
break;
}
}
}
return TMaps.asSortedMap(context);
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class Operations method minKeyAtomic.
/**
* Use the {@code store} to atomically compute the min across all the values
* stored for {@code key} across all records at {@code timestamp}.
*
* @param key
* @param timestamp
* @param store
* @return the max
*/
public static Number minKeyAtomic(String key, long timestamp, Store store) {
checkAtomicity(store, timestamp);
Map<TObject, Set<Long>> data = Stores.browse(store, key, timestamp);
TObject min = Iterables.getFirst(data.keySet(), null);
if (min != null) {
return (Number) Convert.thriftToJava(min);
} else {
return null;
}
}
use of com.cinchapi.concourse.thrift.TObject in project concourse by cinchapi.
the class Operations method avgKeyRecordAtomic.
/**
* Use the provided {@code store} to atomically add each of the values in
* {@code key}/{@code record} at {@code timestamp} to the running
* {@code sum}.
*
* @param key the field name
* @param record the record id
* @param timestamp the selection timestamp
* @param store the {@link Store} to use
* @return the new running sum
*/
public static Number avgKeyRecordAtomic(String key, long record, long timestamp, Store store) {
checkAtomicity(store, timestamp);
Set<TObject> values = Stores.select(store, key, record, timestamp);
Number sum = 0;
for (TObject value : values) {
Object object = Convert.thriftToJava(value);
Calculations.checkCalculatable(object);
Number number = (Number) object;
sum = Numbers.add(sum, number);
}
return values.isEmpty() ? null : Numbers.divide(sum, values.size());
}
Aggregations