Search in sources :

Example 46 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class EntityProjectionTranslatorTest method testWherePromotion.

@Test
public void testWherePromotion() throws ParseException {
    FilterExpression originalFilter = filterParser.parseFilterExpression("overallRating==Good,lowScore[foo:bar]<45", playerStatsType, false);
    EntityProjection projection = basicProjection.copyOf().filterExpression(originalFilter).build();
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, projection, scope, true);
    Query query = translator.getQuery();
    SplitFilterExpressionVisitor visitor = new SplitFilterExpressionVisitor(playerStatsTable);
    FilterConstraints constraints = originalFilter.accept(visitor);
    FilterExpression whereFilter = constraints.getWhereExpression();
    FilterExpression havingFilter = constraints.getHavingExpression();
    assertEquals(whereFilter, query.getWhereFilter());
    assertEquals(havingFilter, query.getHavingFilter());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Query(com.yahoo.elide.datastores.aggregation.query.Query) SplitFilterExpressionVisitor(com.yahoo.elide.datastores.aggregation.filter.visitor.SplitFilterExpressionVisitor) FilterConstraints(com.yahoo.elide.datastores.aggregation.filter.visitor.FilterConstraints) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 47 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class EntityProjectionTranslatorTest method testHavingClauseMetricsMissingFromProjection.

@Test
public void testHavingClauseMetricsMissingFromProjection() throws ParseException {
    FilterExpression filter = filterParser.parseFilterExpression("lowScore>45", playerStatsType, false);
    EntityProjection projection = EntityProjection.builder().type(PlayerStats.class).filterExpression(filter).attribute(Attribute.builder().type(long.class).name("highScore").build()).attribute(Attribute.builder().type(String.class).name("overallRating").build()).build();
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, projection, scope, true);
    Query query = translator.getQuery();
    List<String> metricNames = query.getMetricProjections().stream().map(MetricProjection::getName).collect(Collectors.toList());
    assertEquals(metricNames, Arrays.asList("highScore", "lowScore"));
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) Query(com.yahoo.elide.datastores.aggregation.query.Query) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 48 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class EntityProjectionTranslatorTest method testTimeDimension.

@Test
public void testTimeDimension() {
    EntityProjection projection = basicProjection.copyOf().attribute(Attribute.builder().type(Date.class).name("recordedDate").build()).build();
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, projection, scope, true);
    Query query = translator.getQuery();
    List<TimeDimensionProjection> timeDimensions = new ArrayList<>(query.getTimeDimensionProjections());
    assertEquals(1, timeDimensions.size());
    assertEquals("recordedDate", timeDimensions.get(0).getAlias());
    assertEquals(TimeGrain.DAY, timeDimensions.get(0).getGrain());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) TimeDimensionProjection(com.yahoo.elide.datastores.aggregation.query.TimeDimensionProjection) Query(com.yahoo.elide.datastores.aggregation.query.Query) ArrayList(java.util.ArrayList) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 49 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class AggregationDataStoreTransactionTest method loadObjectsPopulatesCache.

@Test
public void loadObjectsPopulatesCache() {
    Mockito.reset(queryLogger);
    QueryResult queryResult = QueryResult.builder().data(DATA).build();
    NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
    when(queryEngine.getTableVersion(playerStatsTable, qeTransaction)).thenReturn("foo");
    when(queryEngine.executeQuery(query, qeTransaction)).thenReturn(queryResult);
    when(queryEngine.explain(query)).thenReturn(Arrays.asList(myQuery.toString()));
    AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
    assertEquals(DATA, Lists.newArrayList(transaction.loadObjects(entityProjection, scope)));
    String cacheKey = "foo;" + queryKey;
    Mockito.verify(cache).get(cacheKey);
    Mockito.verify(cache).put(cacheKey, queryResult);
    Mockito.verifyNoMoreInteractions(cache);
    Mockito.verify(queryLogger, times(1)).acceptQuery(Mockito.eq(scope.getRequestId()), any(), any(), any(), any(), any());
    Mockito.verify(queryLogger, times(1)).processQuery(Mockito.eq(scope.getRequestId()), any(), any(), Mockito.eq(false));
    Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
Also used : EntityProjection(com.yahoo.elide.core.request.EntityProjection) QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) PlayerStats(example.PlayerStats) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 50 with EntityProjection

use of com.yahoo.elide.core.request.EntityProjection in project elide by yahoo.

the class AggregationDataStoreTransactionTest method loadObjectsPassesPagination.

@Test
public void loadObjectsPassesPagination() {
    Mockito.reset(queryLogger);
    QueryResult queryResult = QueryResult.builder().data(DATA).pageTotals(314L).build();
    NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
    when(cache.get(anyString())).thenReturn(queryResult);
    when(queryEngine.getTableVersion(playerStatsTable, qeTransaction)).thenReturn("foo");
    when(queryEngine.explain(query)).thenReturn(Arrays.asList(myQuery.toString()));
    AggregationDataStoreTransaction transaction = new MyAggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    Pagination pagination = new PaginationImpl(String.class, null, null, DEFAULT_PAGE_LIMIT, MAX_PAGE_LIMIT, true, false);
    EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).pagination(pagination).build();
    assertEquals(DATA, Lists.newArrayList(transaction.loadObjects(entityProjection, scope)));
    assertEquals(314L, entityProjection.getPagination().getPageTotals());
    String cacheKey = "foo;" + queryKey;
    Mockito.verify(queryEngine, never()).executeQuery(any(), any());
    Mockito.verify(cache).get(cacheKey);
    Mockito.verifyNoMoreInteractions(cache);
    Mockito.verify(queryLogger, times(1)).acceptQuery(Mockito.eq(scope.getRequestId()), any(), any(), any(), any(), any());
    Mockito.verify(queryLogger, times(1)).processQuery(Mockito.eq(scope.getRequestId()), any(), any(), Mockito.eq(true));
    Mockito.verify(queryLogger, times(1)).completeQuery(Mockito.eq(scope.getRequestId()), any());
}
Also used : Pagination(com.yahoo.elide.core.request.Pagination) EntityProjection(com.yahoo.elide.core.request.EntityProjection) QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) PaginationImpl(com.yahoo.elide.core.pagination.PaginationImpl) NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

EntityProjection (com.yahoo.elide.core.request.EntityProjection)108 Test (org.junit.jupiter.api.Test)90 Book (example.Book)41 RequestScope (com.yahoo.elide.core.RequestScope)27 Author (example.Author)27 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)22 Publisher (example.Publisher)22 Relationship (com.yahoo.elide.core.request.Relationship)19 Path (com.yahoo.elide.core.Path)18 TestRequestScope (com.yahoo.elide.core.TestRequestScope)18 InPredicate (com.yahoo.elide.core.filter.predicates.InPredicate)18 HashMap (java.util.HashMap)18 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)18 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)16 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)15 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)15 Collection (java.util.Collection)15 LinkedHashSet (java.util.LinkedHashSet)14 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)13 Editor (example.Editor)13