use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.
the class ConcourseServer method findKeyOperatorValuesTimeOrder.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Set<Long> findKeyOperatorValuesTimeOrder(String key, Operator operator, List<TObject> values, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
TObject[] tValues = values.toArray(Array.containing());
AtomicSupport store = getStore(transaction, environment);
Function<Store, SortableSet<Set<TObject>>> function = $store -> {
SortableSet<Set<TObject>> $records = SortableSet.of(Stores.find($store, timestamp, key, operator, tValues));
// NOTE: The #timestamp is not considered when sorting because it is
// a component of criteria evaluation and no data is being selected.
$records.sort(Sorting.byValues(Orders.from(order), store));
return $records;
};
SortableSet<Set<TObject>> records = null;
boolean isAtomic = order != NO_ORDER;
while (records == null) {
try {
if (isAtomic) {
records = AtomicOperations.<SortableSet<Set<TObject>>>supplyWithRetry(store, atomic -> function.apply(atomic));
} else {
records = function.apply(store);
}
} catch (InsufficientAtomicityException e) {
isAtomic = true;
}
}
return records;
}
use of com.cinchapi.concourse.thrift.Operator 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.Operator in project concourse by cinchapi.
the class Stores method find.
/**
* Find the records that contain values that are stored for {@code key} and
* satisfy {@code operator} in relation to the specified {@code values} at
* {@code timestamp}.
* <p>
* If the {@code key} is primitive, the store lookup is usually a simple
* {@link Store#find(String, Operator, TObject[]) find}. However, if the key
* is a navigation key, this method will process it by
* {@link #browse(Store, String) browsing} the destination values and
* checking the operator validity of each if and only if the {@code store}
* is an {@link AtomicOperation} or {@link AtomicSupport supports} starting
* one.
* </p>
*
* @param store
* @param timestamp
* @param key
* @param operator
* @param values
* @return the records that satisfy the query
*/
public static Set<Long> find(Store store, long timestamp, String key, Operator operator, TObject... values) {
for (int i = 0; i < values.length; ++i) {
TObject value = values[i];
if (value.getType() == Type.FUNCTION) {
Function function = (Function) Convert.thriftToJava(value);
TemporalFunction func = (TemporalFunction) function;
String method = Calculations.alias(function.operation());
ArrayBuilder<Object> args = ArrayBuilder.builder();
method += "Key";
args.add(function.key());
if (function instanceof KeyRecordsFunction || function instanceof KeyConditionFunction) {
method += "Records";
Collection<Long> records = function instanceof KeyRecordsFunction ? ((KeyRecordsFunction) function).source() : Finder.instance().visit(((KeyConditionFunction) function).source(), store);
args.add(records);
} else if (!(function instanceof IndexFunction)) {
throw new IllegalStateException("Invalid function value");
}
method += "Atomic";
args.add(func.timestamp());
args.add(store);
values[i] = Convert.javaToThrift(Reflection.callStatic(Operations.class, method, args.build()));
}
}
if (Keys.isNavigationKey(key)) {
Map<TObject, Set<Long>> index = timestamp == Time.NONE ? browse(store, key) : browse(store, key, timestamp);
Set<Long> records = index.entrySet().stream().filter(e -> e.getKey().is(operator, values)).map(e -> e.getValue()).flatMap(Set::stream).collect(Collectors.toCollection(LinkedHashSet::new));
return records;
} else if (Keys.isFunctionKey(key)) {
Set<Long> records = Sets.newLinkedHashSet();
for (long record : store.getAllRecords()) {
Set<TObject> aggregate = select(store, key, record, timestamp);
for (TObject tobject : aggregate) {
if (tobject.is(operator, values)) {
records.add(record);
break;
}
}
}
return records;
} else {
return timestamp == Time.NONE ? store.find(key, operator, values) : store.find(timestamp, key, operator, values);
}
}
use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.
the class AtomicOperation method explore.
@Override
public Map<Long, Set<TObject>> explore(String key, Aliases aliases) {
checkState();
Operator operator = aliases.operator();
TObject[] values = aliases.values();
Text key0 = Text.wrapCached(key);
RangeToken rangeToken = RangeToken.forReading(key0, operator, Transformers.transformArray(values, Value::wrap, Value.class));
source.addVersionChangeListener(rangeToken, this);
Iterable<Range<Value>> ranges = RangeTokens.convertToRange(rangeToken);
for (Range<Value> range : ranges) {
rangeReads2Lock.put(key0, range);
}
return super.explore(key, aliases);
}
use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.
the class ConcourseCompilerTest method testGroupSingle.
@Test
public void testGroupSingle() {
String key = TestData.getString();
Operator operator = Operator.EQUALS;
Object value = TestData.getObject();
Criteria criteria = Criteria.where().key(key).operator(operator).value(value).build();
List<Symbol> symbols = Parsing.groupExpressions(criteria.symbols());
ExpressionSymbol exp = (ExpressionSymbol) symbols.get(0);
Assert.assertEquals(1, symbols.size());
Assert.assertEquals(exp.raw().key(), key);
Assert.assertEquals(exp.raw().operator(), operator);
Assert.assertEquals(exp.values().get(0).value(), value);
}
Aggregations