JdbcAnalyticsManager implements AnalyticsManager { @Override @Async public Future<Map<String, Object>> getAggregatedDataValues( DataQueryParams params, AnalyticsTableType tableType, int maxLimit ) { assertQuery( params ); try { ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = params.getDataPeriodAggregationPeriodMap(); if ( params.isDisaggregation() && params.hasDataPeriodType() ) { params = DataQueryParams.newBuilder( params ) .withDataPeriodsForAggregationPeriods( dataPeriodAggregationPeriodMap ) .build(); params = queryPlanner.assignPartitionsFromQueryPeriods( params, tableType ); } String sql = getSelectClause( params ); sql += getFromClause( params ); sql += getWhereClause( params, tableType ); sql += getGroupByClause( params ); if ( params.hasMeasureCriteria() && params.isDataType( DataType.NUMERIC ) ) { sql += getMeasureCriteriaSql( params ); } log.debug( sql ); Map<String, Object> map; try { map = getKeyValueMap( params, sql, maxLimit ); } catch ( BadSqlGrammarException ex ) { log.info( AnalyticsUtils.ERR_MSG_TABLE_NOT_EXISTING, ex ); return new AsyncResult<>( Maps.newHashMap() ); } replaceDataPeriodsWithAggregationPeriods( map, params, dataPeriodAggregationPeriodMap ); return new AsyncResult<>( map ); } catch ( DataAccessResourceFailureException ex ) { log.warn( ErrorCode.E7131.getMessage(), ex ); throw new QueryRuntimeException( ErrorCode.E7131, ex ); } catch ( RuntimeException ex ) { log.error( DebugUtils.getStackTrace( ex ) ); throw ex; } } JdbcAnalyticsManager( QueryPlanner queryPlanner, @Qualifier( "readOnlyJdbcTemplate" ) JdbcTemplate jdbcTemplate ); @Override @Async Future<Map<String, Object>> getAggregatedDataValues( DataQueryParams params, AnalyticsTableType tableType, int maxLimit ); @Override void replaceDataPeriodsWithAggregationPeriods( Map<String, Object> dataValueMap,
        DataQueryParams params, ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap );  }
@Test public void verifyQueryGeneratedWhenDataElementHasLastAggregationType() { DataQueryParams params = createParams( AggregationType.LAST ); subject.getAggregatedDataValues( params, AnalyticsTableType.DATA_VALUE, 20000 ); assertExpectedSql( "desc" ); }
@Test public void verifyQueryGeneratedWhenDataElementHasLastAvgOrgUnitAggregationType() { DataQueryParams params = createParams( AggregationType.LAST_AVERAGE_ORG_UNIT ); subject.getAggregatedDataValues( params, AnalyticsTableType.DATA_VALUE, 20000 ); assertExpectedSql( "desc" ); }
@Test public void verifyQueryGeneratedWhenDataElementHasLastInPeriodAggregationType() { DataQueryParams params = createParams( AggregationType.LAST_IN_PERIOD ); subject.getAggregatedDataValues( params, AnalyticsTableType.DATA_VALUE, 20000 ); assertExpectedLastSql( "desc" ); }
@Test public void verifyQueryGeneratedWhenDataElementHasLastInPeriodAvgOrgUnitAggregationType() { DataQueryParams params = createParams( AggregationType.LAST_IN_PERIOD_AVERAGE_ORG_UNIT ); subject.getAggregatedDataValues( params, AnalyticsTableType.DATA_VALUE, 20000 ); assertExpectedLastSql( "desc" ); }