use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class ConcourseServer method selectKeyCclOrderPage.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Set<TObject>> selectKeyCclOrderPage(String key, String ccl, TOrder order, TPage page, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(ccl);
AtomicSupport store = getStore(transaction, environment);
Supplier<SortableColumn<Set<TObject>>> supplier = () -> SortableColumn.multiValued(key, new LinkedHashMap<>());
return AtomicOperations.supplyWithRetry(store, atomic -> Operations.selectKeyAstAtomic(atomic, key, ast, Orders.from(order), Pages.from(page), supplier));
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class ConcourseServer method sumKeyCriteria.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public TObject sumKeyCriteria(String key, TCriteria criteria, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
return AtomicOperations.supplyWithRetry(store, (atomic) -> {
Set<Long> records = ast.accept(Finder.instance(), atomic);
Number sum = Operations.sumKeyRecordsAtomic(key, records, Time.NONE, atomic);
return Convert.javaToThrift(sum);
});
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class ConcourseServer method minKeyCcl.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public TObject minKeyCcl(String key, String ccl, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(ccl);
AtomicSupport store = getStore(transaction, environment);
return AtomicOperations.supplyWithRetry(store, (atomic) -> {
Set<Long> records = ast.accept(Finder.instance(), atomic);
Number min = Operations.minKeyRecordsAtomic(key, records, Time.NONE, atomic);
return Convert.javaToThrift(min);
});
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class Operations method insertDeferredAtomic.
/**
* Atomically insert a list of {@link DeferredWrite deferred writes}. This
* method should only be called after all necessary calls to
* {@link #insertAtomic(Multimap, long, AtomicOperation, List)} have been
* made.
*
* @param parser
* @param deferred
* @param atomic
* @return {@code true} if all the writes are successful
*/
public static boolean insertDeferredAtomic(List<DeferredWrite> deferred, AtomicOperation atomic) {
// have already been checked
for (DeferredWrite write : deferred) {
if (write.getValue() instanceof ResolvableLink) {
ResolvableLink rlink = (ResolvableLink) write.getValue();
AbstractSyntaxTree ast = ConcourseCompiler.get().parse(rlink.getCcl());
Set<Long> targets = ast.accept(Finder.instance(), atomic);
for (long target : targets) {
if (target == write.getRecord()) {
// accidentally creates self links.
continue;
}
TObject link = Convert.javaToThrift(Link.to(target));
if (!atomic.add(write.getKey(), link, write.getRecord())) {
return false;
}
}
} else if (!atomic.add(write.getKey(), Convert.javaToThrift(write.getValue()), write.getRecord())) {
return false;
}
}
return true;
}
use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.
the class FinderTest method testBasicExpression.
@Test
public void testBasicExpression() {
Queue store = new Queue(16);
store.insert(Write.add("name", Convert.javaToThrift("jeff"), 1));
store.insert(Write.add("company", Convert.javaToThrift("Cinchapi"), 1));
store.insert(Write.add("age", Convert.javaToThrift(100), 1));
store.insert(Write.add("name", Convert.javaToThrift("jeff"), 2));
store.insert(Write.add("company", Convert.javaToThrift("Blavity"), 2));
store.insert(Write.add("age", Convert.javaToThrift(100), 2));
store.insert(Write.add("name", Convert.javaToThrift("ashleah"), 3));
store.insert(Write.add("company", Convert.javaToThrift("ARMN Inc."), 3));
store.insert(Write.add("age", Convert.javaToThrift(50), 3));
String ccl = "name = jeff";
AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
Finder visitor = Finder.instance();
Set<Long> result = ast.accept(visitor, store);
Assert.assertEquals(Sets.newHashSet(1L, 2L), result);
}
Aggregations