@Override public void dropTempTable( AnalyticsTable table ) { dropTableCascade( table.getTempTableName() ); }
/** * Drops and creates the table partitions for the given analytics table. * * @param table the {@link AnalyticsTable}. */ protected void createTempTablePartitions( AnalyticsTable table ) { for ( AnalyticsTablePartition partition : table.getPartitionTables() ) { final String tableName = partition.getTempTableName(); final List<String> checks = getPartitionChecks( partition ); String sqlCreate = "create table " + tableName + " "; if ( !checks.isEmpty() ) { StringBuilder sqlCheck = new StringBuilder( "(" ); checks.stream().forEach( check -> sqlCheck.append( "check (" + check + "), " ) ); sqlCreate += TextUtils.removeLastComma( sqlCheck.toString() ) + ") "; } sqlCreate += "inherits (" + table.getTempTableName() + ") " + getTableOptions(); log.info( String.format( "Creating partition table: %s", tableName ) ); log.debug( "Create SQL: " + sqlCreate ); jdbcTemplate.execute( sqlCreate ); } }
@Override public void swapTable( AnalyticsTableUpdateParams params, AnalyticsTable table ) { boolean tableExists = partitionManager.tableExists( table.getTableName() ); boolean skipMasterTable = params.isPartialUpdate() && tableExists; log.info( String.format( "Swapping table, master table exists: %b, skip master table: %b", tableExists, skipMasterTable ) ); table.getPartitionTables().stream().forEach( p -> swapTable( p.getTempTableName(), p.getTableName() ) ); if ( !skipMasterTable ) { swapTable( table.getTempTableName(), table.getTableName() ); } else { table.getPartitionTables().stream().forEach( p -> swapInheritance( p.getTableName(),table.getTempTableName(), table.getTableName() ) ); dropTempTable( table ); } }
/** * Drops and creates the given analytics table. * * @param table the {@link AnalyticsTable}. */ protected void createTempTable( AnalyticsTable table ) { validateDimensionColumns( table.getDimensionColumns() ); final String tableName = table.getTempTableName(); String sqlCreate = "create table " + tableName + " ("; for ( AnalyticsTableColumn col : ListUtils.union( table.getDimensionColumns(), table.getValueColumns() ) ) { sqlCreate += col.getName() + " " + col.getDataType() + ","; } sqlCreate = TextUtils.removeLastComma( sqlCreate ) + ") " + getTableOptions(); log.info( String.format( "Creating table: %s, columns: %d", tableName, table.getDimensionColumns().size() ) ); log.debug( "Create SQL: " + sqlCreate ); jdbcTemplate.execute( sqlCreate ); }