dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #21381
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10103: Analytics, splitting queries on data sets if any
------------------------------------------------------------
revno: 10103
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-03-09 13:34:00 +0100
message:
Analytics, splitting queries on data sets if any
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-03-08 16:18:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-03-09 12:34:00 +0000
@@ -142,7 +142,7 @@
}
/**
- * Creates a mapping between the dimension names and the filter dimensions.
+ * Creates a mapping between dimension identifiers and filter dimensions.
*/
public ListMap<String, Dimension> getDimensionFilterMap()
{
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2013-03-08 16:18:21 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2013-03-09 12:34:00 +0000
@@ -200,6 +200,17 @@
}
// ---------------------------------------------------------------------
+ // Group by data set
+ // ---------------------------------------------------------------------
+
+ queries = splitByDimension( queries, DataQueryParams.DATASET_DIM_ID, optimalQueries );
+
+ if ( queries.size() >= optimalQueries )
+ {
+ return queries;
+ }
+
+ // ---------------------------------------------------------------------
// Group by organisation unit
// ---------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2013-02-26 18:33:01 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2013-03-09 12:34:00 +0000
@@ -54,11 +54,14 @@
import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.indicator.Indicator;
import org.hisp.dhis.indicator.IndicatorService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Cal;
+import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.period.QuarterlyPeriodType;
@@ -77,6 +80,9 @@
private DataElementService dataElementService;
@Autowired
+ private DataSetService dataSetService;
+
+ @Autowired
private DataElementCategoryService categoryService;
@Autowired
@@ -96,6 +102,11 @@
private DataElement deC;
private DataElement deD;
+ private DataSet dsA;
+ private DataSet dsB;
+ private DataSet dsC;
+ private DataSet dsD;
+
private DataElementCategoryOptionCombo coc;
private OrganisationUnit ouA;
@@ -109,6 +120,8 @@
@Override
public void setUpTest()
{
+ PeriodType pt = new MonthlyPeriodType();
+
inA = createIndicator( 'A', null );
indicatorService.addIndicator( inA );
@@ -123,6 +136,16 @@
dataElementService.addDataElement( deC );
dataElementService.addDataElement( deD );
+ dsA = createDataSet( 'A', pt );
+ dsB = createDataSet( 'B', pt );
+ dsC = createDataSet( 'C', pt );
+ dsD = createDataSet( 'D', pt );
+
+ dataSetService.addDataSet( dsA );
+ dataSetService.addDataSet( dsB );
+ dataSetService.addDataSet( dsC );
+ dataSetService.addDataSet( dsD );
+
coc = categoryService.getDefaultDataElementCategoryOptionCombo();
ouA = createOrganisationUnit( 'A' );
@@ -555,6 +578,31 @@
queryPlanner.planQuery( params, 4, ANALYTICS_TABLE_NAME );
}
+
+ /**
+ * Query spans 2 partitions. Splits in 2 queries for each partition, then
+ * splits in 2 queries on data sets to satisfy optimal for a total
+ * of 4 queries.
+ */
+ @Test
+ public void planQueryK()
+ {
+ DataQueryParams params = new DataQueryParams();
+ params.setDataSets( getList( dsA, dsB, dsC, dsD ) );
+ params.setOrganisationUnits( getList( ouA, ouB, ouC, ouD, ouE ) );
+ params.setPeriods( getList( createPeriod( "2000Q1" ), createPeriod( "2000Q2" ), createPeriod( "2000Q3" ), createPeriod( "2000Q4" ), createPeriod( "2001Q1" ), createPeriod( "2001Q2" ) ) );
+
+ List<DataQueryParams> queries = queryPlanner.planQuery( params, 4, ANALYTICS_TABLE_NAME );
+
+ assertEquals( 4, queries.size() );
+
+ for ( DataQueryParams query : queries )
+ {
+ assertTrue( samePeriodType( query.getPeriods() ) );
+ assertTrue( samePartition( query.getPeriods() ) );
+ assertDimensionNameNotNull( query );
+ }
+ }
// -------------------------------------------------------------------------
// Supportive methods