Search in sources :

Example 26 with SortingImpl

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");
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) TreeMap(java.util.TreeMap) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 27 with SortingImpl

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]);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) HashMap(java.util.HashMap) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Sorting(com.yahoo.elide.core.request.Sorting) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Editor(example.Editor) Test(org.junit.jupiter.api.Test)

Example 28 with SortingImpl

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);
}
Also used : Path(com.yahoo.elide.core.Path) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Path(com.yahoo.elide.core.Path) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Publisher(example.Publisher) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) ClassType(com.yahoo.elide.core.type.ClassType) Map(java.util.Map) PersistentResource(com.yahoo.elide.core.PersistentResource) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Relationship(com.yahoo.elide.core.request.Relationship) RequestScope(com.yahoo.elide.core.RequestScope) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) HashMap(java.util.HashMap) Author(example.Author) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Editor(example.Editor) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) LinkedHashSet(java.util.LinkedHashSet) ElideSettings(com.yahoo.elide.ElideSettings) Price(example.Price) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Sorting(com.yahoo.elide.core.request.Sorting) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Mockito.times(org.mockito.Mockito.times) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Address(example.Address) Mockito.reset(org.mockito.Mockito.reset) EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) HashMap(java.util.HashMap) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Sorting(com.yahoo.elide.core.request.Sorting) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 29 with SortingImpl

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"));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Path(com.yahoo.elide.core.Path) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Publisher(example.Publisher) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) ClassType(com.yahoo.elide.core.type.ClassType) Map(java.util.Map) PersistentResource(com.yahoo.elide.core.PersistentResource) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Relationship(com.yahoo.elide.core.request.Relationship) RequestScope(com.yahoo.elide.core.RequestScope) ImmutableSet(com.google.common.collect.ImmutableSet) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) HashMap(java.util.HashMap) Author(example.Author) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) Editor(example.Editor) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) LinkedHashSet(java.util.LinkedHashSet) ElideSettings(com.yahoo.elide.ElideSettings) Price(example.Price) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Sorting(com.yahoo.elide.core.request.Sorting) InPredicate(com.yahoo.elide.core.filter.predicates.InPredicate) Mockito.times(org.mockito.Mockito.times) EntityProjection(com.yahoo.elide.core.request.EntityProjection) Book(example.Book) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Address(example.Address) Mockito.reset(org.mockito.Mockito.reset) EntityProjection(com.yahoo.elide.core.request.EntityProjection) DataStoreIterableBuilder(com.yahoo.elide.core.datastore.DataStoreIterableBuilder) HashMap(java.util.HashMap) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Sorting(com.yahoo.elide.core.request.Sorting) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) Test(org.junit.jupiter.api.Test)

Example 30 with SortingImpl

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);
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) HashMap(java.util.HashMap) SortingImpl(com.yahoo.elide.core.sort.SortingImpl) DataStoreIterable(com.yahoo.elide.core.datastore.DataStoreIterable) Sorting(com.yahoo.elide.core.request.Sorting) Test(org.junit.jupiter.api.Test)

Aggregations

SortingImpl (com.yahoo.elide.core.sort.SortingImpl)53 Test (org.junit.jupiter.api.Test)53 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)29 Query (com.yahoo.elide.datastores.aggregation.query.Query)29 TreeMap (java.util.TreeMap)29 HashMap (java.util.HashMap)23 EntityProjection (com.yahoo.elide.core.request.EntityProjection)15 Book (example.Book)15 PlayerStats (example.PlayerStats)12 Sorting (com.yahoo.elide.core.request.Sorting)10 Path (com.yahoo.elide.core.Path)9 Relationship (com.yahoo.elide.core.request.Relationship)8 Author (example.Author)8 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)7 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)7 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)7 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)6 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)6 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)6 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)6