← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14779: Event analytics, fixed bug with query planner and partitions

 

------------------------------------------------------------
revno: 14779
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2014-04-10 23:12:18 +0200
message:
  Event analytics, fixed bug with query planner and partitions
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/QueryPlanner.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/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.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	2014-04-10 20:40:06 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2014-04-10 21:12:18 +0000
@@ -1142,30 +1142,7 @@
     {
         return getDimensionOptions( key ) != null ? getDimensionOptions( key ) : getFilterOptions( key );
     }
-    
-    /**
-     * Replaces the items for the dimension or filter identified by the given key.
-     * No action is taken if no dimensions or filters exist.
-     */
-    public void replaceDimensionOrFilterOptions( String key, List<NameableObject> items )
-    {
-        int dimensionIndex = dimensions.indexOf( new BaseDimensionalObject( key ) );
-        
-        if ( dimensionIndex != -1 )
-        {
-            DimensionalObject dim = dimensions.get( dimensionIndex );
-            dimensions.set( dimensionIndex, new BaseDimensionalObject( dim.getDimension(), dim.getDimensionType(), dim.getDimensionName(), items ) );            
-        }
-        
-        int filterIndex = filters.indexOf( new BaseDimensionalObject( key ) );
-        
-        if ( filterIndex != -1 )
-        {
-            DimensionalObject flt = filters.get( filterIndex );
-            filters.set( filterIndex, new BaseDimensionalObject( flt.getDimension(), flt.getDimensionType(), flt.getDimensionName(), items ) );
-        }
-    }
-    
+        
     /**
      * Retrieves the options for the given dimension identifier. If the dx dimension
      * is specified, all concrete dimensions (in|de|dc|ds) are returned as a single

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java	2014-04-08 18:25:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/QueryPlanner.java	2014-04-10 21:12:18 +0000
@@ -96,6 +96,14 @@
     List<DataQueryParams> groupByOrgUnitLevel( DataQueryParams params );
 
     /**
+     * Groups the given query into sub queries based on its periods and which 
+     * partition it should be executed against. Sets the partition table name on
+     * each query. Queries are grouped based on periods if appearing as a 
+     * dimension.
+     */
+    List<DataQueryParams> groupByPartition( DataQueryParams params, String tableName, String tableSuffix );
+    
+    /**
      * If periods appear as dimensions in the given query; groups the query into 
      * sub queries based on the period type of the periods. Sets the period type 
      * name on each query. If periods appear as filters; replaces the period filter

=== 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	2014-04-08 19:36:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2014-04-10 21:12:18 +0000
@@ -212,7 +212,7 @@
         
         List<DataQueryParams> queries = new ArrayList<DataQueryParams>();
         
-        List<DataQueryParams> groupedByPartition = groupByPartition( params, tableName );
+        List<DataQueryParams> groupedByPartition = groupByPartition( params, tableName, null );
         
         for ( DataQueryParams byPartition : groupedByPartition )
         {
@@ -388,13 +388,7 @@
     // Supportive - group by methods
     // -------------------------------------------------------------------------
     
-    /**
-     * Groups the given query into sub queries based on its periods and which 
-     * partition it should be executed against. Sets the partition table name on
-     * each query. Queries are grouped based on periods if appearing as a 
-     * dimension.
-     */
-    private List<DataQueryParams> groupByPartition( DataQueryParams params, String tableName )
+    public List<DataQueryParams> groupByPartition( DataQueryParams params, String tableName, String tableSuffix )
     {
         List<DataQueryParams> queries = new ArrayList<DataQueryParams>();
 
@@ -405,7 +399,7 @@
         }
         else if ( params.getPeriods() != null && !params.getPeriods().isEmpty() )
         {
-            ListMap<Partitions, NameableObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap( params.getPeriods(), tableName, null );
+            ListMap<Partitions, NameableObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap( params.getPeriods(), tableName, tableSuffix );
             
             for ( Partitions partitions : partitionPeriodMap.keySet() )
             {
@@ -418,7 +412,7 @@
         else if ( params.getFilterPeriods() != null && !params.getFilterPeriods().isEmpty() )
         {
             DataQueryParams query = params.instance();
-            query.setPartitions( PartitionUtils.getPartitions( params.getFilterPeriods(), tableName, null ) );
+            query.setPartitions( PartitionUtils.getPartitions( params.getFilterPeriods(), tableName, tableSuffix ) );
             queries.add( query );
         }
         else

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2014-04-10 20:40:06 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2014-04-10 21:12:18 +0000
@@ -28,15 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
-
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.analytics.DataQueryParams;
-import org.hisp.dhis.analytics.Partitions;
 import org.hisp.dhis.analytics.QueryPlanner;
 import org.hisp.dhis.analytics.event.EventAnalyticsManager;
 import org.hisp.dhis.analytics.event.EventAnalyticsService;
@@ -45,7 +42,6 @@
 import org.hisp.dhis.analytics.table.PartitionUtils;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.IllegalQueryException;
-import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -179,12 +175,12 @@
 
     private List<EventQueryParams> groupByPartition( EventQueryParams params, List<String> validPartitions )
     {
-        List<EventQueryParams> queries = new ArrayList<EventQueryParams>();
-        
         String tableSuffix = "_" + params.getProgram().getUid();
         
         if ( params.hasStartEndDate() )
         {
+            List<EventQueryParams> queries = new ArrayList<EventQueryParams>();
+            
             Period queryPeriod = new Period();
             queryPeriod.setStartDate( params.getStartDate() );
             queryPeriod.setEndDate( params.getEndDate() );
@@ -196,21 +192,13 @@
             {
                 queries.add( query );
             }
+            
+            return queries;
         }
         else // Aggregate only
         {
-            ListMap<Partitions, NameableObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap( params.getDimensionOrFilter( PERIOD_DIM_ID ), TABLE_PREFIX, tableSuffix );
-            
-            for ( Partitions partitions : partitionPeriodMap.keySet() )
-            {
-                EventQueryParams query = params.instance();
-                query.replaceDimensionOrFilterOptions( DimensionalObject.PERIOD_DIM_ID, partitionPeriodMap.get( partitions ) );
-                query.setPartitions( partitions );
-                queries.add( query );
-            }
+            return convert( queryPlanner.groupByPartition( params, TABLE_PREFIX, tableSuffix ) );
         }
-        
-        return queries;
     }
         
     private static List<EventQueryParams> convert( List<DataQueryParams> params )