Search in sources :

Example 1 with HIVE_FILESYSTEM_ERROR

use of com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR 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)

Aggregations

MethodHandleUtil.methodHandle (com.facebook.presto.common.block.MethodHandleUtil.methodHandle)1 BOOLEAN (com.facebook.presto.common.type.StandardTypes.BOOLEAN)1 VARCHAR (com.facebook.presto.common.type.StandardTypes.VARCHAR)1 HIVE_FILESYSTEM_ERROR (com.facebook.presto.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR)1 Column (com.facebook.presto.hive.metastore.Column)1 MetastoreContext (com.facebook.presto.hive.metastore.MetastoreContext)1 PRESTO_QUERY_ID_NAME (com.facebook.presto.hive.metastore.MetastoreUtil.PRESTO_QUERY_ID_NAME)1 MetastoreUtil.extractPartitionValues (com.facebook.presto.hive.metastore.MetastoreUtil.extractPartitionValues)1 MetastoreUtil.getMetastoreHeaders (com.facebook.presto.hive.metastore.MetastoreUtil.getMetastoreHeaders)1 MetastoreUtil.isUserDefinedTypeEncodingEnabled (com.facebook.presto.hive.metastore.MetastoreUtil.isUserDefinedTypeEncodingEnabled)1 Partition (com.facebook.presto.hive.metastore.Partition)1 PartitionStatistics (com.facebook.presto.hive.metastore.PartitionStatistics)1 SemiTransactionalHiveMetastore (com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore)1 Table (com.facebook.presto.hive.metastore.Table)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 PrestoException (com.facebook.presto.spi.PrestoException)1 SchemaTableName (com.facebook.presto.spi.SchemaTableName)1 INVALID_PROCEDURE_ARGUMENT (com.facebook.presto.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT)1 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)1 ThreadContextClassLoader (com.facebook.presto.spi.classloader.ThreadContextClassLoader)1