Search in sources :

Example 1 with PrestoThriftNullableTableMetadata

use of com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata in project presto by prestodb.

the class ThriftMetadata method getTableMetadataInternal.

// this method makes actual thrift request and should be called only by cache load method
private Optional<ThriftTableMetadata> getTableMetadataInternal(SchemaTableName schemaTableName) {
    requireNonNull(schemaTableName, "schemaTableName is null");
    PrestoThriftNullableTableMetadata thriftTableMetadata = getTableMetadata(schemaTableName);
    if (thriftTableMetadata.getTableMetadata() == null) {
        return Optional.empty();
    }
    ThriftTableMetadata tableMetadata = new ThriftTableMetadata(thriftTableMetadata.getTableMetadata(), typeManager);
    if (!Objects.equals(schemaTableName, tableMetadata.getSchemaTableName())) {
        throw new PrestoException(THRIFT_SERVICE_INVALID_RESPONSE, "Requested and actual table names are different");
    }
    return Optional.of(tableMetadata);
}
Also used : PrestoThriftNullableTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata) ThriftExceptions.toPrestoException(com.facebook.presto.connector.thrift.util.ThriftExceptions.toPrestoException) PrestoException(com.facebook.presto.spi.PrestoException)

Example 2 with PrestoThriftNullableTableMetadata

use of com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata in project presto by prestodb.

the class ThriftTpchService method getTableMetadata.

@Override
public final PrestoThriftNullableTableMetadata getTableMetadata(PrestoThriftSchemaTableName schemaTableName) {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    if (!SCHEMAS.contains(schemaName) || TpchTable.getTables().stream().noneMatch(table -> table.getTableName().equals(tableName))) {
        return new PrestoThriftNullableTableMetadata(null);
    }
    TpchTable<?> tpchTable = TpchTable.getTable(schemaTableName.getTableName());
    List<PrestoThriftColumnMetadata> columns = new ArrayList<>();
    for (TpchColumn<? extends TpchEntity> column : tpchTable.getColumns()) {
        columns.add(new PrestoThriftColumnMetadata(column.getSimplifiedColumnName(), getTypeString(column), null, false));
    }
    List<Set<String>> indexableKeys = getIndexableKeys(schemaName, tableName);
    return new PrestoThriftNullableTableMetadata(new PrestoThriftTableMetadata(schemaTableName, columns, null, !indexableKeys.isEmpty() ? indexableKeys : null));
}
Also used : RecordPageSource(com.facebook.presto.spi.RecordPageSource) PrestoThriftNullableSchemaName(com.facebook.presto.thrift.api.connector.PrestoThriftNullableSchemaName) TpchColumn(io.airlift.tpch.TpchColumn) MoreExecutors.listeningDecorator(com.google.common.util.concurrent.MoreExecutors.listeningDecorator) JsonCodec(com.facebook.airlift.json.JsonCodec) Page(com.facebook.presto.common.Page) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrestoThriftNullableTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata) PrestoThriftNullableColumnSet(com.facebook.presto.thrift.api.connector.PrestoThriftNullableColumnSet) TpchRecordSet.createTpchRecordSet(com.facebook.presto.tpch.TpchRecordSet.createTpchRecordSet) PrestoThriftSplitBatch(com.facebook.presto.thrift.api.connector.PrestoThriftSplitBatch) PrestoThriftPageResult(com.facebook.presto.thrift.api.connector.PrestoThriftPageResult) ArrayList(java.util.ArrayList) PreDestroy(javax.annotation.PreDestroy) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) PrestoThriftSchemaTableName(com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName) PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) SplitInfo.normalSplit(com.facebook.presto.connector.thrift.server.SplitInfo.normalSplit) PrestoThriftNullableToken(com.facebook.presto.thrift.api.connector.PrestoThriftNullableToken) PrestoThriftTupleDomain(com.facebook.presto.thrift.api.connector.PrestoThriftTupleDomain) PrestoThriftColumnMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftColumnMetadata) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) PrestoThriftService(com.facebook.presto.thrift.api.connector.PrestoThriftService) PrestoThriftServiceException(com.facebook.presto.thrift.api.connector.PrestoThriftServiceException) DEFAULT_MAX_PAGE_SIZE_IN_BYTES(com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES) Threads.threadsNamed(com.facebook.airlift.concurrent.Threads.threadsNamed) Set(java.util.Set) PrestoThriftBlock.fromBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock.fromBlock) Math.min(java.lang.Math.min) PrestoThriftId(com.facebook.presto.thrift.api.connector.PrestoThriftId) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) PrestoThriftSplit(com.facebook.presto.thrift.api.connector.PrestoThriftSplit) Ints(com.google.common.primitives.Ints) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Executors.newFixedThreadPool(java.util.concurrent.Executors.newFixedThreadPool) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TpchTable(io.airlift.tpch.TpchTable) TpchEntity(io.airlift.tpch.TpchEntity) TpchMetadata.getPrestoType(com.facebook.presto.tpch.TpchMetadata.getPrestoType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) PrestoThriftTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftTableMetadata) Closeable(java.io.Closeable) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) PrestoThriftNullableTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata) PrestoThriftNullableColumnSet(com.facebook.presto.thrift.api.connector.PrestoThriftNullableColumnSet) TpchRecordSet.createTpchRecordSet(com.facebook.presto.tpch.TpchRecordSet.createTpchRecordSet) Set(java.util.Set) ArrayList(java.util.ArrayList) PrestoThriftColumnMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftColumnMetadata) PrestoThriftTableMetadata(com.facebook.presto.thrift.api.connector.PrestoThriftTableMetadata)

Aggregations

PrestoThriftNullableTableMetadata (com.facebook.presto.thrift.api.connector.PrestoThriftNullableTableMetadata)2 Threads.threadsNamed (com.facebook.airlift.concurrent.Threads.threadsNamed)1 JsonCodec (com.facebook.airlift.json.JsonCodec)1 JsonCodec.jsonCodec (com.facebook.airlift.json.JsonCodec.jsonCodec)1 Page (com.facebook.presto.common.Page)1 DEFAULT_MAX_PAGE_SIZE_IN_BYTES (com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES)1 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)1 Type (com.facebook.presto.common.type.Type)1 SplitInfo.normalSplit (com.facebook.presto.connector.thrift.server.SplitInfo.normalSplit)1 ThriftExceptions.toPrestoException (com.facebook.presto.connector.thrift.util.ThriftExceptions.toPrestoException)1 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)1 PrestoException (com.facebook.presto.spi.PrestoException)1 RecordPageSource (com.facebook.presto.spi.RecordPageSource)1 PrestoThriftColumnMetadata (com.facebook.presto.thrift.api.connector.PrestoThriftColumnMetadata)1 PrestoThriftId (com.facebook.presto.thrift.api.connector.PrestoThriftId)1 PrestoThriftNullableColumnSet (com.facebook.presto.thrift.api.connector.PrestoThriftNullableColumnSet)1 PrestoThriftNullableSchemaName (com.facebook.presto.thrift.api.connector.PrestoThriftNullableSchemaName)1 PrestoThriftNullableToken (com.facebook.presto.thrift.api.connector.PrestoThriftNullableToken)1 PrestoThriftPageResult (com.facebook.presto.thrift.api.connector.PrestoThriftPageResult)1 PrestoThriftSchemaTableName (com.facebook.presto.thrift.api.connector.PrestoThriftSchemaTableName)1