use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtilsTest method testGetTablePeriodMapA.
@Test
public void testGetTablePeriodMapA() {
ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000S1"), createPeriod("2000S2"), createPeriod("2001S1"), createPeriod("2001S2"), createPeriod("2002S1")), TBL, null, null);
assertEquals(3, map.size());
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2002")));
assertEquals(2, map.get(new Partitions().add(TBL + "_2000")).size());
assertEquals(2, map.get(new Partitions().add(TBL + "_2001")).size());
assertEquals(1, map.get(new Partitions().add(TBL + "_2002")).size());
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class PartitionUtilsTest method testGetTablePeriodMapB.
@Test
public void testGetTablePeriodMapB() {
ListMap<Partitions, DimensionalItemObject> map = PartitionUtils.getPartitionPeriodMap(getList(createPeriod("2000April"), createPeriod("2000"), createPeriod("2001"), createPeriod("2001Oct"), createPeriod("2002Oct")), TBL, null, null);
assertEquals(5, map.size());
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2000").add(TBL + "_2001")));
assertTrue(map.keySet().contains(new Partitions().add(TBL + "_2001").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(String tablePrefix, String tableSuffix, Set<String> validPartitions) {
tablePrefix = StringUtils.trimToEmpty(tablePrefix);
tableSuffix = StringUtils.trimToEmpty(tableSuffix);
Partitions partitions = new Partitions();
String name = tablePrefix + tableSuffix;
partitions.add(name.toLowerCase());
return partitions.prunePartitions(validPartitions);
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class QueryPlannerTest method testWithTableTypeAndPartition.
@Test
void testWithTableTypeAndPartition() {
DataQueryParams params = DataQueryParams.newBuilder().withStartDate(getDate(2014, 4, 1)).withEndDate(getDate(2016, 8, 1)).build();
assertTrue(params.hasStartEndDate());
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withTableType(ANALYTICS_TABLE_TYPE).build();
DataQueryParams query = queryPlanner.withTableNameAndPartitions(params, plannerParams);
Partitions partitions = query.getPartitions();
Partitions expected = new Partitions(Sets.newHashSet(0, 2014, 2015, 2016));
assertNotNull(partitions);
assertEquals(4, partitions.getPartitions().size());
assertEquals(expected, partitions);
assertEquals(ANALYTICS_TABLE_TYPE.getTableName(), query.getTableName());
}
use of org.hisp.dhis.analytics.Partitions in project dhis2-core by dhis2.
the class EventQueryPlannerTest method testPlanAggregateQueryB.
@Test
void testPlanAggregateQueryB() {
EventQueryParams params = new EventQueryParams.Builder().withProgram(prA).withStartDate(new DateTime(2010, 3, 1, 0, 0).toDate()).withEndDate(new DateTime(2010, 9, 20, 0, 0).toDate()).withOrganisationUnits(Lists.newArrayList(ouA)).build();
List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
assertEquals(1, queries.size());
EventQueryParams query = queries.get(0);
assertEquals(new DateTime(2010, 3, 1, 0, 0).toDate(), query.getStartDate());
assertEquals(new DateTime(2010, 9, 20, 0, 0).toDate(), query.getEndDate());
Partitions partitions = query.getPartitions();
Partitions expected = new Partitions(Sets.newHashSet(2010));
assertEquals(1, partitions.getPartitions().size());
assertEquals(expected, partitions);
assertEquals(PartitionUtils.getTableName(AnalyticsTableType.EVENT.getTableName(), prA), query.getTableName());
}
Aggregations