← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12752: Analytics, made query planner more flexible

 

------------------------------------------------------------
revno: 12752
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-10-16 21:21:01 +0200
message:
  Analytics, made query planner more flexible
modified:
  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/table/PartitionUtils.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/PartitionUtilsTest.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/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-09-29 17:20:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-10-16 19:21:01 +0000
@@ -350,7 +350,7 @@
         }
         else if ( params.getPeriods() != null && !params.getPeriods().isEmpty() )
         {
-            ListMap<Partitions, NameableObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap( params.getPeriods(), tableName );
+            ListMap<Partitions, NameableObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap( params.getPeriods(), tableName, null );
             
             for ( Partitions partitions : partitionPeriodMap.keySet() )
             {
@@ -363,7 +363,7 @@
         else if ( params.getFilterPeriods() != null && !params.getFilterPeriods().isEmpty() )
         {
             DataQueryParams query = params.instance();
-            query.setPartitions( PartitionUtils.getPartitions( params.getFilterPeriods(), tableName ) );
+            query.setPartitions( PartitionUtils.getPartitions( params.getFilterPeriods(), tableName, null ) );
             queries.add( query );
         }
         else

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java	2013-09-28 16:27:09 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/PartitionUtils.java	2013-10-16 19:21:01 +0000
@@ -68,42 +68,44 @@
     //TODO allow periods spanning more than two years
     //TODO optimize by including required filter periods only
     
-    public static Partitions getPartitions( Period period, String tableName )
+    public static Partitions getPartitions( Period period, String tablePrefix, String tableSuffix )
     {
+        String suffix = tableSuffix != null ? SEP + tableSuffix : "";
+        
         Partitions partitions = new Partitions();
         
         Period startYear = PERIODTYPE.createPeriod( period.getStartDate() );
         Period endYear = PERIODTYPE.createPeriod( period.getEndDate() );
         
-        partitions.add( tableName + SEP + startYear.getIsoDate() );
+        partitions.add( tablePrefix + SEP + startYear.getIsoDate() + suffix );
         
         if ( !startYear.equals( endYear ) )
         {
-            partitions.add( tableName + SEP + endYear.getIsoDate() );            
+            partitions.add( tablePrefix + SEP + endYear.getIsoDate() + suffix );            
         }
 
         return partitions;
     }
     
-    public static Partitions getPartitions( List<NameableObject> periods, String tableName )
+    public static Partitions getPartitions( List<NameableObject> periods, String tablePrefix, String tableSuffix )
     {
         Set<String> partitions = new HashSet<String>();
         
         for ( NameableObject period : periods )
         {
-            partitions.addAll( getPartitions( (Period) period, tableName ).getPartitions() );
+            partitions.addAll( getPartitions( (Period) period, tablePrefix, tableSuffix ).getPartitions() );
         }
         
         return new Partitions( new ArrayList<String>( partitions ) );
     }
     
-    public static ListMap<Partitions, NameableObject> getPartitionPeriodMap( List<NameableObject> periods, String tableName )
+    public static ListMap<Partitions, NameableObject> getPartitionPeriodMap( List<NameableObject> periods, String tablePrefix, String tableSuffix )
     {
         ListMap<Partitions, NameableObject> map = new ListMap<Partitions, NameableObject>();
         
         for ( NameableObject period : periods )
         {
-            map.putValue( getPartitions( (Period) period, tableName ), period );
+            map.putValue( getPartitions( (Period) period, tablePrefix, tableSuffix ), period );
         }
         
         return map;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/PartitionUtilsTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/PartitionUtilsTest.java	2013-08-31 18:07:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/table/PartitionUtilsTest.java	2013-10-16 19:21:01 +0000
@@ -52,13 +52,13 @@
     @Test
     public void testGetPartitions()
     {
-        assertEquals( new Partitions().add( TBL + "_2000" ), PartitionUtils.getPartitions( createPeriod( "200001" ), TBL ) );
-        assertEquals( new Partitions().add( TBL + "_2001" ), PartitionUtils.getPartitions( createPeriod( "200110" ), TBL ) );
-        assertEquals( new Partitions().add( TBL + "_2002" ), PartitionUtils.getPartitions( createPeriod( "2002Q2" ), TBL ) );
-        assertEquals( new Partitions().add( TBL + "_2003" ), PartitionUtils.getPartitions( createPeriod( "2003S2" ), TBL ) );
+        assertEquals( new Partitions().add( TBL + "_2000" ), PartitionUtils.getPartitions( createPeriod( "200001" ), TBL, null ) );
+        assertEquals( new Partitions().add( TBL + "_2001" ), PartitionUtils.getPartitions( createPeriod( "200110" ), TBL, null ) );
+        assertEquals( new Partitions().add( TBL + "_2002" ), PartitionUtils.getPartitions( createPeriod( "2002Q2" ), TBL, null ) );
+        assertEquals( new Partitions().add( TBL + "_2003" ), PartitionUtils.getPartitions( createPeriod( "2003S2" ), TBL, null ) );
         
-        assertEquals( new Partitions().add( TBL + "_2000" ).add( TBL + "_2001" ), PartitionUtils.getPartitions( createPeriod( "2000July" ), TBL ) );
-        assertEquals( new Partitions().add( TBL + "_2001" ).add( TBL + "_2002" ), PartitionUtils.getPartitions( createPeriod( "2001April" ), TBL ) );
+        assertEquals( new Partitions().add( TBL + "_2000" ).add( TBL + "_2001" ), PartitionUtils.getPartitions( createPeriod( "2000July" ), TBL, null ) );
+        assertEquals( new Partitions().add( TBL + "_2001" ).add( TBL + "_2002" ), PartitionUtils.getPartitions( createPeriod( "2001April" ), TBL, null ) );
     }
     
     public void getGetPartitionsMultiplePeriods()
@@ -68,14 +68,14 @@
         periods.add( createPeriod( "200105" ) );
         periods.add( createPeriod( "200108" ) );
         
-        assertEquals( new Partitions().add( TBL + "_2000" ).add( TBL + "_2001" ), PartitionUtils.getPartitions( periods, TBL ) );
+        assertEquals( new Partitions().add( TBL + "_2000" ).add( TBL + "_2001" ), PartitionUtils.getPartitions( periods, TBL, null ) );
     }
         
     @Test
     public void testGetTablePeriodMapA()
     {        
         ListMap<Partitions, NameableObject> map = PartitionUtils.getPartitionPeriodMap( getList( 
-            createPeriod( "2000S1" ), createPeriod( "2000S2" ), createPeriod( "2001S1" ), createPeriod( "2001S2" ), createPeriod( "2002S1" ) ), TBL );
+            createPeriod( "2000S1" ), createPeriod( "2000S2" ), createPeriod( "2001S1" ), createPeriod( "2001S2" ), createPeriod( "2002S1" ) ), TBL, null );
         
         assertEquals( 3, map.size() );
         
@@ -92,7 +92,7 @@
     public void testGetTablePeriodMapB()
     {        
         ListMap<Partitions, NameableObject> map = PartitionUtils.getPartitionPeriodMap( getList( 
-            createPeriod( "2000April" ), createPeriod( "2000" ), createPeriod( "2001" ), createPeriod( "2001Oct" ), createPeriod( "2002Oct" ) ), TBL );
+            createPeriod( "2000April" ), createPeriod( "2000" ), createPeriod( "2001" ), createPeriod( "2001Oct" ), createPeriod( "2002Oct" ) ), TBL, null );
 
         assertEquals( 5, map.size() );