Search in sources :

Example 16 with TableNotFoundException

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

the class RaptorMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    RaptorTableHandle handle = (RaptorTableHandle) tableHandle;
    SchemaTableName tableName = new SchemaTableName(handle.getSchemaName(), handle.getTableName());
    List<TableColumn> tableColumns = dao.listTableColumns(handle.getTableId());
    if (tableColumns.isEmpty()) {
        throw new TableNotFoundException(tableName);
    }
    ImmutableMap.Builder<String, Object> properties = ImmutableMap.builder();
    SortedMap<Integer, String> bucketing = new TreeMap<>();
    SortedMap<Integer, String> ordering = new TreeMap<>();
    for (TableColumn column : tableColumns) {
        if (column.isTemporal()) {
            properties.put(TEMPORAL_COLUMN_PROPERTY, column.getColumnName());
        }
        column.getBucketOrdinal().ifPresent(bucketOrdinal -> bucketing.put(bucketOrdinal, column.getColumnName()));
        column.getSortOrdinal().ifPresent(sortOrdinal -> ordering.put(sortOrdinal, column.getColumnName()));
    }
    if (!bucketing.isEmpty()) {
        properties.put(BUCKETED_ON_PROPERTY, ImmutableList.copyOf(bucketing.values()));
    }
    if (!ordering.isEmpty()) {
        properties.put(ORDERING_PROPERTY, ImmutableList.copyOf(ordering.values()));
    }
    handle.getBucketCount().ifPresent(bucketCount -> properties.put(BUCKET_COUNT_PROPERTY, bucketCount));
    handle.getDistributionName().ifPresent(distributionName -> properties.put(DISTRIBUTION_NAME_PROPERTY, distributionName));
    // Only display organization property if set
    if (handle.isOrganized()) {
        properties.put(ORGANIZED_PROPERTY, true);
    }
    List<ColumnMetadata> columns = tableColumns.stream().map(TableColumn::toColumnMetadata).collect(toCollection(ArrayList::new));
    columns.add(hiddenColumn(SHARD_UUID_COLUMN_NAME, SHARD_UUID_COLUMN_TYPE));
    columns.add(hiddenColumn(BUCKET_NUMBER_COLUMN_NAME, INTEGER));
    return new ConnectorTableMetadata(tableName, columns, properties.build());
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TreeMap(java.util.TreeMap) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableColumn(com.facebook.presto.raptor.metadata.TableColumn) ImmutableMap(com.google.common.collect.ImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 17 with TableNotFoundException

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

the class RedisMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    RedisTableHandle redisTableHandle = convertTableHandle(tableHandle);
    RedisTableDescription redisTableDescription = getDefinedTables().get(redisTableHandle.toSchemaTableName());
    if (redisTableDescription == null) {
        throw new TableNotFoundException(redisTableHandle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    int index = 0;
    RedisTableFieldGroup key = redisTableDescription.getKey();
    if (key != null) {
        List<RedisTableFieldDescription> fields = key.getFields();
        if (fields != null) {
            for (RedisTableFieldDescription field : fields) {
                columnHandles.put(field.getName(), field.getColumnHandle(connectorId, true, index));
                index++;
            }
        }
    }
    RedisTableFieldGroup value = redisTableDescription.getValue();
    if (value != null) {
        List<RedisTableFieldDescription> fields = value.getFields();
        if (fields != null) {
            for (RedisTableFieldDescription field : fields) {
                columnHandles.put(field.getName(), field.getColumnHandle(connectorId, false, index));
                index++;
            }
        }
    }
    for (RedisInternalFieldDescription field : internalFieldDescriptions) {
        columnHandles.put(field.getName(), field.getColumnHandle(connectorId, index, hideInternalColumns));
        index++;
    }
    return columnHandles.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) RedisHandleResolver.convertColumnHandle(com.facebook.presto.redis.RedisHandleResolver.convertColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(com.facebook.presto.spi.Constraint)

Example 18 with TableNotFoundException

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

the class KafkaMetadata method getColumnHandles.

@SuppressWarnings("ValueOfIncrementOrDecrementUsed")
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    KafkaTableHandle kafkaTableHandle = convertTableHandle(tableHandle);
    KafkaTopicDescription kafkaTopicDescription = tableDescriptions.get(kafkaTableHandle.toSchemaTableName());
    if (kafkaTopicDescription == null) {
        throw new TableNotFoundException(kafkaTableHandle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    int index = 0;
    KafkaTopicFieldGroup key = kafkaTopicDescription.getKey();
    if (key != null) {
        List<KafkaTopicFieldDescription> fields = key.getFields();
        if (fields != null) {
            for (KafkaTopicFieldDescription kafkaTopicFieldDescription : fields) {
                columnHandles.put(kafkaTopicFieldDescription.getName(), kafkaTopicFieldDescription.getColumnHandle(connectorId, true, index++));
            }
        }
    }
    KafkaTopicFieldGroup message = kafkaTopicDescription.getMessage();
    if (message != null) {
        List<KafkaTopicFieldDescription> fields = message.getFields();
        if (fields != null) {
            for (KafkaTopicFieldDescription kafkaTopicFieldDescription : fields) {
                columnHandles.put(kafkaTopicFieldDescription.getName(), kafkaTopicFieldDescription.getColumnHandle(connectorId, false, index++));
            }
        }
    }
    for (KafkaInternalFieldDescription kafkaInternalFieldDescription : internalFieldDescriptions) {
        columnHandles.put(kafkaInternalFieldDescription.getName(), kafkaInternalFieldDescription.getColumnHandle(connectorId, index++, hideInternalColumns));
    }
    return columnHandles.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) KafkaHandleResolver.convertColumnHandle(com.facebook.presto.kafka.KafkaHandleResolver.convertColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(com.facebook.presto.spi.Constraint)

Example 19 with TableNotFoundException

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

the class MongoSession method getTableMetadata.

// Internal Schema management
private Document getTableMetadata(SchemaTableName schemaTableName) throws TableNotFoundException {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    MongoDatabase db = client.getDatabase(schemaName);
    MongoCollection<Document> schema = db.getCollection(schemaCollection);
    Document doc = schema.find(new Document(TABLE_NAME_KEY, tableName)).first();
    if (doc == null) {
        if (!collectionExists(db, tableName)) {
            throw new TableNotFoundException(schemaTableName);
        } else {
            Document metadata = new Document(TABLE_NAME_KEY, tableName);
            metadata.append(FIELDS_KEY, guessTableFields(schemaTableName));
            schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
            schema.insertOne(metadata);
            return metadata;
        }
    }
    return doc;
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) IndexOptions(com.mongodb.client.model.IndexOptions) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase)

Example 20 with TableNotFoundException

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

the class MongoSession method createTableMetadata.

private void createTableMetadata(SchemaTableName schemaTableName, List<MongoColumnHandle> columns) throws TableNotFoundException {
    String schemaName = schemaTableName.getSchemaName();
    String tableName = schemaTableName.getTableName();
    MongoDatabase db = client.getDatabase(schemaName);
    Document metadata = new Document(TABLE_NAME_KEY, tableName);
    ArrayList<Document> fields = new ArrayList<>();
    if (!columns.stream().anyMatch(c -> c.getName().equals("_id"))) {
        fields.add(new MongoColumnHandle("_id", OBJECT_ID, true).getDocument());
    }
    fields.addAll(columns.stream().map(MongoColumnHandle::getDocument).collect(toList()));
    metadata.append(FIELDS_KEY, fields);
    MongoCollection<Document> schema = db.getCollection(schemaCollection);
    schema.createIndex(new Document(TABLE_NAME_KEY, 1), new IndexOptions().unique(true));
    schema.insertOne(metadata);
}
Also used : Document(org.bson.Document) Arrays(java.util.Arrays) LoadingCache(com.google.common.cache.LoadingCache) TypeManager(com.facebook.presto.spi.type.TypeManager) Date(java.util.Date) MongoDatabase(com.mongodb.client.MongoDatabase) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) SchemaTableName(com.facebook.presto.spi.SchemaTableName) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) SchemaNotFoundException(com.facebook.presto.spi.SchemaNotFoundException) Map(java.util.Map) TypeSignatureParameter(com.facebook.presto.spi.type.TypeSignatureParameter) StandardTypes(com.facebook.presto.spi.type.StandardTypes) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CacheLoader(com.google.common.cache.CacheLoader) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) List(java.util.List) FindIterable(com.mongodb.client.FindIterable) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) TypeSignature(com.facebook.presto.spi.type.TypeSignature) IntStream(java.util.stream.IntStream) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) MongoCollection(com.mongodb.client.MongoCollection) Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) OBJECT_ID(com.facebook.presto.mongodb.ObjectIdType.OBJECT_ID) MINUTES(java.util.concurrent.TimeUnit.MINUTES) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) MongoCursor(com.mongodb.client.MongoCursor) Verify.verify(com.google.common.base.Verify.verify) Type(com.facebook.presto.spi.type.Type) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) NamedTypeSignature(com.facebook.presto.spi.type.NamedTypeSignature) Objects.requireNonNull(java.util.Objects.requireNonNull) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) Throwables(com.google.common.base.Throwables) Range(com.facebook.presto.spi.predicate.Range) IndexOptions(com.mongodb.client.model.IndexOptions) ExecutionException(java.util.concurrent.ExecutionException) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) Collectors.toList(java.util.stream.Collectors.toList) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ColumnHandle(com.facebook.presto.spi.ColumnHandle) MongoClient(com.mongodb.MongoClient) DeleteResult(com.mongodb.client.result.DeleteResult) ObjectId(org.bson.types.ObjectId) HOURS(java.util.concurrent.TimeUnit.HOURS) VisibleForTesting(com.google.common.annotations.VisibleForTesting) IndexOptions(com.mongodb.client.model.IndexOptions) ArrayList(java.util.ArrayList) Document(org.bson.Document) MongoDatabase(com.mongodb.client.MongoDatabase)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)39 SchemaTableName (com.facebook.presto.spi.SchemaTableName)26 PrestoException (com.facebook.presto.spi.PrestoException)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 ColumnHandle (com.facebook.presto.spi.ColumnHandle)8 Table (com.facebook.presto.hive.metastore.Table)7 ImmutableList (com.google.common.collect.ImmutableList)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 AccumuloTable (com.facebook.presto.accumulo.metadata.AccumuloTable)4 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)4 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)4 Constraint (com.facebook.presto.spi.Constraint)4 Slice (io.airlift.slice.Slice)4 Collectors.toList (java.util.stream.Collectors.toList)4 Path (org.apache.hadoop.fs.Path)4 AccumuloTableHandle (com.facebook.presto.accumulo.model.AccumuloTableHandle)3 HiveTableProperties.getHiveStorageFormat (com.facebook.presto.hive.HiveTableProperties.getHiveStorageFormat)3 Table (org.apache.hadoop.hive.metastore.api.Table)3 AccumuloColumnHandle (com.facebook.presto.accumulo.model.AccumuloColumnHandle)2