Search in sources :

Example 86 with AbstractSyntaxTree

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));
}
Also used : ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) SortableColumn(com.cinchapi.concourse.data.sort.SortableColumn) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 87 with AbstractSyntaxTree

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);
    });
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 88 with AbstractSyntaxTree

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);
    });
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 89 with AbstractSyntaxTree

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;
}
Also used : ResolvableLink(com.cinchapi.concourse.util.Convert.ResolvableLink) TObject(com.cinchapi.concourse.thrift.TObject) DeferredWrite(com.cinchapi.concourse.server.ConcourseServer.DeferredWrite) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree)

Example 90 with AbstractSyntaxTree

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);
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Aggregations

AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)113 TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)104 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)104 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)104 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)102 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)62 TObject (com.cinchapi.concourse.thrift.TObject)57 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)56 SortableColumn (com.cinchapi.concourse.data.sort.SortableColumn)50 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)42 Set (java.util.Set)42 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)40 InsufficientAtomicityException (com.cinchapi.concourse.server.ops.InsufficientAtomicityException)39 NaturalLanguage (com.cinchapi.ccl.util.NaturalLanguage)38 AnyStrings (com.cinchapi.common.base.AnyStrings)38 Array (com.cinchapi.common.base.Array)38 CheckedExceptions (com.cinchapi.common.base.CheckedExceptions)38 Reflection (com.cinchapi.common.reflect.Reflection)38 Constants (com.cinchapi.concourse.Constants)38 Link (com.cinchapi.concourse.Link)38