Search in sources :

Example 1 with HIVE_FILESYSTEM_ERROR

use of io.prestosql.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR in project hetu-core by openlookeng.

the class SyncPartitionMetadataProcedure method doSyncPartitionMetadata.

private void doSyncPartitionMetadata(ConnectorSession session, String schemaName, String tableName, String mode) {
    SyncMode syncMode = toSyncMode(mode);
    HdfsContext hdfsContext = new HdfsContext(session, schemaName, tableName);
    HiveIdentity identity = new HiveIdentity(session);
    SemiTransactionalHiveMetastore metastore = ((HiveMetadata) hiveMetadataFactory.get()).getMetastore();
    SchemaTableName schemaTableName = new SchemaTableName(schemaName, tableName);
    Table table = metastore.getTable(identity, 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());
    Set<String> partitionsToAdd;
    Set<String> partitionsToDrop;
    try {
        FileSystem fileSystem = hdfsEnvironment.getFileSystem(hdfsContext, tableLocation);
        List<String> partitionsInMetastore = metastore.getPartitionNames(identity, schemaName, tableName).orElseThrow(() -> new TableNotFoundException(schemaTableName));
        List<String> partitionsInFileSystem = listDirectory(fileSystem, fileSystem.getFileStatus(tableLocation), table.getPartitionColumns(), table.getPartitionColumns().size()).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) Partition(io.prestosql.plugin.hive.metastore.Partition) Provider(javax.inject.Provider) FileSystem(org.apache.hadoop.fs.FileSystem) HIVE_FILESYSTEM_ERROR(io.prestosql.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext) Argument(io.prestosql.spi.procedure.Procedure.Argument) PRESTO_QUERY_ID_NAME(io.prestosql.plugin.hive.HiveMetadata.PRESTO_QUERY_ID_NAME) FileStatus(org.apache.hadoop.fs.FileStatus) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) HashSet(java.util.HashSet) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Procedure(io.prestosql.spi.procedure.Procedure) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) HivePartitionManager.extractPartitionValues(io.prestosql.plugin.hive.HivePartitionManager.extractPartitionValues) Objects.requireNonNull(java.util.Objects.requireNonNull) Path(org.apache.hadoop.fs.Path) INVALID_PROCEDURE_ARGUMENT(io.prestosql.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) ENGLISH(java.util.Locale.ENGLISH) VARCHAR(io.prestosql.spi.type.StandardTypes.VARCHAR) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) PrestoException(io.prestosql.spi.PrestoException) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) IOException(java.io.IOException) ThreadContextClassLoader(io.prestosql.spi.classloader.ThreadContextClassLoader) MethodHandleUtil.methodHandle(io.prestosql.spi.block.MethodHandleUtil.methodHandle) Sets(com.google.common.collect.Sets) List(java.util.List) Stream(java.util.stream.Stream) Table(io.prestosql.plugin.hive.metastore.Table) Column(io.prestosql.plugin.hive.metastore.Column) Table(io.prestosql.plugin.hive.metastore.Table) SemiTransactionalHiveMetastore(io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore) PrestoException(io.prestosql.spi.PrestoException) IOException(java.io.IOException) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) HiveIdentity(io.prestosql.plugin.hive.authentication.HiveIdentity) TableNotFoundException(io.prestosql.spi.connector.TableNotFoundException) FileSystem(org.apache.hadoop.fs.FileSystem) HdfsContext(io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Sets (com.google.common.collect.Sets)1 HdfsContext (io.prestosql.plugin.hive.HdfsEnvironment.HdfsContext)1 HIVE_FILESYSTEM_ERROR (io.prestosql.plugin.hive.HiveErrorCode.HIVE_FILESYSTEM_ERROR)1 PRESTO_QUERY_ID_NAME (io.prestosql.plugin.hive.HiveMetadata.PRESTO_QUERY_ID_NAME)1 HivePartitionManager.extractPartitionValues (io.prestosql.plugin.hive.HivePartitionManager.extractPartitionValues)1 HiveIdentity (io.prestosql.plugin.hive.authentication.HiveIdentity)1 Column (io.prestosql.plugin.hive.metastore.Column)1 Partition (io.prestosql.plugin.hive.metastore.Partition)1 SemiTransactionalHiveMetastore (io.prestosql.plugin.hive.metastore.SemiTransactionalHiveMetastore)1 Table (io.prestosql.plugin.hive.metastore.Table)1 PrestoException (io.prestosql.spi.PrestoException)1 INVALID_PROCEDURE_ARGUMENT (io.prestosql.spi.StandardErrorCode.INVALID_PROCEDURE_ARGUMENT)1 MethodHandleUtil.methodHandle (io.prestosql.spi.block.MethodHandleUtil.methodHandle)1 ThreadContextClassLoader (io.prestosql.spi.classloader.ThreadContextClassLoader)1 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)1 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)1 TableNotFoundException (io.prestosql.spi.connector.TableNotFoundException)1