use of org.hisp.dhis.analytics.AnalyticsTablePartition in project dhis2-core by dhis2.
the class PartitionUtilsTest method testGetTablePartitions.
@Test
void testGetTablePartitions() {
List<AnalyticsTableColumn> dimensions = Lists.newArrayList(new AnalyticsTableColumn("dx", TEXT, "dx"));
List<AnalyticsTableColumn> values = Lists.newArrayList(new AnalyticsTableColumn("value", DOUBLE, "value"));
AnalyticsTable tA = new AnalyticsTable(AnalyticsTableType.DATA_VALUE, dimensions, values);
tA.addPartitionTable(2010, new DateTime(2010, 1, 1, 0, 0).toDate(), new DateTime(2010, 12, 31, 0, 0).toDate());
tA.addPartitionTable(2011, new DateTime(2011, 1, 1, 0, 0).toDate(), new DateTime(2011, 12, 31, 0, 0).toDate());
AnalyticsTable tB = new AnalyticsTable(AnalyticsTableType.ORG_UNIT_TARGET, dimensions, values);
List<AnalyticsTablePartition> partitions = PartitionUtils.getTablePartitions(Lists.newArrayList(tA, tB));
assertEquals(3, partitions.size());
}
use of org.hisp.dhis.analytics.AnalyticsTablePartition in project dhis2-core by dhis2.
the class JdbcAnalyticsTableManagerTest method testGetRegularAnalyticsTable.
@Test
void testGetRegularAnalyticsTable() {
Date startTime = new DateTime(2019, 3, 1, 10, 0).toDate();
List<Integer> dataYears = Lists.newArrayList(2018, 2019);
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(startTime).build();
when(jdbcTemplate.queryForList(Mockito.anyString(), ArgumentMatchers.<Class<Integer>>any())).thenReturn(dataYears);
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertEquals(1, tables.size());
AnalyticsTable table = tables.get(0);
assertNotNull(table);
assertNotNull(table.getTablePartitions());
assertEquals(2, table.getTablePartitions().size());
AnalyticsTablePartition partitionA = table.getTablePartitions().get(0);
AnalyticsTablePartition partitionB = table.getTablePartitions().get(1);
assertNotNull(partitionA);
assertNotNull(partitionA.getStartDate());
assertNotNull(partitionA.getEndDate());
assertEquals(partitionA.getYear().intValue(), new DateTime(partitionA.getStartDate()).getYear());
assertNotNull(partitionB);
assertNotNull(partitionB.getStartDate());
assertNotNull(partitionB.getEndDate());
assertEquals(partitionB.getYear().intValue(), new DateTime(partitionB.getStartDate()).getYear());
}
use of org.hisp.dhis.analytics.AnalyticsTablePartition in project dhis2-core by dhis2.
the class AnalyticsIndexHelper method getIndexes.
/**
* Returns a queue of analytics table indexes.
*
* @param partitions the list of {@link AnalyticsTablePartition}.
* @return a {@link java.util.concurrent.ConcurrentLinkedQueue} of indexes.
*/
public static List<AnalyticsIndex> getIndexes(final List<AnalyticsTablePartition> partitions) {
final List<AnalyticsIndex> indexes = new ArrayList<>();
for (final AnalyticsTablePartition partition : partitions) {
final List<AnalyticsTableColumn> columns = partition.getMasterTable().getDimensionColumns();
for (final AnalyticsTableColumn col : columns) {
if (!col.isSkipIndex()) {
final List<String> indexColumns = col.hasIndexColumns() ? col.getIndexColumns() : Lists.newArrayList(col.getName());
indexes.add(new AnalyticsIndex(partition.getTempTableName(), indexColumns, col.getIndexType()));
maybeAddTextLowerIndex(indexes, partition.getTempTableName(), col, indexColumns);
}
}
}
return indexes;
}
use of org.hisp.dhis.analytics.AnalyticsTablePartition in project dhis2-core by dhis2.
the class JdbcCompletenessTableManager method removeUpdatedData.
@Override
public void removeUpdatedData(List<AnalyticsTable> tables) {
AnalyticsTablePartition partition = getLatestTablePartition(tables);
String sql = "delete from " + quote(getAnalyticsTableType().getTableName()) + " ax " + "where ax.id in (" + "select (ds.uid || '-' || ps.iso || '-' || ou.uid || '-' || ao.uid) as id " + "from completedatasetregistration cdr " + "inner join dataset ds on cdr.datasetid=ds.datasetid " + "inner join _periodstructure ps on cdr.periodid=ps.periodid " + "inner join organisationunit ou on cdr.sourceid=ou.organisationunitid " + "inner join categoryoptioncombo ao on cdr.attributeoptioncomboid=ao.categoryoptioncomboid " + "where cdr.lastupdated >= '" + getLongDateString(partition.getStartDate()) + "' " + "and cdr.lastupdated < '" + getLongDateString(partition.getEndDate()) + "')";
invokeTimeAndLog(sql, "Remove updated data values");
}
use of org.hisp.dhis.analytics.AnalyticsTablePartition in project dhis2-core by dhis2.
the class JdbcAnalyticsTableManagerTest method testGetLatestAnalyticsTable.
@Test
void testGetLatestAnalyticsTable() {
Date lastFullTableUpdate = new DateTime(2019, 3, 1, 2, 0).toDate();
Date lastLatestPartitionUpdate = new DateTime(2019, 3, 1, 9, 0).toDate();
Date startTime = new DateTime(2019, 3, 1, 10, 0).toDate();
AnalyticsTableUpdateParams params = AnalyticsTableUpdateParams.newBuilder().withStartTime(startTime).withLatestPartition().build();
List<Map<String, Object>> queryResp = Lists.newArrayList();
queryResp.add(ImmutableMap.of("dataelementid", 1));
when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE)).thenReturn(lastFullTableUpdate);
when(systemSettingManager.getDateSetting(SettingKey.LAST_SUCCESSFUL_LATEST_ANALYTICS_PARTITION_UPDATE)).thenReturn(lastLatestPartitionUpdate);
when(jdbcTemplate.queryForList(Mockito.anyString())).thenReturn(queryResp);
List<AnalyticsTable> tables = subject.getAnalyticsTables(params);
assertEquals(1, tables.size());
AnalyticsTable table = tables.get(0);
assertNotNull(table);
assertNotNull(table.getTablePartitions());
assertEquals(1, table.getTablePartitions().size());
AnalyticsTablePartition partition = table.getLatestPartition();
assertNotNull(partition);
assertTrue(partition.isLatestPartition());
assertEquals(lastFullTableUpdate, partition.getStartDate());
assertEquals(startTime, partition.getEndDate());
}
Aggregations