Search in sources :

Example 1 with StorageManager

use of com.facebook.presto.raptor.storage.StorageManager in project presto by prestodb.

the class TestShardCompactor method testShardCompactorSorted.

@Test(dataProvider = "useOptimizedOrcWriter")
public void testShardCompactorSorted(boolean useOptimizedOrcWriter) throws Exception {
    StorageManager storageManager = createOrcStorageManager(dbi, temporary, MAX_SHARD_ROWS);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), DATE, TIMESTAMP, DOUBLE);
    List<Long> columnIds = ImmutableList.of(3L, 7L, 2L, 1L, 5L);
    List<Long> sortColumnIds = ImmutableList.of(1L, 2L, 3L, 5L, 7L);
    List<SortOrder> sortOrders = nCopies(sortColumnIds.size(), ASC_NULLS_FIRST);
    List<Integer> sortIndexes = sortColumnIds.stream().map(columnIds::indexOf).collect(toList());
    List<ShardInfo> inputShards = createSortedShards(storageManager, columnIds, columnTypes, sortIndexes, sortOrders, 2);
    assertEquals(inputShards.size(), 2);
    long totalRows = inputShards.stream().mapToLong(ShardInfo::getRowCount).sum();
    long expectedOutputShards = computeExpectedOutputShards(totalRows);
    Map<UUID, Optional<UUID>> inputUuids = new HashMap<>();
    for (ShardInfo shardInfo : inputShards) {
        inputUuids.put(shardInfo.getShardUuid(), Optional.empty());
    }
    long transactionId = 1;
    ShardCompactor compactor = new ShardCompactor(storageManager, READER_ATTRIBUTES);
    List<ShardInfo> outputShards = compactor.compactSorted(transactionId, false, OptionalInt.empty(), inputUuids, getColumnInfo(columnIds, columnTypes), sortColumnIds, sortOrders);
    List<UUID> outputUuids = outputShards.stream().map(ShardInfo::getShardUuid).collect(toList());
    assertEquals(outputShards.size(), expectedOutputShards);
    assertShardEqualsSorted(storageManager, inputUuids.keySet(), outputUuids, columnIds, columnTypes, sortIndexes, sortOrders);
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) StorageManager(com.facebook.presto.raptor.storage.StorageManager) TestOrcStorageManager.createOrcStorageManager(com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager) SortOrder(com.facebook.presto.common.block.SortOrder) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) UUID(java.util.UUID) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 2 with StorageManager

use of com.facebook.presto.raptor.storage.StorageManager in project presto by prestodb.

the class TestShardCompactor method testShardCompactor.

@Test(dataProvider = "useOptimizedOrcWriter")
public void testShardCompactor(boolean useOptimizedOrcWriter) throws Exception {
    StorageManager storageManager = createOrcStorageManager(dbi, temporary, MAX_SHARD_ROWS);
    List<Long> columnIds = ImmutableList.of(3L, 7L, 2L, 1L, 5L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), DOUBLE, DATE, TIMESTAMP);
    List<ShardInfo> inputShards = createShards(storageManager, columnIds, columnTypes, 3);
    assertEquals(inputShards.size(), 3);
    long totalRows = inputShards.stream().mapToLong(ShardInfo::getRowCount).sum();
    long expectedOutputShards = computeExpectedOutputShards(totalRows);
    Map<UUID, Optional<UUID>> inputUuids = new HashMap<>();
    for (ShardInfo shardInfo : inputShards) {
        inputUuids.put(shardInfo.getShardUuid(), Optional.empty());
    }
    long transactionId = 1;
    ShardCompactor compactor = new ShardCompactor(storageManager, READER_ATTRIBUTES);
    List<ShardInfo> outputShards = compactor.compact(transactionId, false, OptionalInt.empty(), inputUuids, getColumnInfo(columnIds, columnTypes));
    assertEquals(outputShards.size(), expectedOutputShards);
    Set<UUID> outputUuids = outputShards.stream().map(ShardInfo::getShardUuid).collect(toSet());
    assertShardEqualsIgnoreOrder(storageManager, inputUuids.keySet(), outputUuids, columnIds, columnTypes);
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) StorageManager(com.facebook.presto.raptor.storage.StorageManager) TestOrcStorageManager.createOrcStorageManager(com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) UUID(java.util.UUID) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 3 with StorageManager

use of com.facebook.presto.raptor.storage.StorageManager in project presto by prestodb.

the class TestShardCompactor method testShardCompactorWithDelta.

@Test
public void testShardCompactorWithDelta() throws Exception {
    StorageManager storageManager = createOrcStorageManager(dbi, temporary, MAX_SHARD_ROWS);
    List<Long> columnIds = ImmutableList.of(3L, 7L, 2L, 1L, 5L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(20), DOUBLE, DATE, TIMESTAMP);
    List<ShardInfo> inputShards = createShards(storageManager, columnIds, columnTypes, 3);
    assertEquals(inputShards.size(), 3);
    List<Long> deltaColumnIds = ImmutableList.of(1L);
    List<Type> deltaColumnTypes = ImmutableList.of(BIGINT);
    StoragePageSink deltaSink = createStoragePageSink(storageManager, deltaColumnIds, deltaColumnTypes);
    List<Page> deltaPages = rowPagesBuilder(deltaColumnTypes).row(1L).row(2L).build();
    deltaSink.appendPages(deltaPages);
    List<ShardInfo> deltaShards = getFutureValue(deltaSink.commit());
    long totalRows = inputShards.stream().mapToLong(ShardInfo::getRowCount).sum();
    long expectedOutputShardsCount = computeExpectedOutputShards(totalRows - 2);
    Map<UUID, Optional<UUID>> inputUuidsMap = new HashMap<>();
    inputUuidsMap.put(inputShards.get(0).getShardUuid(), Optional.of(deltaShards.get(0).getShardUuid()));
    inputUuidsMap.put(inputShards.get(1).getShardUuid(), Optional.empty());
    inputUuidsMap.put(inputShards.get(2).getShardUuid(), Optional.empty());
    long transactionId = 1;
    ShardCompactor compactor = new ShardCompactor(storageManager, READER_ATTRIBUTES);
    List<ShardInfo> outputShards = compactor.compact(transactionId, true, OptionalInt.empty(), inputUuidsMap, getColumnInfo(columnIds, columnTypes));
    assertEquals(outputShards.size(), expectedOutputShardsCount);
    Set<UUID> outputUuids = outputShards.stream().map(ShardInfo::getShardUuid).collect(toSet());
    assertShardEqualsIgnoreOrder(storageManager, inputUuidsMap, outputUuids, columnIds, columnTypes);
}
Also used : Optional(java.util.Optional) HashMap(java.util.HashMap) StorageManager(com.facebook.presto.raptor.storage.StorageManager) TestOrcStorageManager.createOrcStorageManager(com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager) Page(com.facebook.presto.common.Page) StoragePageSink(com.facebook.presto.raptor.storage.StoragePageSink) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) UUID(java.util.UUID) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 4 with StorageManager

use of com.facebook.presto.raptor.storage.StorageManager in project presto by prestodb.

the class TestRaptorConnector method setup.

@BeforeMethod
public void setup() throws Exception {
    FunctionAndTypeManager functionAndTypeManager = createTestFunctionAndTypeManager();
    DBI dbi = new DBI("jdbc:h2:mem:test" + System.nanoTime() + "_" + ThreadLocalRandom.current().nextInt());
    dbi.registerMapper(new TableColumn.Mapper(functionAndTypeManager));
    dummyHandle = dbi.open();
    metadataDao = dbi.onDemand(MetadataDao.class);
    createTablesWithRetry(dbi);
    dataDir = Files.createTempDir();
    RaptorConnectorId connectorId = new RaptorConnectorId("test");
    NodeManager nodeManager = new TestingNodeManager();
    NodeSupplier nodeSupplier = nodeManager::getWorkerNodes;
    ShardManager shardManager = createShardManager(dbi);
    StorageManager storageManager = createOrcStorageManager(dbi, dataDir);
    StorageManagerConfig config = new StorageManagerConfig();
    connector = new RaptorConnector(new LifeCycleManager(ImmutableList.of(), null), new TestingNodeManager(), new RaptorMetadataFactory(connectorId, dbi, shardManager, functionAndTypeManager), new RaptorSplitManager(connectorId, nodeSupplier, shardManager, false), new RaptorPageSourceProvider(storageManager), new RaptorPageSinkProvider(storageManager, new PagesIndexPageSorter(new PagesIndex.TestingFactory(false)), new TemporalFunction(DateTimeZone.forID("America/Los_Angeles")), config), new RaptorNodePartitioningProvider(nodeSupplier), new RaptorSessionProperties(config), new RaptorTableProperties(functionAndTypeManager), ImmutableSet.of(), new AllowAllAccessControl(), dbi, ImmutableSet.of());
}
Also used : StorageManager(com.facebook.presto.raptor.storage.StorageManager) TestOrcStorageManager.createOrcStorageManager(com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager) DBI(org.skife.jdbi.v2.DBI) ShardManager(com.facebook.presto.raptor.metadata.ShardManager) TestDatabaseShardManager.createShardManager(com.facebook.presto.raptor.metadata.TestDatabaseShardManager.createShardManager) StorageManagerConfig(com.facebook.presto.raptor.storage.StorageManagerConfig) TemporalFunction(com.facebook.presto.raptor.storage.organization.TemporalFunction) PagesIndexPageSorter(com.facebook.presto.PagesIndexPageSorter) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) FunctionAndTypeManager.createTestFunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager) TestingNodeManager(com.facebook.presto.testing.TestingNodeManager) AllowAllAccessControl(com.facebook.presto.plugin.base.security.AllowAllAccessControl) MetadataDao(com.facebook.presto.raptor.metadata.MetadataDao) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) NodeManager(com.facebook.presto.spi.NodeManager) TestingNodeManager(com.facebook.presto.testing.TestingNodeManager) LifeCycleManager(com.facebook.airlift.bootstrap.LifeCycleManager) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

StorageManager (com.facebook.presto.raptor.storage.StorageManager)4 TestOrcStorageManager.createOrcStorageManager (com.facebook.presto.raptor.storage.TestOrcStorageManager.createOrcStorageManager)4 Type (com.facebook.presto.common.type.Type)3 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)3 ShardInfo (com.facebook.presto.raptor.metadata.ShardInfo)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 UUID (java.util.UUID)3 Test (org.testng.annotations.Test)3 LifeCycleManager (com.facebook.airlift.bootstrap.LifeCycleManager)1 PagesIndexPageSorter (com.facebook.presto.PagesIndexPageSorter)1 Page (com.facebook.presto.common.Page)1 SortOrder (com.facebook.presto.common.block.SortOrder)1 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)1 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)1 AllowAllAccessControl (com.facebook.presto.plugin.base.security.AllowAllAccessControl)1 MetadataDao (com.facebook.presto.raptor.metadata.MetadataDao)1 ShardManager (com.facebook.presto.raptor.metadata.ShardManager)1 TableColumn (com.facebook.presto.raptor.metadata.TableColumn)1 TestDatabaseShardManager.createShardManager (com.facebook.presto.raptor.metadata.TestDatabaseShardManager.createShardManager)1