Search in sources :

Example 6 with ConnectorTableLayoutResult

use of com.facebook.presto.spi.ConnectorTableLayoutResult in project presto by prestodb.

the class MemoryMetadata method getTableLayouts.

@Override
public synchronized List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle handle, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    requireNonNull(handle, "handle is null");
    checkArgument(handle instanceof MemoryTableHandle);
    MemoryTableLayoutHandle layoutHandle = new MemoryTableLayoutHandle((MemoryTableHandle) handle);
    return ImmutableList.of(new ConnectorTableLayoutResult(getTableLayout(session, layoutHandle), constraint.getSummary()));
}
Also used : ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult)

Example 7 with ConnectorTableLayoutResult

use of com.facebook.presto.spi.ConnectorTableLayoutResult in project presto by prestodb.

the class TestRaptorSplitManager method testSanity.

@Test
public void testSanity() throws InterruptedException {
    List<ConnectorTableLayoutResult> layouts = metadata.getTableLayouts(SESSION, tableHandle, Constraint.alwaysTrue(), Optional.empty());
    assertEquals(layouts.size(), 1);
    ConnectorTableLayoutResult layout = getOnlyElement(layouts);
    assertInstanceOf(layout.getTableLayout().getHandle(), RaptorTableLayoutHandle.class);
    ConnectorSplitSource splitSource = getSplits(raptorSplitManager, layout);
    int splitCount = 0;
    while (!splitSource.isFinished()) {
        splitCount += getFutureValue(splitSource.getNextBatch(1000)).size();
    }
    assertEquals(splitCount, 4);
}
Also used : ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) Constraint(com.facebook.presto.spi.Constraint) Test(org.testng.annotations.Test)

Example 8 with ConnectorTableLayoutResult

use of com.facebook.presto.spi.ConnectorTableLayoutResult in project presto by prestodb.

the class RedisMetadata method getTableLayouts.

@Override
public List<ConnectorTableLayoutResult> getTableLayouts(ConnectorSession session, ConnectorTableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    RedisTableHandle tableHandle = convertTableHandle(table);
    ConnectorTableLayout layout = new ConnectorTableLayout(new RedisTableLayoutHandle(tableHandle));
    return ImmutableList.of(new ConnectorTableLayoutResult(layout, constraint.getSummary()));
}
Also used : ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout)

Example 9 with ConnectorTableLayoutResult

use of com.facebook.presto.spi.ConnectorTableLayoutResult in project presto by prestodb.

the class ConnectorMetadata method getInsertLayout.

/**
     * Get the physical layout for a inserting into an existing table.
     */
default default Optional<ConnectorNewTableLayout> getInsertLayout(ConnectorSession session, ConnectorTableHandle tableHandle) {
    List<ConnectorTableLayout> layouts = getTableLayouts(session, tableHandle, new Constraint<>(TupleDomain.all(), map -> true), Optional.empty()).stream().map(ConnectorTableLayoutResult::getTableLayout).filter(layout -> layout.getNodePartitioning().isPresent()).collect(toList());
    if (layouts.isEmpty()) {
        return Optional.empty();
    }
    if (layouts.size() > 1) {
        throw new PrestoException(NOT_SUPPORTED, "Tables with multiple layouts can not be written");
    }
    ConnectorTableLayout layout = layouts.get(0);
    ConnectorPartitioningHandle partitioningHandle = layout.getNodePartitioning().get().getPartitioningHandle();
    Map<ColumnHandle, String> columnNamesByHandle = getColumnHandles(session, tableHandle).entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
    List<String> partitionColumns = layout.getNodePartitioning().get().getPartitioningColumns().stream().map(columnNamesByHandle::get).collect(toList());
    return Optional.of(new ConnectorNewTableLayout(partitioningHandle, partitionColumns));
}
Also used : Slice(io.airlift.slice.Slice) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) GENERIC_INTERNAL_ERROR(com.facebook.presto.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) TableIdentity(com.facebook.presto.spi.TableIdentity) Privilege(com.facebook.presto.spi.security.Privilege) OptionalLong(java.util.OptionalLong) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Map(java.util.Map) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptyList(java.util.Collections.emptyList) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Collection(java.util.Collection) ColumnIdentity(com.facebook.presto.spi.ColumnIdentity) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) Collectors(java.util.stream.Collectors) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) Optional(java.util.Optional) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) ColumnHandle(com.facebook.presto.spi.ColumnHandle) PrestoException(com.facebook.presto.spi.PrestoException) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 10 with ConnectorTableLayoutResult

use of com.facebook.presto.spi.ConnectorTableLayoutResult in project presto by prestodb.

the class MetadataManager method getLayouts.

@Override
public List<TableLayoutResult> getLayouts(Session session, TableHandle table, Constraint<ColumnHandle> constraint, Optional<Set<ColumnHandle>> desiredColumns) {
    if (constraint.getSummary().isNone()) {
        return ImmutableList.of();
    }
    ConnectorId connectorId = table.getConnectorId();
    ConnectorTableHandle connectorTable = table.getConnectorHandle();
    CatalogMetadata catalogMetadata = getCatalogMetadata(session, connectorId);
    ConnectorMetadata metadata = catalogMetadata.getMetadataFor(connectorId);
    ConnectorTransactionHandle transaction = catalogMetadata.getTransactionHandleFor(connectorId);
    ConnectorSession connectorSession = session.toConnectorSession(connectorId);
    List<ConnectorTableLayoutResult> layouts = metadata.getTableLayouts(connectorSession, connectorTable, constraint, desiredColumns);
    return layouts.stream().map(layout -> new TableLayoutResult(fromConnectorLayout(connectorId, transaction, layout.getTableLayout()), layout.getUnenforcedConstraint())).collect(toImmutableList());
}
Also used : TypeManager(com.facebook.presto.spi.type.TypeManager) TypeRegistry(com.facebook.presto.type.TypeRegistry) BETWEEN(com.facebook.presto.spi.function.OperatorType.BETWEEN) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TableIdentity(com.facebook.presto.spi.TableIdentity) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) Privilege(com.facebook.presto.spi.security.Privilege) ObjectMapperProvider(io.airlift.json.ObjectMapperProvider) SchemaTableName(com.facebook.presto.spi.SchemaTableName) HashMultimap(com.google.common.collect.HashMultimap) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Map(java.util.Map) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) LESS_THAN(com.facebook.presto.spi.function.OperatorType.LESS_THAN) LESS_THAN_OR_EQUAL(com.facebook.presto.spi.function.OperatorType.LESS_THAN_OR_EQUAL) ENGLISH(java.util.Locale.ENGLISH) ImmutableSet(com.google.common.collect.ImmutableSet) EQUAL(com.facebook.presto.spi.function.OperatorType.EQUAL) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) OperatorType(com.facebook.presto.spi.function.OperatorType) QualifiedObjectName.convertFromSchemaTableName(com.facebook.presto.metadata.QualifiedObjectName.convertFromSchemaTableName) JsonCodecFactory(io.airlift.json.JsonCodecFactory) Entry(java.util.Map.Entry) Optional(java.util.Optional) GREATER_THAN(com.facebook.presto.spi.function.OperatorType.GREATER_THAN) ConnectorId(com.facebook.presto.connector.ConnectorId) Joiner(com.google.common.base.Joiner) JsonCodec(io.airlift.json.JsonCodec) TypeSignature(com.facebook.presto.spi.type.TypeSignature) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) QualifiedName(com.facebook.presto.sql.tree.QualifiedName) Slice(io.airlift.slice.Slice) HASH_CODE(com.facebook.presto.spi.function.OperatorType.HASH_CODE) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) HashMap(java.util.HashMap) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) OptionalLong(java.util.OptionalLong) BlockEncodingSerde(com.facebook.presto.spi.block.BlockEncodingSerde) ImmutableList(com.google.common.collect.ImmutableList) Type(com.facebook.presto.spi.type.Type) Objects.requireNonNull(java.util.Objects.requireNonNull) TransactionManager(com.facebook.presto.transaction.TransactionManager) LinkedHashSet(java.util.LinkedHashSet) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) NOT_EQUAL(com.facebook.presto.spi.function.OperatorType.NOT_EQUAL) ConnectorOutputMetadata(com.facebook.presto.spi.connector.ConnectorOutputMetadata) Session(com.facebook.presto.Session) CatalogSchemaName(com.facebook.presto.spi.CatalogSchemaName) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) ColumnIdentity(com.facebook.presto.spi.ColumnIdentity) Constraint(com.facebook.presto.spi.Constraint) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) INVALID_VIEW(com.facebook.presto.spi.StandardErrorCode.INVALID_VIEW) TypeDeserializer(com.facebook.presto.type.TypeDeserializer) SYNTAX_ERROR(com.facebook.presto.spi.StandardErrorCode.SYNTAX_ERROR) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ViewColumn(com.facebook.presto.metadata.ViewDefinition.ViewColumn) QueryId(com.facebook.presto.spi.QueryId) GREATER_THAN_OR_EQUAL(com.facebook.presto.spi.function.OperatorType.GREATER_THAN_OR_EQUAL) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TransactionManager.createTestTransactionManager(com.facebook.presto.transaction.TransactionManager.createTestTransactionManager) TableLayout.fromConnectorLayout(com.facebook.presto.metadata.TableLayout.fromConnectorLayout) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) BlockEncodingManager(com.facebook.presto.block.BlockEncodingManager) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) ConnectorId(com.facebook.presto.connector.ConnectorId) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle)

Aggregations

ConnectorTableLayoutResult (com.facebook.presto.spi.ConnectorTableLayoutResult)38 ConnectorTableLayout (com.facebook.presto.spi.ConnectorTableLayout)28 ColumnHandle (com.facebook.presto.spi.ColumnHandle)20 Test (org.testng.annotations.Test)19 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)18 Constraint (com.facebook.presto.spi.Constraint)18 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)17 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)17 Map (java.util.Map)17 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)16 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)16 ConnectorSession (com.facebook.presto.spi.ConnectorSession)16 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)16 SchemaTableName (com.facebook.presto.spi.SchemaTableName)16 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)16 ImmutableList (com.google.common.collect.ImmutableList)16 ImmutableMap (com.google.common.collect.ImmutableMap)16 Set (java.util.Set)16 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)15 GroupByHashPageIndexerFactory (com.facebook.presto.GroupByHashPageIndexerFactory)14