Search in sources :

Example 41 with Store

use of com.cinchapi.concourse.server.storage.Store 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 42 with Store

use of com.cinchapi.concourse.server.storage.Store in project concourse by cinchapi.

the class SortingTest method testSortMultipleKeysSort.

@Test
public void testSortMultipleKeysSort() {
    Map<Long, Map<String, Set<TObject>>> records = Maps.newLinkedHashMap();
    List<String> keys = Lists.newArrayList("name", "company", "age");
    Map<String, Set<TObject>> entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    Set<TObject> values = Sets.newHashSet(Convert.javaToThrift("jeff"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(1), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("ashleah"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("ARMN Inc."));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(2), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("mark"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(50));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(3), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("jeffB"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Blavity"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(1));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(4), entry);
    Order order = Order.by("age").ascending().then("company").ascending().build();
    Store store = new Queue(1);
    Map<Long, Map<String, Set<TObject>>> result = Sorting.byValues(order, store).organize(records);
    List<Long> expectedSort = Lists.newArrayList();
    expectedSort.add(Integer.toUnsignedLong(4));
    expectedSort.add(Integer.toUnsignedLong(3));
    expectedSort.add(Integer.toUnsignedLong(2));
    expectedSort.add(Integer.toUnsignedLong(1));
    List<Long> sort = Lists.newArrayList(result.keySet());
    Assert.assertEquals(expectedSort, sort);
}
Also used : Order(com.cinchapi.concourse.lang.sort.Order) TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) Store(com.cinchapi.concourse.server.storage.Store) Map(java.util.Map) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Example 43 with Store

use of com.cinchapi.concourse.server.storage.Store in project concourse by cinchapi.

the class SortingTest method testIntAscendingSort.

@Test
public void testIntAscendingSort() {
    Map<Long, Map<String, Set<TObject>>> records = Maps.newLinkedHashMap();
    List<String> keys = Lists.newArrayList("name", "company", "age");
    Map<String, Set<TObject>> entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    Set<TObject> values = Sets.newHashSet(Convert.javaToThrift("jeff"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(50));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(1), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("jeffB"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Blavity"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(2), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("ashleah"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("ARMN Inc."));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(3), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("mark"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(25));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(4), entry);
    Order order = Order.by("age").ascending().build();
    Store store = new Queue(1);
    Map<Long, Map<String, Set<TObject>>> result = Sorting.byValues(order, store).organize(records);
    List<Long> expectedSort = Lists.newArrayList();
    expectedSort.add(Integer.toUnsignedLong(4));
    expectedSort.add(Integer.toUnsignedLong(1));
    expectedSort.add(Integer.toUnsignedLong(2));
    expectedSort.add(Integer.toUnsignedLong(3));
    List<Long> sort = Lists.newArrayList(result.keySet());
    Assert.assertEquals(expectedSort, sort);
}
Also used : Order(com.cinchapi.concourse.lang.sort.Order) TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) Store(com.cinchapi.concourse.server.storage.Store) Map(java.util.Map) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Example 44 with Store

use of com.cinchapi.concourse.server.storage.Store in project concourse by cinchapi.

the class SortingTest method testUnequalValueQuantityAscendingSort.

@Test
public void testUnequalValueQuantityAscendingSort() {
    Map<Long, Map<String, Set<TObject>>> records = Maps.newLinkedHashMap();
    List<String> keys = Lists.newArrayList("name", "company", "age");
    Map<String, Set<TObject>> entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    Set<TObject> values = Sets.newHashSet(Convert.javaToThrift("jeff"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"), Convert.javaToThrift("Blavity"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(50));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(1), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("ashleah"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("ARMN Inc."));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(25));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(2), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("mark"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(3), entry);
    Order order = Order.by("company").ascending().build();
    Store store = new Queue(1);
    Map<Long, Map<String, Set<TObject>>> result = Sorting.byValues(order, store).organize(records);
    List<Long> expectedSort = Lists.newArrayList();
    expectedSort.add(Integer.toUnsignedLong(2));
    expectedSort.add(Integer.toUnsignedLong(1));
    expectedSort.add(Integer.toUnsignedLong(3));
    List<Long> sort = Lists.newArrayList(result.keySet());
    Assert.assertEquals(expectedSort, sort);
}
Also used : Order(com.cinchapi.concourse.lang.sort.Order) TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) Store(com.cinchapi.concourse.server.storage.Store) Map(java.util.Map) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Example 45 with Store

use of com.cinchapi.concourse.server.storage.Store in project concourse by cinchapi.

the class SortingTest method testStringAscendingSort.

@Test
public void testStringAscendingSort() {
    Map<Long, Map<String, Set<TObject>>> records = Maps.newLinkedHashMap();
    List<String> keys = Lists.newArrayList("name", "company", "age");
    Map<String, Set<TObject>> entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    Set<TObject> values = Sets.newHashSet(Convert.javaToThrift("jeff"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(50));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(1), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("jeffB"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Blavity"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(2), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("ashleah"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("ARMN Inc."));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(3), entry);
    entry = TMaps.newLinkedHashMapWithCapacity(keys.size());
    values = Sets.newHashSet(Convert.javaToThrift("mark"));
    entry.put("name", values);
    values = Sets.newHashSet(Convert.javaToThrift("Cinchapi"));
    entry.put("company", values);
    values = Sets.newHashSet(Convert.javaToThrift(25));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(4), entry);
    Order order = Order.by("name").ascending().build();
    Store store = new Queue(1);
    Map<Long, Map<String, Set<TObject>>> result = Sorting.byValues(order, store).organize(records);
    List<Long> expectedSort = Lists.newArrayList();
    expectedSort.add(Integer.toUnsignedLong(3));
    expectedSort.add(Integer.toUnsignedLong(1));
    expectedSort.add(Integer.toUnsignedLong(2));
    expectedSort.add(Integer.toUnsignedLong(4));
    List<Long> sort = Lists.newArrayList(result.keySet());
    Assert.assertEquals(expectedSort, sort);
}
Also used : Order(com.cinchapi.concourse.lang.sort.Order) TObject(com.cinchapi.concourse.thrift.TObject) Set(java.util.Set) Store(com.cinchapi.concourse.server.storage.Store) Map(java.util.Map) Queue(com.cinchapi.concourse.server.storage.temp.Queue) Test(org.junit.Test)

Aggregations

Store (com.cinchapi.concourse.server.storage.Store)67 TObject (com.cinchapi.concourse.thrift.TObject)67 Set (java.util.Set)67 Map (java.util.Map)66 Order (com.cinchapi.concourse.lang.sort.Order)64 Constants (com.cinchapi.concourse.Constants)57 Link (com.cinchapi.concourse.Link)57 Operator (com.cinchapi.concourse.thrift.Operator)57 Reflection (com.cinchapi.common.reflect.Reflection)56 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)55 ConcourseCompiler (com.cinchapi.concourse.lang.ConcourseCompiler)55 GlobalState (com.cinchapi.concourse.server.GlobalState)55 NaturalLanguage (com.cinchapi.ccl.util.NaturalLanguage)54 AnyStrings (com.cinchapi.common.base.AnyStrings)54 Array (com.cinchapi.common.base.Array)54 CheckedExceptions (com.cinchapi.common.base.CheckedExceptions)54 Timestamp (com.cinchapi.concourse.Timestamp)54 SortableColumn (com.cinchapi.concourse.data.sort.SortableColumn)54 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)54 SortableTable (com.cinchapi.concourse.data.sort.SortableTable)54