Search in sources :

Example 6 with NativeQuery

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery 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 NativeQuery

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery 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 NativeQuery

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery in project elide by yahoo.

the class SQLQueryEngine method getPageTotal.

private long getPageTotal(Query expandedQuery, NativeQuery sql, Query clientQuery, SqlTransaction sqlTransaction) {
    ConnectionDetails details = expandedQuery.getConnectionDetails();
    DataSource dataSource = details.getDataSource();
    SQLDialect dialect = details.getDialect();
    NativeQuery paginationSQL = toPageTotalSQL(expandedQuery, sql, dialect);
    if (paginationSQL == null) {
        // Only 1 record will be returned.
        return 1;
    }
    NamedParamPreparedStatement stmt = sqlTransaction.initializeStatement(paginationSQL.toString(), dataSource);
    // Supply the query parameters to the query
    supplyFilterQueryParameters(clientQuery, stmt, dialect);
    // Run the Pagination query and log the time spent.
    Long result = CoerceUtil.coerce(runQuery(stmt, paginationSQL.toString(), SINGLE_RESULT_MAPPER), Long.class);
    return (result != null) ? result : 0;
}
Also used : NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) SQLDialect(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect) DataSource(javax.sql.DataSource)

Example 9 with NativeQuery

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery in project elide by yahoo.

the class AggregationDataStoreTransactionTest method loadObjectsUsesCache.

@Test
public void loadObjectsUsesCache() {
    Mockito.reset(queryLogger);
    String cacheKey = "foo;" + queryKey;
    QueryResult queryResult = QueryResult.builder().data(DATA).build();
    NativeQuery myQuery = NativeQuery.builder().fromClause(playerStatsTable.getName()).projectionClause(" ").build();
    when(cache.get(cacheKey)).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);
    EntityProjection entityProjection = EntityProjection.builder().type(PlayerStats.class).build();
    assertEquals(DATA, Lists.newArrayList(transaction.loadObjects(entityProjection, scope)));
    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 : 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PlayerStats(example.PlayerStats) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

NativeQuery (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery)9 QueryResult (com.yahoo.elide.datastores.aggregation.query.QueryResult)7 EntityProjection (com.yahoo.elide.core.request.EntityProjection)5 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)5 Test (org.junit.jupiter.api.Test)5 Pagination (com.yahoo.elide.core.request.Pagination)4 PlayerStats (example.PlayerStats)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Query (com.yahoo.elide.datastores.aggregation.query.Query)3 VersionQuery (com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.VersionQuery)3 SQLDialect (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect)3 DataSource (javax.sql.DataSource)3 ResultSet (java.sql.ResultSet)2 ArrayList (java.util.ArrayList)2 Preconditions (com.google.common.base.Preconditions)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 PredicateExtractionVisitor (com.yahoo.elide.core.filter.expression.PredicateExtractionVisitor)1 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)1 PaginationImpl (com.yahoo.elide.core.pagination.PaginationImpl)1 Argument (com.yahoo.elide.core.request.Argument)1