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