Search in sources :

Example 41 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class ViewTest method testNestedRelationshipAttribute.

@Test
public void testNestedRelationshipAttribute() throws Exception {
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("countryViewIsoCode", Sorting.SortOrder.desc);
    Query query = Query.builder().source(playerStatsWithViewSchema).metricProjection(playerStatsWithViewSchema.getMetricProjection("lowScore")).dimensionProjection(playerStatsWithViewSchema.getDimensionProjection("countryViewViewIsoCode")).sorting(new SortingImpl(sortMap, PlayerStatsWithView.class, dictionary)).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    PlayerStatsWithView usa0 = new PlayerStatsWithView();
    usa0.setId("0");
    usa0.setLowScore(35);
    usa0.setCountryViewViewIsoCode("USA");
    PlayerStatsWithView hk1 = new PlayerStatsWithView();
    hk1.setId("1");
    hk1.setLowScore(72);
    hk1.setCountryViewViewIsoCode("HKG");
    assertEquals(2, results.size());
    assertEquals(usa0, results.get(0));
    assertEquals(hk1, results.get(1));
    // the join would not happen for a view join
    PlayerStatsWithView actualStats1 = (PlayerStatsWithView) results.get(0);
    assertNull(actualStats1.getCountry());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStatsWithView(example.PlayerStatsWithView) 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 42 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class ViewTest method testNestedViewAttribute.

@Test
public void testNestedViewAttribute() throws Exception {
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("countryViewIsoCode", Sorting.SortOrder.desc);
    Query query = Query.builder().source(playerStatsWithViewSchema).metricProjection(playerStatsWithViewSchema.getMetricProjection("lowScore")).dimensionProjection(playerStatsWithViewSchema.getDimensionProjection("countryViewViewIsoCode")).sorting(new SortingImpl(sortMap, PlayerStatsWithView.class, dictionary)).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    PlayerStatsWithView usa0 = new PlayerStatsWithView();
    usa0.setId("0");
    usa0.setLowScore(35);
    usa0.setCountryViewViewIsoCode("USA");
    PlayerStatsWithView hk1 = new PlayerStatsWithView();
    hk1.setId("1");
    hk1.setLowScore(72);
    hk1.setCountryViewViewIsoCode("HKG");
    assertEquals(2, results.size());
    assertEquals(usa0, results.get(0));
    assertEquals(hk1, results.get(1));
    // the join would not happen for a view join
    PlayerStatsWithView actualStats1 = (PlayerStatsWithView) results.get(0);
    assertNull(actualStats1.getCountry());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStatsWithView(example.PlayerStatsWithView) 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 43 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class ViewTest method testSortingNestedViewAttribute.

@Test
public void testSortingNestedViewAttribute() throws Exception {
    Map<String, Sorting.SortOrder> sortMap = new TreeMap<>();
    sortMap.put("countryViewViewIsoCode", Sorting.SortOrder.desc);
    Query query = Query.builder().source(playerStatsWithViewSchema).metricProjection(playerStatsWithViewSchema.getMetricProjection("lowScore")).dimensionProjection(playerStatsWithViewSchema.getDimensionProjection("countryViewViewIsoCode")).sorting(new SortingImpl(sortMap, PlayerStatsWithView.class, dictionary)).build();
    List<Object> results = toList(engine.executeQuery(query, transaction).getData());
    PlayerStatsWithView usa0 = new PlayerStatsWithView();
    usa0.setId("0");
    usa0.setLowScore(35);
    usa0.setCountryViewViewIsoCode("USA");
    PlayerStatsWithView hk1 = new PlayerStatsWithView();
    hk1.setId("1");
    hk1.setLowScore(72);
    hk1.setCountryViewViewIsoCode("HKG");
    assertEquals(2, results.size());
    assertEquals(usa0, results.get(0));
    assertEquals(hk1, results.get(1));
    // the join would not happen for a view join
    PlayerStatsWithView actualStats1 = (PlayerStatsWithView) results.get(0);
    assertNull(actualStats1.getCountry());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) PlayerStatsWithView(example.PlayerStatsWithView) 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 44 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class AbstractHQLQueryBuilderTest method testSortClauseWithComplexAttribute.

@Test
public void testSortClauseWithComplexAttribute() {
    Map<String, Sorting.SortOrder> sorting = new LinkedHashMap<>();
    sorting.put("price.total", Sorting.SortOrder.asc);
    String actual = getSortClause(new SortingImpl(sorting, Book.class, dictionary));
    String expected = " order by example_Book.price.total asc";
    assertEquals(expected, actual);
}
Also used : SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 45 with SortingImpl

use of com.yahoo.elide.core.sort.SortingImpl in project elide by yahoo.

the class AbstractHQLQueryBuilderTest method testSortClauseWithJoin.

@Test
public void testSortClauseWithJoin() {
    Map<String, Sorting.SortOrder> sorting = new LinkedHashMap<>();
    sorting.put(PUBLISHER + PERIOD + NAME, Sorting.SortOrder.asc);
    String actual = getSortClause(new SortingImpl(sorting, Book.class, dictionary));
    String expected = " order by example_Book_publisher.name asc";
    assertEquals(expected, actual);
}
Also used : SortingImpl(com.yahoo.elide.core.sort.SortingImpl) Book(example.Book) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedHashMap(java.util.LinkedHashMap) 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