Search in sources :

Example 91 with AbstractSyntaxTree

use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.

the class FinderTest method testAndConjunctionShortCircuit.

@Test
public void testAndConjunctionShortCircuit() {
    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 or company = Cinchapi) and age = 70";
    AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
    Finder visitor = Finder.instance();
    Set<Long> result = ast.accept(visitor, store);
    Assert.assertEquals(Sets.newHashSet(), result);
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Example 92 with AbstractSyntaxTree

use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.

the class FinderTest method testAndConjunction.

@Test
public void testAndConjunction() {
    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 and company = Cinchapi";
    AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
    Finder visitor = Finder.instance();
    Set<Long> result = ast.accept(visitor, store);
    Assert.assertEquals(Sets.newHashSet(1L), result);
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Example 93 with AbstractSyntaxTree

use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.

the class Criteria method parse.

/**
 * Return a {@link Criteria} object that expresses the same as the
 * {@code ccl} statement.
 *
 * @param ccl the CCL statement to parse
 * @return an equivalent {@link Criteria} object
 */
public static Criteria parse(String ccl) {
    try {
        AbstractSyntaxTree ast = ConcourseCompiler.get().parse(ccl);
        BuiltCriteria criteria = new BuiltCriteria();
        criteria.symbols = Lists.newArrayList(ConcourseCompiler.get().tokenize(ast));
        return criteria;
    } catch (Exception e) {
        if (e instanceof SyntaxException || e instanceof IllegalStateException || e.getCause() != null && e.getCause() instanceof com.cinchapi.ccl.generated.ParseException) {
            throw new ParseException(new com.cinchapi.concourse.thrift.ParseException(e.getMessage()));
        } else {
            throw CheckedExceptions.throwAsRuntimeException(e);
        }
    }
}
Also used : AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) SyntaxException(com.cinchapi.ccl.SyntaxException) ParseException(com.cinchapi.concourse.ParseException) SyntaxException(com.cinchapi.ccl.SyntaxException) ParseException(com.cinchapi.concourse.ParseException)

Example 94 with AbstractSyntaxTree

use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.

the class ExportCli method init.

/**
 * Initialize the CLI based on the arguments that are provided.
 */
private void init() {
    ExportOptions opts = (ExportOptions) options;
    // file
    if (!Empty.ness().describes(opts.file)) {
        file = Paths.get(opts.file);
        File $file = file.toFile();
        $file.getParentFile().mkdirs();
        try {
            $file.createNewFile();
        } catch (IOException e) {
            CheckedExceptions.wrapAsRuntimeException(e);
        }
    }
    // records
    if (!Empty.ness().describes(opts.records)) {
        records = AnyObjects.split(opts.records, ',').stream().map(Long::parseLong).collect(Collectors.toCollection(LinkedHashSet::new));
    }
    // keys
    if (!Empty.ness().describes(opts.keys)) {
        keys = AnyObjects.split(opts.keys, ',').stream().collect(Collectors.toCollection(LinkedHashSet::new));
    }
    // order
    if (!Empty.ness().describes(opts.order)) {
        if (!opts.order.toLowerCase().startsWith("order by")) {
            opts.order = "ORDER BY " + opts.order;
        }
        try {
            AbstractSyntaxTree ast = ConcourseCompiler.get().parse(opts.order);
            OrderTree tree = (OrderTree) ast;
            order = Order.from(tree);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid order CCL statement");
        }
    }
    // page
    String $page = "";
    if (!Empty.ness().describes(opts.page)) {
        $page += "PAGE " + opts.page + " ";
    }
    if (!Empty.ness().describes(opts.size)) {
        $page += "SIZE " + opts.size;
    }
    if (!Empty.ness().describes($page)) {
        try {
            AbstractSyntaxTree ast = ConcourseCompiler.get().parse($page);
            PageTree tree = (PageTree) ast;
            page = Page.from(tree);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid page or size argument");
        }
    }
    excludeRecordId = opts.excludeRecordId;
    condition = opts.condition;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) OrderTree(com.cinchapi.ccl.syntax.OrderTree) PageTree(com.cinchapi.ccl.syntax.PageTree) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 95 with AbstractSyntaxTree

use of com.cinchapi.ccl.syntax.AbstractSyntaxTree in project concourse by cinchapi.

the class ConcourseServer method selectKeysCriteriaTimeOrder.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, Set<TObject>>> selectKeysCriteriaTimeOrder(List<String> keys, TCriteria criteria, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AbstractSyntaxTree ast = compiler.parse(criteria);
    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;
}
Also used : UpgradeTasks(com.cinchapi.concourse.server.upgrade.UpgradeTasks) TServer(org.apache.thrift.server.TServer) Transaction(com.cinchapi.concourse.server.storage.Transaction) Constants(com.cinchapi.concourse.Constants) Permission(com.cinchapi.concourse.security.Permission) ServerSocket(java.net.ServerSocket) ConcourseCalculateService(com.cinchapi.concourse.thrift.ConcourseCalculateService) TransactionStateException(com.cinchapi.concourse.server.storage.TransactionStateException) SortableColumn(com.cinchapi.concourse.data.sort.SortableColumn) SecurityException(com.cinchapi.concourse.thrift.SecurityException) Map(java.util.Map) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer) TransactionException(com.cinchapi.concourse.thrift.TransactionException) Link(com.cinchapi.concourse.Link) SortableSet(com.cinchapi.concourse.data.sort.SortableSet) SortableTable(com.cinchapi.concourse.data.sort.SortableTable) AccessToken(com.cinchapi.concourse.thrift.AccessToken) UserService(com.cinchapi.concourse.security.UserService) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions) Orders(com.cinchapi.concourse.server.query.sort.Orders) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) FileSystem(com.cinchapi.concourse.server.io.FileSystem) Set(java.util.Set) DuplicateEntryException(com.cinchapi.concourse.thrift.DuplicateEntryException) Executors(java.util.concurrent.Executors) ConcourseManagementService(com.cinchapi.concourse.server.management.ConcourseManagementService) MalformedObjectNameException(javax.management.MalformedObjectNameException) AtomicOperation(com.cinchapi.concourse.server.storage.AtomicOperation) Operator(com.cinchapi.concourse.thrift.Operator) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TProcessor(org.apache.thrift.TProcessor) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) PluginManager(com.cinchapi.concourse.server.plugin.PluginManager) Stores(com.cinchapi.concourse.server.ops.Stores) Iterables(com.google.common.collect.Iterables) Environments(com.cinchapi.concourse.util.Environments) TMultiplexedProcessor(org.apache.thrift.TMultiplexedProcessor) Sorting(com.cinchapi.concourse.server.query.sort.Sorting) Timestamps(com.cinchapi.concourse.util.Timestamps) ConcourseCompiler(com.cinchapi.concourse.lang.ConcourseCompiler) Strings(com.google.common.base.Strings) Reflection(com.cinchapi.common.reflect.Reflection) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) Lists(com.google.common.collect.Lists) InsufficientAtomicityException(com.cinchapi.concourse.server.ops.InsufficientAtomicityException) ManagementFactory(java.lang.management.ManagementFactory) TSimpleServer(org.apache.thrift.server.TSimpleServer) Array(com.cinchapi.common.base.Array) Nullable(javax.annotation.Nullable) ConcourseServerAdvisor(com.cinchapi.concourse.server.aop.ConcourseServerAdvisor) NonBlockingHashMap(org.cliffc.high_scale_lib.NonBlockingHashMap) Engine(com.cinchapi.concourse.server.storage.Engine) TException(org.apache.thrift.TException) CommandLine(com.cinchapi.concourse.shell.CommandLine) File(java.io.File) Args(org.apache.thrift.server.TThreadPoolServer.Args) NaturalLanguage(com.cinchapi.ccl.util.NaturalLanguage) CommitVersions(com.cinchapi.concourse.server.storage.CommitVersions) Guice(com.google.inject.Guice) Preconditions(com.google.common.base.Preconditions) ConcourseNavigateService(com.cinchapi.concourse.thrift.ConcourseNavigateService) AnyStrings(com.cinchapi.common.base.AnyStrings) TCriteria(com.cinchapi.concourse.thrift.TCriteria) TTransportException(org.apache.thrift.transport.TTransportException) Logger(com.cinchapi.concourse.util.Logger) AtomicStateException(com.cinchapi.concourse.server.storage.AtomicStateException) Paging(com.cinchapi.concourse.server.query.paginate.Paging) ByteBuffer(java.nio.ByteBuffer) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Convert(com.cinchapi.concourse.util.Convert) PluginRestricted(com.cinchapi.concourse.server.plugin.PluginRestricted) BufferedStore(com.cinchapi.concourse.server.storage.BufferedStore) TOrder(com.cinchapi.concourse.thrift.TOrder) Internal(com.cinchapi.concourse.server.aop.Internal) AtomicOperations(com.cinchapi.concourse.server.ops.AtomicOperations) Timestamp(com.cinchapi.concourse.Timestamp) Version(com.cinchapi.concourse.util.Version) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) ManagedOperation(com.cinchapi.concourse.server.jmx.ManagedOperation) Operations(com.cinchapi.concourse.server.ops.Operations) Language(com.cinchapi.concourse.lang.Language) Sets(com.google.common.collect.Sets) List(java.util.List) Entry(java.util.Map.Entry) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) CheckedExceptions(com.cinchapi.common.base.CheckedExceptions) Role(com.cinchapi.concourse.security.Role) ManagementException(com.cinchapi.concourse.thrift.ManagementException) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Store(com.cinchapi.concourse.server.storage.Store) HttpServer(com.cinchapi.concourse.server.http.HttpServer) ConcourseService(com.cinchapi.concourse.thrift.ConcourseService) TransactionToken(com.cinchapi.concourse.thrift.TransactionToken) Multimap(com.google.common.collect.Multimap) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ParseException(com.cinchapi.concourse.thrift.ParseException) TObject(com.cinchapi.concourse.thrift.TObject) GlobalState(com.cinchapi.concourse.server.GlobalState) TMaps(com.cinchapi.concourse.util.TMaps) MBeanRegistrationException(javax.management.MBeanRegistrationException) NoSuchElementException(java.util.NoSuchElementException) MemoryUsage(java.lang.management.MemoryUsage) Time(com.cinchapi.concourse.time.Time) Iterator(java.util.Iterator) Order(com.cinchapi.concourse.lang.sort.Order) LazyTrackingTObjectResultDataset(com.cinchapi.concourse.server.plugin.data.LazyTrackingTObjectResultDataset) TPage(com.cinchapi.concourse.thrift.TPage) Pages(com.cinchapi.concourse.server.query.paginate.Pages) Maps(com.google.common.collect.Maps) Injector(com.google.inject.Injector) TServerSocket(org.apache.thrift.transport.TServerSocket) Finder(com.cinchapi.concourse.server.query.Finder) ClientInvokable(com.cinchapi.concourse.server.management.ClientInvokable) Immutable(javax.annotation.concurrent.Immutable) Diff(com.cinchapi.concourse.thrift.Diff) SortableSet(com.cinchapi.concourse.data.sort.SortableSet) Set(java.util.Set) 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)

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