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());
}
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"));
}
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());
}
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());
}
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());
}
Aggregations