Search in sources :

Example 1 with AnalyticsIndex

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());
}
Also used : AnalyticsIndex(org.hisp.dhis.analytics.AnalyticsIndex) AnalyticsTable(org.hisp.dhis.analytics.AnalyticsTable) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) DateUtils.getLongDateString(org.hisp.dhis.util.DateUtils.getLongDateString) Clock(org.hisp.dhis.system.util.Clock) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition)

Example 2 with AnalyticsIndex

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)"));
}
Also used : AnalyticsIndex(org.hisp.dhis.analytics.AnalyticsIndex) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 3 with AnalyticsIndex

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\""));
}
Also used : AnalyticsIndex(org.hisp.dhis.analytics.AnalyticsIndex) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 4 with AnalyticsIndex

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"));
}
Also used : AnalyticsIndex(org.hisp.dhis.analytics.AnalyticsIndex) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 5 with AnalyticsIndex

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;
}
Also used : AnalyticsIndex(org.hisp.dhis.analytics.AnalyticsIndex) ArrayList(java.util.ArrayList) AnalyticsTableColumn(org.hisp.dhis.analytics.AnalyticsTableColumn) AnalyticsTablePartition(org.hisp.dhis.analytics.AnalyticsTablePartition)

Aggregations

AnalyticsIndex (org.hisp.dhis.analytics.AnalyticsIndex)5 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.jupiter.api.Test)3 AnalyticsTablePartition (org.hisp.dhis.analytics.AnalyticsTablePartition)2 ArrayList (java.util.ArrayList)1 AnalyticsTable (org.hisp.dhis.analytics.AnalyticsTable)1 AnalyticsTableColumn (org.hisp.dhis.analytics.AnalyticsTableColumn)1 AnalyticsTableType (org.hisp.dhis.analytics.AnalyticsTableType)1 Clock (org.hisp.dhis.system.util.Clock)1 DateUtils.getLongDateString (org.hisp.dhis.util.DateUtils.getLongDateString)1