Search in sources :

Example 11 with Operator

use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.

the class ConcourseServer method findKeyOperatorValuesTimePage.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Set<Long> findKeyOperatorValuesTimePage(String key, Operator operator, List<TObject> values, long timestamp, TPage page, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    TObject[] tValues = values.toArray(Array.containing());
    AtomicSupport store = getStore(transaction, environment);
    Function<Store, Set<Long>> function = $store -> Stores.find($store, timestamp, key, operator, tValues);
    Set<Long> records;
    try {
        records = function.apply(store);
    } catch (InsufficientAtomicityException e) {
        records = AtomicOperations.supplyWithRetry(store, atomic -> function.apply(atomic));
    }
    return Paging.page(records, Pages.from(page));
}
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) Supplier(java.util.function.Supplier) ConcourseCompiler(com.cinchapi.concourse.lang.ConcourseCompiler) LinkedHashMap(java.util.LinkedHashMap) 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) 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) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) SortableSet(com.cinchapi.concourse.data.sort.SortableSet) Set(java.util.Set) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) BufferedStore(com.cinchapi.concourse.server.storage.BufferedStore) Store(com.cinchapi.concourse.server.storage.Store) InsufficientAtomicityException(com.cinchapi.concourse.server.ops.InsufficientAtomicityException) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 12 with Operator

use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.

the class RangeToken method intersects.

/**
 * Return {@code true} if this RangeToken intersects the {@code other}
 * RangeToken. This RangeToken is considered to intersect another one if the
 * left point of this RangeToken is less than or equal to the right point of
 * the other one and the right point of this RangeToken is greater than or
 * equal to the left point of the other one.
 *
 * @param other
 * @return {@code true} if this RangeToken intersects the other
 */
public boolean intersects(RangeToken other) {
    Value value = other.values[0];
    Value myValue = this.values[0];
    Operator myOperator = this.operator == null ? Operator.EQUALS : this.operator;
    Operator operator = other.operator == null ? Operator.EQUALS : other.operator;
    switch(myOperator) {
        case EQUALS:
            switch(operator) {
                case EQUALS:
                    return myValue.compareTo(value) == 0;
                case NOT_EQUALS:
                    return myValue.compareTo(value) != 0;
                case GREATER_THAN:
                    return myValue.compareTo(value) > 0;
                case GREATER_THAN_OR_EQUALS:
                    return myValue.compareTo(value) >= 0;
                case LESS_THAN:
                    return myValue.compareTo(value) < 0;
                case LESS_THAN_OR_EQUALS:
                    return myValue.compareTo(value) <= 0;
                case BETWEEN:
                    return myValue.compareTo(value) >= 0 && myValue.compareTo(other.values[1]) < 0;
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case NOT_EQUALS:
            switch(operator) {
                case EQUALS:
                    return myValue.compareTo(value) != 0;
                case NOT_EQUALS:
                case GREATER_THAN:
                case GREATER_THAN_OR_EQUALS:
                case LESS_THAN:
                case LESS_THAN_OR_EQUALS:
                    return true;
                case BETWEEN:
                    return myValue.compareTo(value) != 0 || myValue.compareTo(other.values[1]) != 0;
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case GREATER_THAN:
            switch(operator) {
                case EQUALS:
                case LESS_THAN:
                case LESS_THAN_OR_EQUALS:
                    return value.compareTo(myValue) > 0;
                case NOT_EQUALS:
                case GREATER_THAN:
                case GREATER_THAN_OR_EQUALS:
                    return true;
                case BETWEEN:
                    return other.values[1].compareTo(myValue) > 0;
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case GREATER_THAN_OR_EQUALS:
            switch(operator) {
                case EQUALS:
                case LESS_THAN_OR_EQUALS:
                    return value.compareTo(myValue) >= 0;
                case LESS_THAN:
                    return value.compareTo(myValue) > 0;
                case NOT_EQUALS:
                case GREATER_THAN:
                case GREATER_THAN_OR_EQUALS:
                    return true;
                case BETWEEN:
                    // end of range
                    return other.values[1].compareTo(myValue) > 0;
                // included for BETWEEN
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case LESS_THAN:
            switch(operator) {
                case EQUALS:
                case GREATER_THAN:
                case GREATER_THAN_OR_EQUALS:
                    return value.compareTo(myValue) < 0;
                case NOT_EQUALS:
                case LESS_THAN:
                case LESS_THAN_OR_EQUALS:
                    return true;
                case BETWEEN:
                    return value.compareTo(myValue) < 0;
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case LESS_THAN_OR_EQUALS:
            switch(operator) {
                case EQUALS:
                case GREATER_THAN_OR_EQUALS:
                    return value.compareTo(myValue) <= 0;
                case LESS_THAN:
                case LESS_THAN_OR_EQUALS:
                case NOT_EQUALS:
                    return true;
                case GREATER_THAN:
                    return value.compareTo(myValue) < 0;
                case BETWEEN:
                    return value.compareTo(myValue) <= 0;
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case BETWEEN:
            Value myOtherValue = this.values[1];
            switch(operator) {
                case EQUALS:
                    return value.compareTo(myValue) >= 0 && value.compareTo(myOtherValue) < 0;
                case NOT_EQUALS:
                    return value.compareTo(myValue) != 0 || value.compareTo(myOtherValue) != 0;
                case GREATER_THAN:
                case GREATER_THAN_OR_EQUALS:
                    return value.compareTo(myOtherValue) < 0;
                case LESS_THAN:
                    return value.compareTo(myValue) > 0;
                case LESS_THAN_OR_EQUALS:
                    return value.compareTo(myValue) >= 0;
                case BETWEEN:
                    return myOtherValue.compareTo(value) >= 0 && myValue.compareTo(other.values[1]) <= 0;
                case REGEX:
                case NOT_REGEX:
                    return true;
                default:
                    throw new UnsupportedOperationException();
            }
        case REGEX:
        case NOT_REGEX:
            return true;
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) Value(com.cinchapi.concourse.server.model.Value)

Example 13 with Operator

use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.

the class Finder method visit.

@Override
public Set<Long> visit(ExpressionTree tree, Object... data) {
    Verify.that(data.length >= 1);
    Verify.that(data[0] instanceof Store);
    Store store = (Store) data[0];
    ExpressionSymbol expression = ((ExpressionSymbol) tree.root());
    String key = expression.raw().key();
    Operator operator = (Operator) expression.raw().operator();
    if (key.equals(Constants.JSON_RESERVED_IDENTIFIER_NAME)) {
        Set<Long> ids;
        if (operator == Operator.EQUALS) {
            ids = Sets.newTreeSet();
            expression.raw().values().forEach(value -> ids.add(((Number) value).longValue()));
        } else if (operator == Operator.NOT_EQUALS) {
            Set<Long> exclude = expression.raw().values().stream().map(value -> ((Number) value).longValue()).collect(Collectors.toCollection(HashSet::new));
            ids = Sets.difference(store.getAllRecords(), exclude);
        } else {
            throw new IllegalArgumentException("Cannot query on record id using " + expression.raw().operator());
        }
        return ids;
    } else {
        ArrayBuilder<TObject> values = ArrayBuilder.builder();
        expression.values().forEach(value -> values.add(Convert.javaToThrift(value.value())));
        Set<Long> results = (expression.timestamp() == TimestampSymbol.PRESENT || expression.timestamp() == null) ? Stores.find(store, key, operator, values.build()) : Stores.find(store, expression.raw().timestamp(), key, operator, values.build());
        return results;
    }
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) HashSet(java.util.HashSet) Store(com.cinchapi.concourse.server.storage.Store) ExpressionSymbol(com.cinchapi.ccl.grammar.ExpressionSymbol) HashSet(java.util.HashSet)

Example 14 with Operator

use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.

the class Buffer method explore.

@Override
public Map<Long, Set<TObject>> explore(Map<Long, Set<TObject>> context, String key, Aliases aliases, long timestamp) {
    Iterator<Write> it = iterator(key, timestamp);
    try {
        Operator operator = aliases.operator();
        TObject[] values = aliases.values();
        while (it.hasNext()) {
            Write write = it.next();
            long record = write.getRecord().longValue();
            if (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());
                }
            }
        }
        return TMaps.asSortedMap(context);
    } finally {
        Iterators.close(it);
    }
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) TObject(com.cinchapi.concourse.thrift.TObject)

Example 15 with Operator

use of com.cinchapi.concourse.thrift.Operator in project concourse by cinchapi.

the class RangeTokensTest method testConvertNotEqualRangeToken.

@Test
public void testConvertNotEqualRangeToken() {
    Text key = TestData.getText();
    Operator operator = Operator.NOT_EQUALS;
    Value value = TestData.getValue();
    RangeToken token = RangeToken.forReading(key, operator, value);
    Iterable<Range<Value>> ranges = RangeTokens.convertToRange(token);
    Assert.assertEquals(Lists.newArrayList(Range.lessThan(value), Range.greaterThan(value)), ranges);
}
Also used : Operator(com.cinchapi.concourse.thrift.Operator) Value(com.cinchapi.concourse.server.model.Value) Text(com.cinchapi.concourse.server.model.Text) Range(com.google.common.collect.Range) ConcourseBaseTest(com.cinchapi.concourse.test.ConcourseBaseTest) Test(org.junit.Test)

Aggregations

Operator (com.cinchapi.concourse.thrift.Operator)23 Test (org.junit.Test)13 Value (com.cinchapi.concourse.server.model.Value)9 TObject (com.cinchapi.concourse.thrift.TObject)9 Text (com.cinchapi.concourse.server.model.Text)8 Store (com.cinchapi.concourse.server.storage.Store)6 ConcourseBaseTest (com.cinchapi.concourse.test.ConcourseBaseTest)6 Set (java.util.Set)6 Reflection (com.cinchapi.common.reflect.Reflection)5 Constants (com.cinchapi.concourse.Constants)5 Link (com.cinchapi.concourse.Link)5 ConjunctionSymbol (com.cinchapi.ccl.grammar.ConjunctionSymbol)4 ExpressionSymbol (com.cinchapi.ccl.grammar.ExpressionSymbol)4 KeySymbol (com.cinchapi.ccl.grammar.KeySymbol)4 OperatorSymbol (com.cinchapi.ccl.grammar.OperatorSymbol)4 ParenthesisSymbol (com.cinchapi.ccl.grammar.ParenthesisSymbol)4 PostfixNotationSymbol (com.cinchapi.ccl.grammar.PostfixNotationSymbol)4 Symbol (com.cinchapi.ccl.grammar.Symbol)4 ValueSymbol (com.cinchapi.ccl.grammar.ValueSymbol)4 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)4