Search in sources :

Example 16 with Partitions

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());
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.Test)

Example 17 with Partitions

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")));
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) Test(org.junit.Test)

Example 18 with Partitions

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);
}
Also used : Partitions(org.hisp.dhis.analytics.Partitions)

Example 19 with Partitions

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());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with Partitions

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());
}
Also used : EventQueryParams(org.hisp.dhis.analytics.event.EventQueryParams) Partitions(org.hisp.dhis.analytics.Partitions) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

Partitions (org.hisp.dhis.analytics.Partitions)20 Test (org.junit.jupiter.api.Test)9 DateTime (org.joda.time.DateTime)7 DhisSpringTest (org.hisp.dhis.DhisSpringTest)6 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)6 Test (org.junit.Test)5 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)4 HashSet (java.util.HashSet)3 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)3 Period (org.hisp.dhis.period.Period)3 ArrayList (java.util.ArrayList)2 DhisConvenienceTest.createPeriod (org.hisp.dhis.DhisConvenienceTest.createPeriod)2 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)1 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)1 ListMap (org.hisp.dhis.common.ListMap)1