dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #25614
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12760: Event analytics, handling aggregate queries with start/end date spanning multiple years properly
------------------------------------------------------------
revno: 12760
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-10-16 23:11:00 +0200
message:
Event analytics, handling aggregate queries with start/end date spanning multiple years properly
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.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/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-10-16 19:06:05 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2013-10-16 21:11:00 +0000
@@ -32,6 +32,7 @@
import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
import static org.hisp.dhis.system.util.TextUtils.removeLast;
+import static org.hisp.dhis.system.util.TextUtils.trimEnd;
import static org.hisp.dhis.common.DimensionalObject.*;
import java.util.Arrays;
@@ -88,7 +89,14 @@
// Criteria
// ---------------------------------------------------------------------
- sql += getFromWhereClause( params );
+ if ( params.spansMultiplePartitions() )
+ {
+ sql += getFromWhereMultiplePartitionsClause( params );
+ }
+ else
+ {
+ sql += getFromWhereClause( params, params.getPartitions().getSinglePartition() );
+ }
// ---------------------------------------------------------------------
// Group by
@@ -176,7 +184,7 @@
// Criteria
// ---------------------------------------------------------------------
- sql += getFromWhereClause( params );
+ sql += getFromWhereClause( params, params.getPartitions().getSinglePartition() );
// ---------------------------------------------------------------------
// Sorting
@@ -255,7 +263,7 @@
{
String sql = "select count(psi) ";
- sql += getFromWhereClause( params );
+ sql += getFromWhereClause( params, params.getPartitions().getSinglePartition() );
int count = 0;
@@ -308,10 +316,28 @@
return removeLast( sql, 1 );
}
+
+ private String getFromWhereMultiplePartitionsClause( EventQueryParams params )
+ {
+ String sql = "from (";
+
+ for ( String partition : params.getPartitions().getPartitions() )
+ {
+ sql += "select psi, " + getSelectColumns( params );
+
+ sql += " " + getFromWhereClause( params, partition );
+
+ sql += "union all ";
+ }
+
+ sql = trimEnd( sql, "union all ".length() ) + ") as data ";
+
+ return sql;
+ }
- private String getFromWhereClause( EventQueryParams params )
+ private String getFromWhereClause( EventQueryParams params, String partition )
{
- String sql = "from " + params.getPartitions().getSinglePartition() + " ";
+ String sql = "from " + partition + " ";
if ( params.hasStartEndDate() )
{