Search in sources :

Example 6 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class AggregationDataStoreTransactionTest method loadObjectsBypassCache.

@Test
public void loadObjectsBypassCache() {
    Mockito.reset(queryLogger);
    query = Query.builder().source(playerStatsTable).bypassingCache(true).build();
    NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
    QueryResult queryResult = QueryResult.builder().data(DATA).build();
    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)));
    Mockito.verify(queryEngine, never()).getTableVersion(any(), any());
    Mockito.verifyNoInteractions(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) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 7 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class AggregationDataStoreTransactionTest method loadObjectsNoTableVersion.

@Test
public void loadObjectsNoTableVersion() {
    Mockito.reset(queryLogger);
    NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
    QueryResult queryResult = QueryResult.builder().data(DATA).build();
    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();
    transaction.loadObjects(entityProjection, scope);
    String cacheKey = ";" + queryKey;
    Mockito.verify(cache).get(cacheKey);
    Mockito.verify(cache).put(cacheKey, queryResult);
    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 8 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class RedisCacheTest method testPutResults.

@Test
public void testPutResults() {
    String key = "example_PlayerStats;{highScore;{}}{}{};;;;";
    Iterable<Object> data = Collections.singletonList("xyzzy");
    QueryResult queryResult = QueryResult.builder().data(data).build();
    cache.put(key, queryResult);
    // retrive results and verify they match original.
    assertEquals(queryResult, cache.get(key));
    assertEquals("xyzzy", cache.get(key).getData().iterator().next());
}
Also used : QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) Test(org.junit.jupiter.api.Test)

Example 9 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class RedisCacheTest method testPutResultsFail.

// Redis server does not exist.
@Test
public void testPutResultsFail() throws IOException {
    destroy();
    String key = "example_PlayerStats;{highScore;{}}{}{};;;;";
    Iterable<Object> data = Collections.singletonList("xyzzy");
    QueryResult queryResult = QueryResult.builder().data(data).build();
    assertThrows(JedisConnectionException.class, () -> cache.put(key, queryResult));
}
Also used : QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) Test(org.junit.jupiter.api.Test)

Example 10 with QueryResult

use of com.yahoo.elide.datastores.aggregation.query.QueryResult in project elide by yahoo.

the class QueryEngineTest method testPagination.

/**
 * Test pagination.
 *
 * @throws Exception exception
 */
@Test
public void testPagination() throws Exception {
    Query query = Query.builder().source(playerStatsTable).metricProjection(playerStatsTable.getMetricProjection("lowScore")).dimensionProjection(playerStatsTable.getDimensionProjection("overallRating")).timeDimensionProjection(playerStatsTable.getTimeDimensionProjection("recordedDate")).pagination(new ImmutablePagination(0, 1, false, true)).build();
    QueryResult result = engine.executeQuery(query, transaction);
    List<Object> data = toList(result.getData());
    // Jon Doe,1234,72,Good,840,2019-07-12 00:00:00
    PlayerStats stats1 = new PlayerStats();
    stats1.setId("0");
    stats1.setLowScore(35);
    stats1.setOverallRating("Good");
    stats1.setRecordedDate(new Day(Date.valueOf("2019-07-12")));
    assertEquals(ImmutableList.of(stats1), data, "Returned record does not match");
    assertEquals(3, result.getPageTotals(), "Page totals does not match");
}
Also used : QueryResult(com.yahoo.elide.datastores.aggregation.query.QueryResult) Query(com.yahoo.elide.datastores.aggregation.query.Query) ImmutablePagination(com.yahoo.elide.datastores.aggregation.query.ImmutablePagination) PlayerStats(example.PlayerStats) Day(com.yahoo.elide.datastores.aggregation.timegrains.Day) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

QueryResult (com.yahoo.elide.datastores.aggregation.query.QueryResult)12 Test (org.junit.jupiter.api.Test)10 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)7 EntityProjection (com.yahoo.elide.core.request.EntityProjection)6 NativeQuery (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery)6 PlayerStats (example.PlayerStats)6 Query (com.yahoo.elide.datastores.aggregation.query.Query)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Pagination (com.yahoo.elide.core.request.Pagination)2 ImmutablePagination (com.yahoo.elide.datastores.aggregation.query.ImmutablePagination)2 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RequestScope (com.yahoo.elide.core.RequestScope)1 DataStoreIterable (com.yahoo.elide.core.datastore.DataStoreIterable)1 DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 BadRequestException (com.yahoo.elide.core.exceptions.BadRequestException)1 HttpStatus (com.yahoo.elide.core.exceptions.HttpStatus)1 HttpStatusException (com.yahoo.elide.core.exceptions.HttpStatusException)1