Search in sources :

Example 1 with ShardDelta

use of io.trino.plugin.raptor.legacy.metadata.ShardDelta in project trino by trinodb.

the class RaptorStorageManager method shardDelta.

private static Collection<Slice> shardDelta(UUID oldShardUuid, Optional<ShardInfo> shardInfo) {
    List<ShardInfo> newShards = shardInfo.map(ImmutableList::of).orElse(ImmutableList.of());
    ShardDelta delta = new ShardDelta(ImmutableList.of(oldShardUuid), newShards);
    return ImmutableList.of(Slices.wrappedBuffer(SHARD_DELTA_CODEC.toJsonBytes(delta)));
}
Also used : ShardDelta(io.trino.plugin.raptor.legacy.metadata.ShardDelta) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo)

Example 2 with ShardDelta

use of io.trino.plugin.raptor.legacy.metadata.ShardDelta in project trino by trinodb.

the class TestRaptorStorageManager method testRewriter.

@Test
public void testRewriter() throws Exception {
    RaptorStorageManager manager = createRaptorStorageManager();
    long transactionId = TRANSACTION_ID;
    List<Long> columnIds = ImmutableList.of(3L, 7L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10));
    // create file with 2 rows
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello").row(456L, "bye").build();
    sink.appendPages(pages);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shardRecorder.getShards().size(), 1);
    // delete one row
    BitSet rowsToDelete = new BitSet();
    rowsToDelete.set(0);
    Collection<Slice> fragments = manager.rewriteShard(transactionId, OptionalInt.empty(), shards.get(0).getShardUuid(), rowsToDelete);
    Slice shardDelta = Iterables.getOnlyElement(fragments);
    ShardDelta shardDeltas = jsonCodec(ShardDelta.class).fromJson(shardDelta.getBytes());
    ShardInfo shardInfo = Iterables.getOnlyElement(shardDeltas.getNewShards());
    // check that output file has one row
    assertEquals(shardInfo.getRowCount(), 1);
    // check that storage file is same as backup file
    File storageFile = storageService.getStorageFile(shardInfo.getShardUuid());
    File backupFile = fileBackupStore.getBackupFile(shardInfo.getShardUuid());
    assertFileEquals(storageFile, backupFile);
    // verify recorded shard
    List<RecordedShard> recordedShards = shardRecorder.getShards();
    assertEquals(recordedShards.size(), 2);
    assertEquals(recordedShards.get(1).getTransactionId(), TRANSACTION_ID);
    assertEquals(recordedShards.get(1).getShardUuid(), shardInfo.getShardUuid());
}
Also used : BitSet(java.util.BitSet) Page(io.trino.spi.Page) RecordedShard(io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard) Type(io.trino.spi.type.Type) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) OptionalLong(java.util.OptionalLong) ShardDelta(io.trino.plugin.raptor.legacy.metadata.ShardDelta) FileAssert.assertFile(org.testng.FileAssert.assertFile) File(java.io.File) ShardInfo(io.trino.plugin.raptor.legacy.metadata.ShardInfo) Test(org.testng.annotations.Test)

Aggregations

ShardDelta (io.trino.plugin.raptor.legacy.metadata.ShardDelta)2 ShardInfo (io.trino.plugin.raptor.legacy.metadata.ShardInfo)2 Slice (io.airlift.slice.Slice)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1 RecordedShard (io.trino.plugin.raptor.legacy.storage.InMemoryShardRecorder.RecordedShard)1 Page (io.trino.spi.Page)1 Type (io.trino.spi.type.Type)1 VarcharType.createVarcharType (io.trino.spi.type.VarcharType.createVarcharType)1 File (java.io.File)1 BitSet (java.util.BitSet)1 OptionalLong (java.util.OptionalLong)1 FileAssert.assertFile (org.testng.FileAssert.assertFile)1 Test (org.testng.annotations.Test)1