@Test public void alter() throws Exception { SourceKey tableKey = new SourceKey(meta.getTableName()); com.fr.swift.db.Table table = SwiftDatabase.getInstance().createTable(tableKey, meta); Importer inserter = getInserter(table, new HistoryLineSourceAlloter(tableKey, new LineAllotRule(10))); inserter.importResultSet(new LimitedResultSet(new SupplierResultSet(meta, new Supplier<Row>() { @Override public Row get() { A a = new A(); return new ListBasedRow(Arrays.<Object>asList(a.l, a.s)); } }), 25)); new DropColumnAction(new MetaDataColumnEntity("s", Types.VARCHAR)).alter(table); table = SwiftDatabase.getInstance().getTable(tableKey); checkMeta(table); checkSeg(table); }
@Override public void alter(final Table table) { if (!existsColumn(table.getMetadata())) { SwiftLoggers.getLogger().warn("column {} is not present in {}, will drop nothing", relatedColumnMeta, table); return; } SwiftLoggers.getLogger().info("drop column {} of {}", relatedColumnMeta, table); List<SegmentKey> segKeys = SwiftContext.get().getBean(SegmentService.class).getSegmentKeys(table.getSourceKey()); for (final SegmentKey segKey : segKeys) { if (segKey.getStoreType().isTransient()) { ResourceDiscovery.getInstance().releaseColumn(segKey.getSwiftSchema(), segKey.getTable(), new ColumnKey(relatedColumnMeta.getName())); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().asBackup().setColumnId(relatedColumnMeta.getColumnId()).build()); continue; } int currentDir = CubeUtil.getCurrentDir(segKey.getTable()); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().setTempDir(currentDir).setColumnId(relatedColumnMeta.getColumnId()).build()); } alterMeta(table); }
DropColumnAction extends BaseAlterTableAction { @Override public void alter(final Table table) { if (!existsColumn(table.getMetadata())) { SwiftLoggers.getLogger().warn("column {} is not present in {}, will drop nothing", relatedColumnMeta, table); return; } SwiftLoggers.getLogger().info("drop column {} of {}", relatedColumnMeta, table); List<SegmentKey> segKeys = SwiftContext.get().getBean(SegmentService.class).getSegmentKeys(table.getSourceKey()); for (final SegmentKey segKey : segKeys) { if (segKey.getStoreType().isTransient()) { ResourceDiscovery.getInstance().releaseColumn(segKey.getSwiftSchema(), segKey.getTable(), new ColumnKey(relatedColumnMeta.getName())); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().asBackup().setColumnId(relatedColumnMeta.getColumnId()).build()); continue; } int currentDir = CubeUtil.getCurrentDir(segKey.getTable()); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().setTempDir(currentDir).setColumnId(relatedColumnMeta.getColumnId()).build()); } alterMeta(table); } }
DropColumnAction extends BaseAlterTableAction { @Override public void alter(final Table table) { if (!existsColumn(table.getMetadata())) { SwiftLoggers.getLogger().warn("column {} is not present in {}, will drop nothing", relatedColumnMeta, table); return; } SwiftLoggers.getLogger().info("drop column {} of {}", relatedColumnMeta, table); List<SegmentKey> segKeys = SwiftContext.get().getBean(SegmentService.class).getSegmentKeys(table.getSourceKey()); for (final SegmentKey segKey : segKeys) { if (segKey.getStoreType().isTransient()) { ResourceDiscovery.getInstance().releaseColumn(segKey.getSwiftSchema(), segKey.getTable(), new ColumnKey(relatedColumnMeta.getName())); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().asBackup().setColumnId(relatedColumnMeta.getColumnId()).build()); continue; } int currentDir = CubeUtil.getCurrentDir(segKey.getTable()); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().setTempDir(currentDir).setColumnId(relatedColumnMeta.getColumnId()).build()); } alterMeta(table); } DropColumnAction(SwiftMetaDataColumn relatedColumnMeta); }
DropColumnAction extends BaseAlterTableAction { @Override public void alter(final Table table) { if (!existsColumn(table.getMetadata())) { SwiftLoggers.getLogger().warn("column {} is not present in {}, will drop nothing", relatedColumnMeta, table); return; } SwiftLoggers.getLogger().info("drop column {} of {}", relatedColumnMeta, table); List<SegmentKey> segKeys = SwiftContext.get().getBean(SegmentService.class).getSegmentKeys(table.getSourceKey()); for (final SegmentKey segKey : segKeys) { if (segKey.getStoreType().isTransient()) { ResourceDiscovery.getInstance().releaseColumn(segKey.getSwiftSchema(), segKey.getTable(), new ColumnKey(relatedColumnMeta.getName())); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().asBackup().setColumnId(relatedColumnMeta.getColumnId()).build()); continue; } int currentDir = CubeUtil.getCurrentDir(segKey.getTable()); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().setTempDir(currentDir).setColumnId(relatedColumnMeta.getColumnId()).build()); } alterMeta(table); } DropColumnAction(SwiftMetaDataColumn relatedColumnMeta); @Override void alter(final Table table); }
DropColumnAction extends BaseAlterTableAction { @Override public void alter(final Table table) { if (!existsColumn(table.getMetadata())) { SwiftLoggers.getLogger().warn("column {} is not present in {}, will drop nothing", relatedColumnMeta, table); return; } SwiftLoggers.getLogger().info("drop column {} of {}", relatedColumnMeta, table); List<SegmentKey> segKeys = SwiftContext.get().getBean(SegmentService.class).getSegmentKeys(table.getSourceKey()); for (final SegmentKey segKey : segKeys) { if (segKey.getStoreType().isTransient()) { ResourceDiscovery.getInstance().releaseColumn(segKey.getSwiftSchema(), segKey.getTable(), new ColumnKey(relatedColumnMeta.getName())); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().asBackup().setColumnId(relatedColumnMeta.getColumnId()).build()); continue; } int currentDir = CubeUtil.getCurrentDir(segKey.getTable()); FileUtil.delete(new CubePathBuilder(segKey).asAbsolute().setTempDir(currentDir).setColumnId(relatedColumnMeta.getColumnId()).build()); } alterMeta(table); } DropColumnAction(SwiftMetaDataColumn relatedColumnMeta); @Override void alter(final Table table);  }