Search in sources :

Example 6 with TableNotFoundException

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

the class HiveMetadata method listTableColumns.

@SuppressWarnings("TryWithIdenticalCatches")
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    for (SchemaTableName tableName : listTables(session, prefix)) {
        try {
            columns.put(tableName, getTableMetadata(tableName).getColumns());
        } catch (HiveViewNotSupportedException e) {
        // view is not supported
        } catch (TableNotFoundException e) {
        // table disappeared during listing operation
        }
    }
    return columns.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with TableNotFoundException

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

the class HivePartitionManager method getFilteredPartitionNames.

private List<String> getFilteredPartitionNames(SemiTransactionalHiveMetastore metastore, SchemaTableName tableName, List<HiveColumnHandle> partitionKeys, TupleDomain<ColumnHandle> effectivePredicate) {
    checkArgument(effectivePredicate.getDomains().isPresent());
    List<String> filter = new ArrayList<>();
    for (HiveColumnHandle partitionKey : partitionKeys) {
        Domain domain = effectivePredicate.getDomains().get().get(partitionKey);
        if (domain != null && domain.isNullableSingleValue()) {
            Object value = domain.getNullableSingleValue();
            if (value == null) {
                filter.add(HivePartitionKey.HIVE_DEFAULT_DYNAMIC_PARTITION);
            } else if (value instanceof Slice) {
                filter.add(((Slice) value).toStringUtf8());
            } else if ((value instanceof Boolean) || (value instanceof Double) || (value instanceof Long)) {
                if (assumeCanonicalPartitionKeys) {
                    filter.add(value.toString());
                } else {
                    // Hive treats '0', 'false', and 'False' the same. However, the metastore differentiates between these.
                    filter.add(PARTITION_VALUE_WILDCARD);
                }
            } else {
                throw new PrestoException(NOT_SUPPORTED, "Only Boolean, Double and Long partition keys are supported");
            }
        } else {
            filter.add(PARTITION_VALUE_WILDCARD);
        }
    }
    // fetch the partition names
    return metastore.getPartitionNamesByParts(tableName.getSchemaName(), tableName.getTableName(), filter).orElseThrow(() -> new TableNotFoundException(tableName));
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Slice(io.airlift.slice.Slice) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException) ProtectMode.getProtectModeFromString(org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain)

Example 8 with TableNotFoundException

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

the class HiveSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layoutHandle) {
    HiveTableLayoutHandle layout = (HiveTableLayoutHandle) layoutHandle;
    List<HivePartition> partitions = layout.getPartitions().get();
    HivePartition partition = Iterables.getFirst(partitions, null);
    if (partition == null) {
        return new FixedSplitSource(ImmutableList.of());
    }
    SchemaTableName tableName = partition.getTableName();
    List<HiveBucketing.HiveBucket> buckets = partition.getBuckets();
    Optional<HiveBucketHandle> bucketHandle = layout.getBucketHandle();
    // sort partitions
    partitions = Ordering.natural().onResultOf(HivePartition::getPartitionId).reverse().sortedCopy(partitions);
    SemiTransactionalHiveMetastore metastore = metastoreProvider.apply((HiveTransactionHandle) transaction);
    Optional<Table> table = metastore.getTable(tableName.getSchemaName(), tableName.getTableName());
    if (!table.isPresent()) {
        throw new TableNotFoundException(tableName);
    }
    Iterable<HivePartitionMetadata> hivePartitions = getPartitionMetadata(metastore, table.get(), tableName, partitions, bucketHandle.map(HiveBucketHandle::toBucketProperty));
    HiveSplitLoader hiveSplitLoader = new BackgroundHiveSplitLoader(connectorId, table.get(), hivePartitions, bucketHandle, buckets, session, hdfsEnvironment, namenodeStats, directoryLister, executor, maxPartitionBatchSize, maxInitialSplits, recursiveDfsWalkerEnabled);
    HiveSplitSource splitSource = new HiveSplitSource(maxOutstandingSplits, hiveSplitLoader, executor);
    hiveSplitLoader.start(splitSource);
    return splitSource;
}
Also used : Table(com.facebook.presto.hive.metastore.Table) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource)

Example 9 with TableNotFoundException

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

the class ExampleMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    ExampleTableHandle exampleTableHandle = (ExampleTableHandle) tableHandle;
    checkArgument(exampleTableHandle.getConnectorId().equals(connectorId), "tableHandle is not for this connector");
    ExampleTable table = exampleClient.getTable(exampleTableHandle.getSchemaName(), exampleTableHandle.getTableName());
    if (table == null) {
        throw new TableNotFoundException(exampleTableHandle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    int index = 0;
    for (ColumnMetadata column : table.getColumnsMetadata()) {
        columnHandles.put(column.getName(), new ExampleColumnHandle(connectorId, column.getName(), column.getType(), index));
        index++;
    }
    return columnHandles.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(com.facebook.presto.spi.Constraint)

Example 10 with TableNotFoundException

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

the class BridgingHiveMetastore method renameColumn.

@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
    Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(databaseName, tableName);
    if (!source.isPresent()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    org.apache.hadoop.hive.metastore.api.Table table = source.get();
    for (FieldSchema fieldSchema : table.getPartitionKeys()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            throw new PrestoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
        }
    }
    for (FieldSchema fieldSchema : table.getSd().getCols()) {
        if (fieldSchema.getName().equals(oldColumnName)) {
            fieldSchema.setName(newColumnName);
        }
    }
    alterTable(databaseName, tableName, table);
}
Also used : MetastoreUtil.toMetastoreApiTable(com.facebook.presto.hive.metastore.MetastoreUtil.toMetastoreApiTable) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException)

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