use of org.hisp.dhis.analytics.AnalyticsIndex in project dhis2-core by dhis2.
the class DefaultAnalyticsTableService method update.
@Override
public void update(AnalyticsTableUpdateParams params, JobProgress progress) {
final int processNo = getProcessNo();
int tableUpdates = 0;
log.info(String.format("Analytics table update parameters: %s", params));
AnalyticsTableType tableType = getAnalyticsTableType();
Clock clock = new Clock(log).startClock().logTime(String.format("Starting update of type: %s, table name: '%s', processes: %d", tableType, tableType.getTableName(), processNo));
progress.startingStage("Validating Analytics Table " + tableType);
String validState = tableManager.validState();
progress.completedStage(validState);
if (validState != null || progress.isCancellationRequested()) {
return;
}
final List<AnalyticsTable> tables = tableManager.getAnalyticsTables(params);
if (tables.isEmpty()) {
clock.logTime(String.format("Table update aborted, no table or partitions to be updated: '%s'", tableType.getTableName()));
progress.startingStage("Table updates " + tableType);
progress.completedStage("Table updated aborted, no table or partitions to be updated");
return;
}
clock.logTime(String.format("Table update start: %s, earliest: %s, parameters: %s", tableType.getTableName(), getLongDateString(params.getFromDate()), params.toString()));
progress.startingStage("Performing pre-create table work");
progress.runStage(() -> tableManager.preCreateTables(params));
clock.logTime("Performed pre-create table work " + tableType);
progress.startingStage("Dropping temp tables " + tableType, tables.size());
dropTempTables(tables, progress);
clock.logTime("Dropped temp tables");
progress.startingStage("Creating analytics tables " + tableType, tables.size());
createTables(tables, progress);
clock.logTime("Created analytics tables");
List<AnalyticsTablePartition> partitions = PartitionUtils.getTablePartitions(tables);
progress.startingStage("Populating analytics tables " + tableType, partitions.size());
populateTables(params, partitions, progress);
clock.logTime("Populated analytics tables");
progress.startingStage("Invoking analytics table hooks " + tableType);
tableUpdates += progress.runStage(0, tableManager::invokeAnalyticsTableSqlHooks);
clock.logTime("Invoked analytics table hooks");
tableUpdates += applyAggregationLevels(tableType, partitions, progress);
clock.logTime("Applied aggregation levels");
if (tableUpdates > 0) {
progress.startingStage("Vacuuming tables " + tableType, partitions.size());
vacuumTables(partitions, progress);
clock.logTime("Tables vacuumed");
}
List<AnalyticsIndex> indexes = getIndexes(partitions);
progress.startingStage("Creating indexes " + tableType, indexes.size());
createIndexes(indexes, progress);
clock.logTime("Created indexes");
progress.startingStage("Analyzing analytics tables " + tableType, partitions.size());
analyzeTables(partitions, progress);
clock.logTime("Analyzed tables");
if (params.isLatestUpdate()) {
progress.startingStage("Removing updated and deleted data " + tableType);
tableManager.removeUpdatedData(tables);
clock.logTime("Removed updated and deleted data");
}
swapTables(params, tables, progress);
clock.logTime("Table update done: " + tableType.getTableName());
}
use of org.hisp.dhis.analytics.AnalyticsIndex in project dhis2-core by dhis2.
the class AnalyticsIndexHelperTest method testCreateIndexStatement.
@Test
void testCreateIndexStatement() {
// Given
final AnalyticsIndex someAnalyticsIndex = new AnalyticsIndex("table", List.of("column"), BTREE);
// When
final String statement = createIndexStatement(someAnalyticsIndex, EVENT);
// Then
assertThat(statement, containsString("create index \"in_column_table"));
assertThat(statement, containsString("on table using"));
assertThat(statement, containsString("btree (column)"));
}
use of org.hisp.dhis.analytics.AnalyticsIndex in project dhis2-core by dhis2.
the class AnalyticsIndexHelperTest method testGetIndexNameWithFunction.
@Test
void testGetIndexNameWithFunction() {
// Given
final AnalyticsIndex someAnalyticsIndex = new AnalyticsIndex("table", List.of("column"), BTREE, LOWER);
// When
final String statement = getIndexName(someAnalyticsIndex, EVENT);
// Then
assertThat(statement, containsString("\"in_column_table"));
assertThat(statement, containsString("_lower\""));
}
use of org.hisp.dhis.analytics.AnalyticsIndex in project dhis2-core by dhis2.
the class AnalyticsIndexHelperTest method testGetIndexName.
@Test
void testGetIndexName() {
// Given
final AnalyticsIndex someAnalyticsIndex = new AnalyticsIndex("table", List.of("column"), BTREE);
// When
final String statement = getIndexName(someAnalyticsIndex, EVENT);
// Then
assertThat(statement, containsString("\"in_column_table"));
}
use of org.hisp.dhis.analytics.AnalyticsIndex 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;
}
Aggregations