dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #29206
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14728: Event query analytics, fixed issue with partitioning
------------------------------------------------------------
revno: 14728
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-04-07 15:58:32 +0200
message:
Event query analytics, fixed issue with partitioning
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 2014-04-03 08:36:50 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java 2014-04-07 13:58:32 +0000
@@ -36,8 +36,10 @@
import static org.hisp.dhis.system.util.TextUtils.removeLast;
import static org.hisp.dhis.system.util.TextUtils.trimEnd;
+import java.util.Arrays;
import java.util.List;
+import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.analytics.event.EventAnalyticsManager;
@@ -91,7 +93,7 @@
if ( params.spansMultiplePartitions() )
{
- sql += getFromWhereMultiplePartitionsClause( params );
+ sql += getFromWhereMultiplePartitionsClause( params, Arrays.asList( "psi" ) );
}
else
{
@@ -174,13 +176,22 @@
public Grid getEvents( EventQueryParams params, Grid grid )
{
- String sql = "select psi,ps,executiondate,longitude,latitude,ouname,oucode," + getSelectColumns( params ) + " ";
+ List<String> fixedCols = Arrays.asList( "psi", "ps", "executiondate", "longitude", "latitude", "ouname", "oucode" );
+
+ String sql = "select " + getSelectString( fixedCols ) + getSelectColumns( params ) + " ";
// ---------------------------------------------------------------------
// Criteria
// ---------------------------------------------------------------------
- sql += getFromWhereClause( params, params.getPartitions().getSinglePartition() );
+ if ( params.spansMultiplePartitions() )
+ {
+ sql += getFromWhereMultiplePartitionsClause( params, fixedCols );
+ }
+ else
+ {
+ sql += getFromWhereClause( params, params.getPartitions().getSinglePartition() );
+ }
// ---------------------------------------------------------------------
// Sorting
@@ -325,13 +336,15 @@
return removeLast( sql, 1 );
}
- private String getFromWhereMultiplePartitionsClause( EventQueryParams params )
+ private String getFromWhereMultiplePartitionsClause( EventQueryParams params, List<String> fixedColumns )
{
+ String fixedCols = getSelectString( fixedColumns );
+
String sql = "from (";
for ( String partition : params.getPartitions().getPartitions() )
{
- sql += "select psi, " + getSelectColumns( params );
+ sql += "select " + fixedCols + getSelectColumns( params );
sql += " " + getFromWhereClause( params, partition );
@@ -428,4 +441,15 @@
return item.isNumeric() ? sqlFilter : sqlFilter.toLowerCase();
}
+
+ /**
+ * Creates a comma separated string based on the items in the given lists.
+ * Appends a comma at the end of the string if not empty.
+ */
+ private String getSelectString( List<String> columns )
+ {
+ String fixedCols = StringUtils.join( columns, ", " );
+
+ return StringUtils.defaultIfEmpty( fixedCols + ", ", fixedCols );
+ }
}