Search in sources :

Example 91 with TableNotFoundException

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

the class JdbcMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    List<SchemaTableName> tables;
    if (prefix.getTableName() != null) {
        tables = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
    } else {
        tables = listTables(session, Optional.of(prefix.getSchemaName()));
    }
    for (SchemaTableName tableName : tables) {
        try {
            JdbcTableHandle tableHandle = jdbcClient.getTableHandle(JdbcIdentity.from(session), tableName);
            if (tableHandle == null) {
                continue;
            }
            columns.put(tableName, getTableMetadata(session, tableHandle).getColumns());
        } catch (TableNotFoundException e) {
        // table disappeared during listing operation
        }
    }
    return columns.build();
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 92 with TableNotFoundException

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

the class SyncPartitionMetadataProcedure method doSyncPartitionMetadata.

private void doSyncPartitionMetadata(ConnectorSession session, String schemaName, String tableName, String mode, boolean caseSensitive) {
    SyncMode syncMode = toSyncMode(mode);
    SemiTransactionalHiveMetastore metastore = hiveMetadataFactory.get().getMetastore();
    SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
    Table table = metastore.getTable(new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), getMetastoreHeaders(session), isUserDefinedTypeEncodingEnabled(session), metastore.getColumnConverterProvider()), schemaName, tableName).orElseThrow(() -> new TableNotFoundException(schemaTableName));
    if (table.getPartitionColumns().isEmpty()) {
        throw new PrestoException(INVALID_PROCEDURE_ARGUMENT, "Table is not partitioned: " + schemaTableName);
    }
    Path tableLocation = new Path(table.getStorage().getLocation());
    HdfsContext context = new HdfsContext(session, schemaName, tableName, table.getStorage().getLocation(), false);
    Set<String> partitionsToAdd;
    Set<String> partitionsToDrop;
    try {
        FileSystem fileSystem = hdfsEnvironment.getFileSystem(context, tableLocation);
        List<String> partitionsInMetastore = metastore.getPartitionNames(new MetastoreContext(session.getIdentity(), session.getQueryId(), session.getClientInfo(), session.getSource(), getMetastoreHeaders(session), isUserDefinedTypeEncodingEnabled(session), metastore.getColumnConverterProvider()), schemaName, tableName).orElseThrow(() -> new TableNotFoundException(schemaTableName));
        List<String> partitionsInFileSystem = listDirectory(fileSystem, fileSystem.getFileStatus(tableLocation), table.getPartitionColumns(), table.getPartitionColumns().size(), caseSensitive).stream().map(fileStatus -> fileStatus.getPath().toUri()).map(uri -> tableLocation.toUri().relativize(uri).getPath()).collect(toImmutableList());
        // partitions in file system but not in metastore
        partitionsToAdd = difference(partitionsInFileSystem, partitionsInMetastore);
        // partitions in metastore but not in file system
        partitionsToDrop = difference(partitionsInMetastore, partitionsInFileSystem);
    } catch (IOException e) {
        throw new PrestoException(HIVE_FILESYSTEM_ERROR, e);
    }
    syncPartitions(partitionsToAdd, partitionsToDrop, syncMode, metastore, session, table);
}
Also used : Path(org.apache.hadoop.fs.Path) MethodHandle(java.lang.invoke.MethodHandle) Table(com.facebook.presto.hive.metastore.Table) Provider(javax.inject.Provider) Column(com.facebook.presto.hive.metastore.Column) FileSystem(org.apache.hadoop.fs.FileSystem) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) PrestoException(com.facebook.presto.spi.PrestoException) FileStatus(org.apache.hadoop.fs.FileStatus) Supplier(java.util.function.Supplier) Partition(com.facebook.presto.hive.metastore.Partition) Inject(javax.inject.Inject) HashSet(java.util.HashSet) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Path(org.apache.hadoop.fs.Path) ThreadContextClassLoader(com.facebook.presto.spi.classloader.ThreadContextClassLoader) ENGLISH(java.util.Locale.ENGLISH) Argument(com.facebook.presto.spi.procedure.Procedure.Argument) BOOLEAN(com.facebook.presto.common.type.StandardTypes.BOOLEAN) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) IOException(java.io.IOException) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) Sets(com.google.common.collect.Sets) ConnectorSession(com.facebook.presto.spi.ConnectorSession) VARCHAR(com.facebook.presto.common.type.StandardTypes.VARCHAR) INVALID_PROCEDURE_ARGUMENT(com.facebook.presto.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT) MethodHandleUtil.methodHandle(com.facebook.presto.common.block.MethodHandleUtil.methodHandle) Procedure(com.facebook.presto.spi.procedure.Procedure) List(java.util.List) HIVE_FILESYSTEM_ERROR(com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Stream(java.util.stream.Stream) MetastoreUtil.extractPartitionValues(com.facebook.presto.hive.metastore.MetastoreUtil.extractPartitionValues) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) MetastoreUtil.getMetastoreHeaders(com.facebook.presto.hive.metastore.MetastoreUtil.getMetastoreHeaders) MetastoreUtil.isUserDefinedTypeEncodingEnabled(com.facebook.presto.hive.metastore.MetastoreUtil.isUserDefinedTypeEncodingEnabled) PRESTO_QUERY_ID_NAME(com.facebook.presto.hive.metastore.MetastoreUtil.PRESTO_QUERY_ID_NAME) TRUE(java.lang.Boolean.TRUE) Table(com.facebook.presto.hive.metastore.Table) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 93 with TableNotFoundException

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

the class AbstractTestHiveClient method dropTable.

protected void dropTable(SchemaTableName table) {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        ConnectorTableHandle handle = metadata.getTableHandle(session, table);
        if (handle == null) {
            return;
        }
        metadata.dropTable(session, handle);
        try {
            // todo I have no idea why this is needed... maybe there is a propagation delay in the metastore?
            metadata.dropTable(session, handle);
            fail("expected NotFoundException");
        } catch (TableNotFoundException expected) {
        }
        transaction.commit();
    } catch (Exception e) {
        Logger.get(getClass()).warn(e, "failed to drop table");
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) SkipException(org.testng.SkipException) IOException(java.io.IOException) ViewNotFoundException(com.facebook.presto.spi.ViewNotFoundException) PrestoException(com.facebook.presto.spi.PrestoException) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle)

Example 94 with TableNotFoundException

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

the class AbstractTestHiveClient method eraseStatistics.

private void eraseStatistics(SchemaTableName schemaTableName) {
    ExtendedHiveMetastore metastoreClient = getMetastoreClient();
    metastoreClient.updateTableStatistics(METASTORE_CONTEXT, schemaTableName.getSchemaName(), schemaTableName.getTableName(), statistics -> new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of()));
    Table table = metastoreClient.getTable(METASTORE_CONTEXT, schemaTableName.getSchemaName(), schemaTableName.getTableName()).orElseThrow(() -> new TableNotFoundException(schemaTableName));
    List<String> partitionColumns = table.getPartitionColumns().stream().map(Column::getName).collect(toImmutableList());
    if (!table.getPartitionColumns().isEmpty()) {
        List<String> partitionNames = metastoreClient.getPartitionNames(METASTORE_CONTEXT, schemaTableName.getSchemaName(), schemaTableName.getTableName()).orElse(ImmutableList.of());
        List<Partition> partitions = metastoreClient.getPartitionsByNames(METASTORE_CONTEXT, schemaTableName.getSchemaName(), schemaTableName.getTableName(), partitionNames).entrySet().stream().map(Map.Entry::getValue).filter(Optional::isPresent).map(Optional::get).collect(toImmutableList());
        for (Partition partition : partitions) {
            metastoreClient.updatePartitionStatistics(METASTORE_CONTEXT, schemaTableName.getSchemaName(), schemaTableName.getTableName(), makePartName(partitionColumns, partition.getValues()), statistics -> new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of()));
        }
    }
}
Also used : TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Partition(com.facebook.presto.hive.metastore.Partition) Table(com.facebook.presto.hive.metastore.Table) Optional(java.util.Optional) PartitionStatistics(com.facebook.presto.hive.metastore.PartitionStatistics) ExtendedHiveMetastore(com.facebook.presto.hive.metastore.ExtendedHiveMetastore) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 95 with TableNotFoundException

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

the class PrometheusMetadata method getColumnHandles.

@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
    PrometheusTableHandle prometheusTableHandle = (PrometheusTableHandle) tableHandle;
    PrometheusTable table = prometheusClient.getTable(prometheusTableHandle.getSchemaName(), prometheusTableHandle.getTableName());
    if (table == null) {
        throw new TableNotFoundException(prometheusTableHandle.toSchemaTableName());
    }
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    int index = 0;
    for (ColumnMetadata column : table.getColumnsMetadata()) {
        columnHandles.put(column.getName(), new PrometheusColumnHandle(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)

Aggregations

TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)95 SchemaTableName (com.facebook.presto.spi.SchemaTableName)68 PrestoException (com.facebook.presto.spi.PrestoException)38 Table (com.facebook.presto.hive.metastore.Table)36 ImmutableMap (com.google.common.collect.ImmutableMap)33 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)28 ImmutableList (com.google.common.collect.ImmutableList)28 List (java.util.List)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)23 ColumnHandle (com.facebook.presto.spi.ColumnHandle)22 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)20 Constraint (com.facebook.presto.spi.Constraint)20 Map (java.util.Map)20 Set (java.util.Set)20 Optional (java.util.Optional)19 Column (com.facebook.presto.hive.metastore.Column)18 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)18 HashSet (java.util.HashSet)18 SystemTable (com.facebook.presto.spi.SystemTable)17 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)17