/** * Shortens the given table name. * * @param table the table name. */ private static String shortenTableName( String table, AnalyticsTableType tableType ) { table = table.replaceAll( tableType.getTableName(), "ax" ); table = table.replaceAll( TABLE_TEMP_SUFFIX, StringUtils.EMPTY ); return table; }
@Override public Set<String> getEventAnalyticsPartitions() { if ( analyticsEventPartitions != null ) { return analyticsEventPartitions; } final String sql = "select table_name from information_schema.tables " + "where table_name like '" + AnalyticsTableType.EVENT.getTableName() + "%' " + "or table_name like '" + AnalyticsTableType.ENROLLMENT.getTableName() + "%' " + "and table_type = 'BASE TABLE'"; log.info( "Information schema event analytics SQL: " + sql ); Set<String> partitions = new HashSet<>( jdbcTemplate.queryForList( sql, String.class ) ); analyticsEventPartitions = partitions; return partitions; }
/** * Returns the analytics table name. */ protected String getTableName() { return getAnalyticsTableType().getTableName(); }
@Override public Set<String> getDataValueAnalyticsPartitions() { if ( analyticsPartitions != null ) { return analyticsPartitions; } final String sql = "select table_name from information_schema.tables " + "where table_name like '" + AnalyticsTableType.DATA_VALUE.getTableName() + "%' " + "and table_type = 'BASE TABLE'"; log.info( "Information schema analytics SQL: " + sql ); Set<String> partitions = new HashSet<>( jdbcTemplate.queryForList( sql, String.class ) ); analyticsPartitions = partitions; return partitions; }
/** * Generates a list of {@link AnalyticsTable} based on a list of years with data. * * @param dataYears the list of years with data. * @param dimensionColumns the list of dimension {@link AnalyticsTableColumn}. * @param valueColumns the list of value {@link AnalyticsTableColumn}. */ protected AnalyticsTable getAnalyticsTable( List<Integer> dataYears, List<AnalyticsTableColumn> dimensionColumns, List<AnalyticsTableColumn> valueColumns ) { Calendar calendar = PeriodType.getCalendar(); Collections.sort( dataYears ); String baseName = getAnalyticsTableType().getTableName(); AnalyticsTable table = new AnalyticsTable( baseName, dimensionColumns, valueColumns ); for ( Integer year : dataYears ) { table.addPartitionTable( year, PartitionUtils.getStartDate( calendar, year ), PartitionUtils.getEndDate( calendar, year ) ); } return table; }
/** * Adds raw data to the grid for the given data query parameters. * * @param params the {@link DataQueryParams}. * @param grid the grid. */ private void addRawData( DataQueryParams params, Grid grid ) { if ( !params.isSkipData() ) { QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder() .withTableName( AnalyticsTableType.DATA_VALUE.getTableName() ).build(); params = queryPlanner.withTableNameAndPartitions( params, plannerParams ); rawAnalyticsManager.getRawDataValues( params, grid ); } }
.withTableName( tableType.getTableName() ) .withQueryGroupers( queryGroupers ).build();
/** * Sets table name and partitions on the given query. * * @param params the event query parameters. * @return a {@link EventQueryParams}. */ private EventQueryParams withTableNameAndPartitions( EventQueryParams params ) { Partitions partitions = params.hasStartEndDate() ? PartitionUtils.getPartitions( params.getStartDate(), params.getEndDate() ) : PartitionUtils.getPartitions( params.getAllPeriods() ); String baseName = params.hasEnrollmentProgramIndicatorDimension() ? AnalyticsTableType.ENROLLMENT.getTableName() : AnalyticsTableType.EVENT.getTableName(); String tableName = PartitionUtils.getTableName( baseName, params.getProgram() ); return new EventQueryParams.Builder( params ) .withTableName( tableName ) .withPartitions( partitions ) .build(); }
.logTime( String.format( "Starting update: %s, processes: %d, org unit levels: %d", tableType.getTableName(), processNo, orgUnitLevelNo ) ); clock.logTime( "Table update start: " + tableType.getTableName() + ", earliest: " + earliest + ", parameters: " + params.toString() ); notifier.notify( jobId, "Performing pre-create table work, org unit levels: " + orgUnitLevelNo ); clock.logTime( "Table update done: " + tableType.getTableName() ); notifier.notify( jobId, "Table update done" );