use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class DefaultQueryValidatorTest method testSortingOnNotQueriedDimension.
@Test
public void testSortingOnNotQueriedDimension() {
Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
sortMap.put("countryIsoCode", Sorting.SortOrder.asc);
Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).sorting(new SortingImpl(sortMap, PlayerStats.class, dictionary)).build();
validateQuery(query, "Invalid operation: Can not sort on countryIsoCode as it is not present in query");
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortOnComputedAttribute.
@Test
public void testSortOnComputedAttribute() {
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("fullName", Sorting.SortOrder.desc);
Editor editor1 = new Editor();
editor1.setFirstName("A");
editor1.setLastName("X");
Editor editor2 = new Editor();
editor2.setFirstName("B");
editor2.setLastName("Y");
Sorting sorting = new SortingImpl(sortOrder, Editor.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Editor.class).sorting(sorting).build();
DataStoreIterable iterable = new DataStoreIterableBuilder(Arrays.asList(editor1, editor2)).sortInMemory(false).build();
ArgumentCaptor<EntityProjection> projectionArgument = ArgumentCaptor.forClass(EntityProjection.class);
when(wrappedTransaction.loadObjects(projectionArgument.capture(), eq(scope))).thenReturn(iterable);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
assertNull(projectionArgument.getValue().getSorting());
assertEquals(2, loaded.size());
Object[] sorted = loaded.toArray();
assertEquals(editor2, sorted[0]);
assertEquals(editor1, sorted[1]);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testFilteringRequiresInMemorySorting.
@Test
public void testFilteringRequiresInMemorySorting() {
FilterExpression expression = new InPredicate(new Path(Book.class, dictionary, "genre"), "Literary Fiction");
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.desc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).filterExpression(expression).sorting(sorting).build();
DataStoreIterable filterInMemory = new DataStoreIterableBuilder(books).filterInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(filterInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(2, loaded.size());
List<String> bookTitles = loaded.stream().map((o) -> ((Book) o).getTitle()).collect(Collectors.toList());
assertEquals(Lists.newArrayList("Book 3", "Book 1"), bookTitles);
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testDataStoreRequiresInMemorySorting.
@Test
public void testDataStoreRequiresInMemorySorting() {
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.desc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).sorting(sorting).build();
DataStoreIterable sortInMemory = new DataStoreIterableBuilder(books).sortInMemory(true).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(sortInMemory);
Collection<Object> loaded = Lists.newArrayList(inMemoryStoreTransaction.loadObjects(projection, scope));
verify(wrappedTransaction, times(1)).loadObjects(any(EntityProjection.class), eq(scope));
assertEquals(3, loaded.size());
List<String> bookTitles = loaded.stream().map((o) -> ((Book) o).getTitle()).collect(Collectors.toList());
assertEquals(bookTitles, Lists.newArrayList("Book 3", "Book 2", "Book 1"));
}
use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.
the class InMemoryStoreTransactionTest method testSortingPushDown.
@Test
public void testSortingPushDown() {
Map<String, Sorting.SortOrder> sortOrder = new HashMap<>();
sortOrder.put("title", Sorting.SortOrder.asc);
Sorting sorting = new SortingImpl(sortOrder, Book.class, dictionary);
EntityProjection projection = EntityProjection.builder().type(Book.class).sorting(sorting).build();
DataStoreIterable expected = new DataStoreIterableBuilder<>(books).build();
when(wrappedTransaction.loadObjects(any(), eq(scope))).thenReturn(expected);
DataStoreIterable actual = inMemoryStoreTransaction.loadObjects(projection, scope);
verify(wrappedTransaction, times(1)).loadObjects(eq(projection), eq(scope));
assertEquals(expected, actual);
}
Aggregations