Search in sources :

Example 6 with Queue

use of com.cinchapi.concourse.server.storage.temp.Queue in project concourse by cinchapi.

the class SortingTest method testMissingKeyDescendingSort.

@Test
public void testMissingKeyDescendingSort() {
    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);
    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(100));
    entry.put("age", values);
    TMaps.putResultDatasetOptimized(records, Integer.toUnsignedLong(4), entry);
    Order order = Order.by("age").descending();
    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(4));
    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 7 with Queue

use of com.cinchapi.concourse.server.storage.temp.Queue 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)

Example 8 with Queue

use of com.cinchapi.concourse.server.storage.temp.Queue 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 9 with Queue

use of com.cinchapi.concourse.server.storage.temp.Queue 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 10 with Queue

use of com.cinchapi.concourse.server.storage.temp.Queue 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)

Aggregations

Queue (com.cinchapi.concourse.server.storage.temp.Queue)13 Test (org.junit.Test)13 Order (com.cinchapi.concourse.lang.sort.Order)9 Store (com.cinchapi.concourse.server.storage.Store)9 TObject (com.cinchapi.concourse.thrift.TObject)9 Map (java.util.Map)9 Set (java.util.Set)9 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)4 Ignore (org.junit.Ignore)1