@Test public void testRemoveTimestampFromPartitionedTable() { try (TableModel model = new TableModel(configuration, "ABC", PartitionBy.DAY) .col("productId", ColumnType.INT) .col("productName", ColumnType.STRING) .col("category", ColumnType.SYMBOL) .col("price", ColumnType.DOUBLE) .timestamp() .col("supplier", ColumnType.SYMBOL)) { CairoTestUtils.create(model); } try (TableWriter writer = new TableWriter(configuration, "ABC")) { try { writer.removeColumn("timestamp"); Assert.fail(); } catch (CairoException ignore) { } } }
public void removeColumn(CharSequence name) { checkDistressed(); final int index = getColumnIndex(name); final int type = metadata.getColumnType(index); LOG.info().$("removing column '").utf8(name).$("' from ").$(path).$(); final int timestampIndex = metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX); boolean timestamp = index == timestampIndex; if (timestamp && partitionBy != PartitionBy.NONE) { throw CairoException.instance(0).put("Cannot remove timestamp from partitioned table"); } commit(); final CharSequence timestampColumnName = timestampIndex != -1 ? metadata.getColumnName(timestampIndex) : null; this.metaSwapIndex = removeColumnFromMeta(index); metaMem.close(); renameMetaToMetaPrev(name); writeRestoreMetaTodo(name); renameSwapMetaToMeta(name); removeColumn(index); removeSymbolMapWriter(index); columnCount--; if (timestamp) { maxTimestamp = prevMaxTimestamp = Long.MIN_VALUE; minTimestamp = prevMinTimestamp = Long.MAX_VALUE; timestampSetter = value -> { }; } try { openMetaFile(); removeTodoFile(); removeColumnFiles(name, type, REMOVE_OR_LOG); } catch (CairoException err) { throwDistressException(err); } bumpStructureVersion(); metadata.removeColumn(name); if (timestamp) { metadata.setTimestampIndex(-1); } else if (timestampColumnName != null) { metadata.setTimestampIndex(metadata.getColumnIndex(timestampColumnName)); } LOG.info().$("REMOVED column '").utf8(name).$("' from ").$(path).$(); }
TableWriter implements Closeable { public void removeColumn(CharSequence name) { checkDistressed(); final int index = getColumnIndex(name); final int type = metadata.getColumnType(index); LOG.info().$("removing column '").utf8(name).$("' from ").$(path).$(); final int timestampIndex = metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX); boolean timestamp = index == timestampIndex; if (timestamp && partitionBy != PartitionBy.NONE) { throw CairoException.instance(0).put("Cannot remove timestamp from partitioned table"); } commit(); final CharSequence timestampColumnName = timestampIndex != -1 ? metadata.getColumnName(timestampIndex) : null; this.metaSwapIndex = removeColumnFromMeta(index); metaMem.close(); renameMetaToMetaPrev(name); writeRestoreMetaTodo(name); renameSwapMetaToMeta(name); removeColumn(index); removeSymbolMapWriter(index); columnCount--; if (timestamp) { maxTimestamp = prevMaxTimestamp = Long.MIN_VALUE; minTimestamp = prevMinTimestamp = Long.MAX_VALUE; timestampSetter = value -> { }; } try { openMetaFile(); removeTodoFile(); removeColumnFiles(name, type, REMOVE_OR_LOG); } catch (CairoException err) { throwDistressException(err); } bumpStructureVersion(); metadata.removeColumn(name); if (timestamp) { metadata.setTimestampIndex(-1); } else if (timestampColumnName != null) { metadata.setTimestampIndex(metadata.getColumnIndex(timestampColumnName)); } LOG.info().$("REMOVED column '").utf8(name).$("' from ").$(path).$(); } }
TableWriter implements Closeable { public void removeColumn(CharSequence name) { checkDistressed(); final int index = getColumnIndex(name); final int type = metadata.getColumnType(index); LOG.info().$("removing column '").utf8(name).$("' from ").$(path).$(); final int timestampIndex = metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX); boolean timestamp = index == timestampIndex; if (timestamp && partitionBy != PartitionBy.NONE) { throw CairoException.instance(0).put("Cannot remove timestamp from partitioned table"); } commit(); final CharSequence timestampColumnName = timestampIndex != -1 ? metadata.getColumnName(timestampIndex) : null; this.metaSwapIndex = removeColumnFromMeta(index); metaMem.close(); renameMetaToMetaPrev(name); writeRestoreMetaTodo(name); renameSwapMetaToMeta(name); removeColumn(index); removeSymbolMapWriter(index); columnCount--; if (timestamp) { maxTimestamp = prevMaxTimestamp = Long.MIN_VALUE; minTimestamp = prevMinTimestamp = Long.MAX_VALUE; timestampSetter = value -> { }; } try { openMetaFile(); removeTodoFile(); removeColumnFiles(name, type, REMOVE_OR_LOG); } catch (CairoException err) { throwDistressException(err); } bumpStructureVersion(); metadata.removeColumn(name); if (timestamp) { metadata.setTimestampIndex(-1); } else if (timestampColumnName != null) { metadata.setTimestampIndex(metadata.getColumnIndex(timestampColumnName)); } LOG.info().$("REMOVED column '").utf8(name).$("' from ").$(path).$(); } TableWriter(CairoConfiguration configuration, CharSequence name);  TableWriter(CairoConfiguration configuration, CharSequence name, MessageBus messageBus);  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager
    );  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager,
            CharSequence root
    ); }
TableWriter implements Closeable { public void removeColumn(CharSequence name) { checkDistressed(); final int index = getColumnIndex(name); final int type = metadata.getColumnType(index); LOG.info().$("removing column '").utf8(name).$("' from ").$(path).$(); final int timestampIndex = metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX); boolean timestamp = index == timestampIndex; if (timestamp && partitionBy != PartitionBy.NONE) { throw CairoException.instance(0).put("Cannot remove timestamp from partitioned table"); } commit(); final CharSequence timestampColumnName = timestampIndex != -1 ? metadata.getColumnName(timestampIndex) : null; this.metaSwapIndex = removeColumnFromMeta(index); metaMem.close(); renameMetaToMetaPrev(name); writeRestoreMetaTodo(name); renameSwapMetaToMeta(name); removeColumn(index); removeSymbolMapWriter(index); columnCount--; if (timestamp) { maxTimestamp = prevMaxTimestamp = Long.MIN_VALUE; minTimestamp = prevMinTimestamp = Long.MAX_VALUE; timestampSetter = value -> { }; } try { openMetaFile(); removeTodoFile(); removeColumnFiles(name, type, REMOVE_OR_LOG); } catch (CairoException err) { throwDistressException(err); } bumpStructureVersion(); metadata.removeColumn(name); if (timestamp) { metadata.setTimestampIndex(-1); } else if (timestampColumnName != null) { metadata.setTimestampIndex(metadata.getColumnIndex(timestampColumnName)); } LOG.info().$("REMOVED column '").utf8(name).$("' from ").$(path).$(); } TableWriter(CairoConfiguration configuration, CharSequence name);  TableWriter(CairoConfiguration configuration, CharSequence name, MessageBus messageBus);  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager
    );  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager,
            CharSequence root
    ); static TimestampFormat selectPartitionDirFmt(int partitionBy); void addColumn(CharSequence name, int type); void addColumn(
            CharSequence name,
            int type,
            int symbolCapacity,
            boolean symbolCacheFlag,
            boolean isIndexed,
            int indexValueBlockCapacity,
            boolean isSequential
    ); void addIndex(CharSequence columnName, int indexValueBlockSize); void changeCacheFlag(int columnIndex, boolean cache); @Override void close(); void commit(); void commit(int commitMode); int getColumnIndex(CharSequence name); long getMaxTimestamp(); RecordMetadata getMetadata(); CharSequence getName(); int getPartitionBy(); long getStructureVersion(); boolean inTransaction(); boolean isOpen(); Row newRow(long timestamp); Row newRow(); long partitionNameToTimestamp(CharSequence partitionName); void removeColumn(CharSequence name); void renameColumn(CharSequence currentName, CharSequence newName); boolean removePartition(long timestamp); void rollback(); void setLifecycleManager(LifecycleManager lifecycleManager); long size(); @Override String toString(); void transferLock(long lockFd); final void truncate(); void updateMetadataVersion(); void warmUp(); }
TableWriter implements Closeable { public void removeColumn(CharSequence name) { checkDistressed(); final int index = getColumnIndex(name); final int type = metadata.getColumnType(index); LOG.info().$("removing column '").utf8(name).$("' from ").$(path).$(); final int timestampIndex = metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX); boolean timestamp = index == timestampIndex; if (timestamp && partitionBy != PartitionBy.NONE) { throw CairoException.instance(0).put("Cannot remove timestamp from partitioned table"); } commit(); final CharSequence timestampColumnName = timestampIndex != -1 ? metadata.getColumnName(timestampIndex) : null; this.metaSwapIndex = removeColumnFromMeta(index); metaMem.close(); renameMetaToMetaPrev(name); writeRestoreMetaTodo(name); renameSwapMetaToMeta(name); removeColumn(index); removeSymbolMapWriter(index); columnCount--; if (timestamp) { maxTimestamp = prevMaxTimestamp = Long.MIN_VALUE; minTimestamp = prevMinTimestamp = Long.MAX_VALUE; timestampSetter = value -> { }; } try { openMetaFile(); removeTodoFile(); removeColumnFiles(name, type, REMOVE_OR_LOG); } catch (CairoException err) { throwDistressException(err); } bumpStructureVersion(); metadata.removeColumn(name); if (timestamp) { metadata.setTimestampIndex(-1); } else if (timestampColumnName != null) { metadata.setTimestampIndex(metadata.getColumnIndex(timestampColumnName)); } LOG.info().$("REMOVED column '").utf8(name).$("' from ").$(path).$(); } TableWriter(CairoConfiguration configuration, CharSequence name);  TableWriter(CairoConfiguration configuration, CharSequence name, MessageBus messageBus);  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager
    );  TableWriter(
            CairoConfiguration configuration,
            CharSequence name,
            @Nullable MessageBus messageBus,
            boolean lock,
            LifecycleManager lifecycleManager,
            CharSequence root
    ); static TimestampFormat selectPartitionDirFmt(int partitionBy); void addColumn(CharSequence name, int type); void addColumn(
            CharSequence name,
            int type,
            int symbolCapacity,
            boolean symbolCacheFlag,
            boolean isIndexed,
            int indexValueBlockCapacity,
            boolean isSequential
    ); void addIndex(CharSequence columnName, int indexValueBlockSize); void changeCacheFlag(int columnIndex, boolean cache); @Override void close(); void commit(); void commit(int commitMode); int getColumnIndex(CharSequence name); long getMaxTimestamp(); RecordMetadata getMetadata(); CharSequence getName(); int getPartitionBy(); long getStructureVersion(); boolean inTransaction(); boolean isOpen(); Row newRow(long timestamp); Row newRow(); long partitionNameToTimestamp(CharSequence partitionName); void removeColumn(CharSequence name); void renameColumn(CharSequence currentName, CharSequence newName); boolean removePartition(long timestamp); void rollback(); void setLifecycleManager(LifecycleManager lifecycleManager); long size(); @Override String toString(); void transferLock(long lockFd); final void truncate(); void updateMetadataVersion(); void warmUp();  }