use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtilsTest method testGetTablePeriodMapPrune.
@Test
public void testGetTablePeriodMapPrune() {
Set<String> validPartitions = new HashSet<>();
validPartitions.add(TBL + "_2000");
validPartitions.add(TBL + "_2002");
validPartitions.add(TBL + "_2003");
ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000April"), createPeriod("2000"), createPeriod("2001"), createPeriod("2001Oct"), createPeriod("2002Oct")), TBL, null, validPartitions);
assertEquals(4, map.size());
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002").add(TBL + "_2003")));
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtils method getPartitions.
public static Partitions getPartitions(Period period, String tablePrefix, String tableSuffix, Set<String> validPartitions) {
tablePrefix = StringUtils.trimToEmpty(tablePrefix);
tableSuffix = StringUtils.trimToEmpty(tableSuffix);
Partitions partitions = new Partitions();
int startYear = PeriodType.getCalendar().fromIso(period.getStartDate()).getYear();
int endYear = PeriodType.getCalendar().fromIso(period.getEndDate()).getYear();
while (startYear <= endYear) {
String name = tablePrefix + SEP + startYear + tableSuffix;
partitions.add(name.toLowerCase());
startYear++;
}
return partitions.prunePartitions(validPartitions);
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class DefaultQueryPlanner method groupByPartition.
// -------------------------------------------------------------------------
// Supportive - group by methods
// -------------------------------------------------------------------------
@Override
public List<DataQueryParams> groupByPartition(DataQueryParams params, QueryPlannerParams plannerParams) {
Set<String> validPartitions = partitionManager.getDataValueAnalyticsPartitions();
String tableName = plannerParams.getTableName();
String tableSuffix = plannerParams.getTableSuffix();
List<DataQueryParams> queries = new ArrayList<>();
if (params.isSkipPartitioning()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(new Partitions().add(tableName)).build();
queries.add(query);
} else if (!params.getPeriods().isEmpty()) {
ListMap<Partitions, DimensionalItemObject> partitionPeriodMap = PartitionUtils.getPartitionPeriodMap(params.getPeriods(), tableName, tableSuffix, validPartitions);
for (Partitions partitions : partitionPeriodMap.keySet()) {
if (partitions.hasAny()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPeriods(partitionPeriodMap.get(partitions)).withPartitions(partitions).build();
queries.add(query);
}
}
} else if (!params.getFilterPeriods().isEmpty()) {
Partitions partitions = PartitionUtils.getPartitions(params.getFilterPeriods(), tableName, tableSuffix, validPartitions);
if (partitions.hasAny()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(partitions).build();
queries.add(query);
}
} else if (params.hasStartEndDate()) {
Partitions partitions = PartitionUtils.getPartitions(params.getStartDate(), params.getEndDate(), tableName, tableSuffix, validPartitions);
if (partitions.hasAny()) {
DataQueryParams query = DataQueryParams.newBuilder(params).withPartitions(partitions).build();
queries.add(query);
}
} else {
throw new IllegalQueryException("Query does not contain any period dimension items");
}
if (queries.size() > 1) {
log.debug(String.format("Split on partition: %d", queries.size()));
}
return queries;
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtils method getPartitions.
/**
* Returns partitions for the given list of periods.
*
* @param period the period.
* @return partitions for the given list of periods.
*/
public static Partitions getPartitions(List<DimensionalItemObject> periods) {
final Set<Integer> years = new HashSet<>();
periods.forEach(p -> {
Period period = (Period) p;
years.addAll(getYears(period));
});
return new Partitions(years);
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class DefaultEventQueryPlanner method withTableNameAndPartitions.
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
/**
* Sets table name and partitions on the given query.
*
* @param params the event query parameters.
* @return a {@link EventQueryParams}.
*/
private EventQueryParams withTableNameAndPartitions(EventQueryParams params) {
Partitions partitions = params.hasStartEndDate() ? PartitionUtils.getPartitions(params.getStartDate(), params.getEndDate()) : PartitionUtils.getPartitions(params.getAllPeriods());
String baseName = params.hasEnrollmentProgramIndicatorDimension() ? AnalyticsTableType.ENROLLMENT.getTableName() : AnalyticsTableType.EVENT.getTableName();
String tableName = PartitionUtils.getTableName(baseName, params.getProgram());
if (params.getCurrentUser() != null) {
partitionManager.filterNonExistingPartitions(partitions, tableName);
}
return new EventQueryParams.Builder(params).withTableName(tableName).withPartitions(partitions).build();
}
Aggregations