Search in sources :

Example 11 with HiveType

use of io.trino.plugin.hive.HiveType in project trino by trinodb.

the class ThriftHiveMetastore method updateTableStatistics.

@Override
public void updateTableStatistics(HiveIdentity identity, String databaseName, String tableName, AcidTransaction transaction, Function<PartitionStatistics, PartitionStatistics> update) {
    Table originalTable = getTable(identity, databaseName, tableName).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    PartitionStatistics currentStatistics = getTableStatistics(identity, originalTable);
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    Table modifiedTable = originalTable.deepCopy();
    HiveBasicStatistics basicStatistics = updatedStatistics.getBasicStatistics();
    modifiedTable.setParameters(updateStatisticsParameters(modifiedTable.getParameters(), basicStatistics));
    if (transaction.isAcidTransactionRunning()) {
        modifiedTable.setWriteId(transaction.getWriteId());
    }
    alterTable(identity, databaseName, tableName, modifiedTable);
    io.trino.plugin.hive.metastore.Table table = fromMetastoreApiTable(modifiedTable);
    OptionalLong rowCount = basicStatistics.getRowCount();
    List<ColumnStatisticsObj> metastoreColumnStatistics = updatedStatistics.getColumnStatistics().entrySet().stream().flatMap(entry -> {
        Optional<Column> column = table.getColumn(entry.getKey());
        if (column.isEmpty() && isAvroTableWithSchemaSet(modifiedTable)) {
            // to store statistics for a column it does not know about.
            return Stream.of();
        }
        HiveType type = column.orElseThrow(() -> new IllegalStateException("Column not found: " + entry.getKey())).getType();
        return Stream.of(createMetastoreColumnStatistics(entry.getKey(), type, entry.getValue(), rowCount));
    }).collect(toImmutableList());
    if (!metastoreColumnStatistics.isEmpty()) {
        setTableColumnStatistics(identity, databaseName, tableName, metastoreColumnStatistics);
    }
    Set<String> removedColumnStatistics = difference(currentStatistics.getColumnStatistics().keySet(), updatedStatistics.getColumnStatistics().keySet());
    removedColumnStatistics.forEach(column -> deleteTableColumnStatistics(identity, databaseName, tableName, column));
}
Also used : ThriftMetastoreUtil.updateStatisticsParameters(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.updateStatisticsParameters) LockComponentBuilder(org.apache.hadoop.hive.metastore.LockComponentBuilder) USER(io.trino.spi.security.PrincipalType.USER) UNKNOWN_METHOD(org.apache.thrift.TApplicationException.UNKNOWN_METHOD) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) Sets.difference(com.google.common.collect.Sets.difference) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Column(io.trino.plugin.hive.metastore.Column) Map(java.util.Map) PartitionWithStatistics(io.trino.plugin.hive.metastore.PartitionWithStatistics) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) HiveIdentity(io.trino.plugin.hive.authentication.HiveIdentity) AcidTransaction(io.trino.plugin.hive.acid.AcidTransaction) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity) HivePartition(io.trino.plugin.hive.HivePartition) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) OWNERSHIP(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP) MetastoreUtil.partitionKeyFilterToStringList(io.trino.plugin.hive.metastore.MetastoreUtil.partitionKeyFilterToStringList) TRUE(java.lang.Boolean.TRUE) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) LockType(org.apache.hadoop.hive.metastore.api.LockType) TxnAbortedException(org.apache.hadoop.hive.metastore.api.TxnAbortedException) Verify.verifyNotNull(com.google.common.base.Verify.verifyNotNull) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) HiveViewNotSupportedException(io.trino.plugin.hive.HiveViewNotSupportedException) Flatten(org.weakref.jmx.Flatten) ThriftMetastoreUtil.toMetastoreApiPartition(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiPartition) HIVE_FILTER_FIELD_PARAMS(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) ThriftMetastoreUtil.isAvroTableWithSchemaSet(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isAvroTableWithSchemaSet) HIVE_TABLE_LOCK_NOT_ACQUIRED(io.trino.plugin.hive.HiveErrorCode.HIVE_TABLE_LOCK_NOT_ACQUIRED) ThriftMetastoreUtil.fromMetastoreApiPrincipalType(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiPrincipalType) DataOperationType(org.apache.hadoop.hive.metastore.api.DataOperationType) HiveType(io.trino.plugin.hive.HiveType) OptionalLong(java.util.OptionalLong) Managed(org.weakref.jmx.Managed) LockState(org.apache.hadoop.hive.metastore.api.LockState) SchemaAlreadyExistsException(io.trino.plugin.hive.SchemaAlreadyExistsException) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) FileUtils.makePartName(org.apache.hadoop.hive.common.FileUtils.makePartName) EnvironmentContext(org.apache.hadoop.hive.metastore.api.EnvironmentContext) TException(org.apache.thrift.TException) ThriftMetastoreAuthenticationType(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreAuthenticationConfig.ThriftMetastoreAuthenticationType) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Throwables.throwIfInstanceOf(com.google.common.base.Throwables.throwIfInstanceOf) RoleGrant(io.trino.spi.security.RoleGrant) Table(org.apache.hadoop.hive.metastore.api.Table) System.nanoTime(java.lang.System.nanoTime) TableType(org.apache.hadoop.hive.metastore.TableType) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) HivePrivilege(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) AcidOperation(io.trino.plugin.hive.acid.AcidOperation) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) Duration(io.airlift.units.Duration) NonEvictableLoadingCache(io.trino.collect.cache.NonEvictableLoadingCache) AcidTransactionOwner(io.trino.plugin.hive.metastore.AcidTransactionOwner) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Throwables.propagateIfPossible(com.google.common.base.Throwables.propagateIfPossible) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ALREADY_EXISTS(io.trino.spi.StandardErrorCode.ALREADY_EXISTS) Path(org.apache.hadoop.fs.Path) LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) ThriftMetastoreUtil.fromTrinoPrincipalType(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromTrinoPrincipalType) PrivilegeBag(org.apache.hadoop.hive.metastore.api.PrivilegeBag) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) LockRequestBuilder(org.apache.hadoop.hive.metastore.LockRequestBuilder) Predicate(java.util.function.Predicate) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) TableAlreadyExistsException(io.trino.plugin.hive.TableAlreadyExistsException) TrinoException(io.trino.spi.TrinoException) String.format(java.lang.String.format) CacheLoader(com.google.common.cache.CacheLoader) SafeCaches.buildNonEvictableCache(io.trino.collect.cache.SafeCaches.buildNonEvictableCache) PRESTO_VIEW_FLAG(io.trino.plugin.hive.ViewReaderUtil.PRESTO_VIEW_FLAG) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) List(java.util.List) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) Pattern(java.util.regex.Pattern) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) RetryDriver(io.trino.plugin.hive.util.RetryDriver) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Logger(io.airlift.log.Logger) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) Type(io.trino.spi.type.Type) Partition(org.apache.hadoop.hive.metastore.api.Partition) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TxnToWriteId(org.apache.hadoop.hive.metastore.api.TxnToWriteId) Inject(javax.inject.Inject) HashSet(java.util.HashSet) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) LockLevel(org.apache.hadoop.hive.metastore.api.LockLevel) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) HIVE_METASTORE_ERROR(io.trino.plugin.hive.HiveErrorCode.HIVE_METASTORE_ERROR) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Objects.requireNonNull(java.util.Objects.requireNonNull) TApplicationException(org.apache.thrift.TApplicationException) FALSE(java.lang.Boolean.FALSE) TABLE(org.apache.hadoop.hive.metastore.api.HiveObjectType.TABLE) Iterator(java.util.Iterator) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TupleDomain(io.trino.spi.predicate.TupleDomain) ThriftMetastoreUtil.fromRolePrincipalGrants(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromRolePrincipalGrants) ThriftMetastoreUtil.createMetastoreColumnStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.createMetastoreColumnStatistics) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ThriftMetastoreUtil.parsePrivilege(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.parsePrivilege) Closeable(java.io.Closeable) Database(org.apache.hadoop.hive.metastore.api.Database) Collections(java.util.Collections) HiveConfig(io.trino.plugin.hive.HiveConfig) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Table(org.apache.hadoop.hive.metastore.api.Table) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) Optional(java.util.Optional) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) SchemaTableName(io.trino.spi.connector.SchemaTableName) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) OptionalLong(java.util.OptionalLong) HiveType(io.trino.plugin.hive.HiveType)

Example 12 with HiveType

use of io.trino.plugin.hive.HiveType in project trino by trinodb.

the class ThriftHiveMetastore method updatePartitionStatistics.

@Override
public void updatePartitionStatistics(HiveIdentity identity, Table table, String partitionName, Function<PartitionStatistics, PartitionStatistics> update) {
    List<Partition> partitions = getPartitionsByNames(identity, table.getDbName(), table.getTableName(), ImmutableList.of(partitionName));
    if (partitions.size() != 1) {
        throw new TrinoException(HIVE_METASTORE_ERROR, "Metastore returned multiple partitions for name: " + partitionName);
    }
    Partition originalPartition = getOnlyElement(partitions);
    PartitionStatistics currentStatistics = requireNonNull(getPartitionStatistics(identity, table, partitions).get(partitionName), "getPartitionStatistics() did not return statistics for partition");
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    Partition modifiedPartition = originalPartition.deepCopy();
    HiveBasicStatistics basicStatistics = updatedStatistics.getBasicStatistics();
    modifiedPartition.setParameters(updateStatisticsParameters(modifiedPartition.getParameters(), basicStatistics));
    alterPartitionWithoutStatistics(identity, table.getDbName(), table.getTableName(), modifiedPartition);
    Map<String, HiveType> columns = modifiedPartition.getSd().getCols().stream().collect(toImmutableMap(FieldSchema::getName, schema -> HiveType.valueOf(schema.getType())));
    setPartitionColumnStatistics(identity, table.getDbName(), table.getTableName(), partitionName, columns, updatedStatistics.getColumnStatistics(), basicStatistics.getRowCount());
    Set<String> removedStatistics = difference(currentStatistics.getColumnStatistics().keySet(), updatedStatistics.getColumnStatistics().keySet());
    removedStatistics.forEach(column -> deletePartitionColumnStatistics(identity, table.getDbName(), table.getTableName(), partitionName, column));
}
Also used : ThriftMetastoreUtil.updateStatisticsParameters(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.updateStatisticsParameters) LockComponentBuilder(org.apache.hadoop.hive.metastore.LockComponentBuilder) USER(io.trino.spi.security.PrincipalType.USER) UNKNOWN_METHOD(org.apache.thrift.TApplicationException.UNKNOWN_METHOD) Throwables.throwIfUnchecked(com.google.common.base.Throwables.throwIfUnchecked) NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) Sets.difference(com.google.common.collect.Sets.difference) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Column(io.trino.plugin.hive.metastore.Column) Map(java.util.Map) PartitionWithStatistics(io.trino.plugin.hive.metastore.PartitionWithStatistics) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) HiveIdentity(io.trino.plugin.hive.authentication.HiveIdentity) AcidTransaction(io.trino.plugin.hive.acid.AcidTransaction) HdfsEnvironment(io.trino.plugin.hive.HdfsEnvironment) ConnectorIdentity(io.trino.spi.security.ConnectorIdentity) HivePartition(io.trino.plugin.hive.HivePartition) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ThreadSafe(javax.annotation.concurrent.ThreadSafe) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MANAGED_TABLE(org.apache.hadoop.hive.metastore.TableType.MANAGED_TABLE) SchemaTableName(io.trino.spi.connector.SchemaTableName) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Stream(java.util.stream.Stream) OWNERSHIP(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege.OWNERSHIP) MetastoreUtil.partitionKeyFilterToStringList(io.trino.plugin.hive.metastore.MetastoreUtil.partitionKeyFilterToStringList) TRUE(java.lang.Boolean.TRUE) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) LockType(org.apache.hadoop.hive.metastore.api.LockType) TxnAbortedException(org.apache.hadoop.hive.metastore.api.TxnAbortedException) Verify.verifyNotNull(com.google.common.base.Verify.verifyNotNull) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) ConfigValSecurityException(org.apache.hadoop.hive.metastore.api.ConfigValSecurityException) HiveViewNotSupportedException(io.trino.plugin.hive.HiveViewNotSupportedException) Flatten(org.weakref.jmx.Flatten) ThriftMetastoreUtil.toMetastoreApiPartition(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiPartition) HIVE_FILTER_FIELD_PARAMS(org.apache.hadoop.hive.metastore.api.hive_metastoreConstants.HIVE_FILTER_FIELD_PARAMS) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) PartitionNotFoundException(io.trino.plugin.hive.PartitionNotFoundException) ThriftMetastoreUtil.isAvroTableWithSchemaSet(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isAvroTableWithSchemaSet) HIVE_TABLE_LOCK_NOT_ACQUIRED(io.trino.plugin.hive.HiveErrorCode.HIVE_TABLE_LOCK_NOT_ACQUIRED) ThriftMetastoreUtil.fromMetastoreApiPrincipalType(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiPrincipalType) DataOperationType(org.apache.hadoop.hive.metastore.api.DataOperationType) HiveType(io.trino.plugin.hive.HiveType) OptionalLong(java.util.OptionalLong) Managed(org.weakref.jmx.Managed) LockState(org.apache.hadoop.hive.metastore.api.LockState) SchemaAlreadyExistsException(io.trino.plugin.hive.SchemaAlreadyExistsException) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) FileUtils.makePartName(org.apache.hadoop.hive.common.FileUtils.makePartName) EnvironmentContext(org.apache.hadoop.hive.metastore.api.EnvironmentContext) TException(org.apache.thrift.TException) ThriftMetastoreAuthenticationType(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreAuthenticationConfig.ThriftMetastoreAuthenticationType) PrincipalType(org.apache.hadoop.hive.metastore.api.PrincipalType) IOException(java.io.IOException) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Throwables.throwIfInstanceOf(com.google.common.base.Throwables.throwIfInstanceOf) RoleGrant(io.trino.spi.security.RoleGrant) Table(org.apache.hadoop.hive.metastore.api.Table) System.nanoTime(java.lang.System.nanoTime) TableType(org.apache.hadoop.hive.metastore.TableType) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) HivePrivilege(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) LockRequest(org.apache.hadoop.hive.metastore.api.LockRequest) AcidOperation(io.trino.plugin.hive.acid.AcidOperation) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) Duration(io.airlift.units.Duration) NonEvictableLoadingCache(io.trino.collect.cache.NonEvictableLoadingCache) AcidTransactionOwner(io.trino.plugin.hive.metastore.AcidTransactionOwner) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Throwables.propagateIfPossible(com.google.common.base.Throwables.propagateIfPossible) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ALREADY_EXISTS(io.trino.spi.StandardErrorCode.ALREADY_EXISTS) Path(org.apache.hadoop.fs.Path) LockComponent(org.apache.hadoop.hive.metastore.api.LockComponent) ThriftMetastoreUtil.fromTrinoPrincipalType(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromTrinoPrincipalType) PrivilegeBag(org.apache.hadoop.hive.metastore.api.PrivilegeBag) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) NoSuchLockException(org.apache.hadoop.hive.metastore.api.NoSuchLockException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) LockRequestBuilder(org.apache.hadoop.hive.metastore.LockRequestBuilder) Predicate(java.util.function.Predicate) ColumnStatisticsObj(org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj) LockResponse(org.apache.hadoop.hive.metastore.api.LockResponse) TableAlreadyExistsException(io.trino.plugin.hive.TableAlreadyExistsException) TrinoException(io.trino.spi.TrinoException) String.format(java.lang.String.format) CacheLoader(com.google.common.cache.CacheLoader) SafeCaches.buildNonEvictableCache(io.trino.collect.cache.SafeCaches.buildNonEvictableCache) PRESTO_VIEW_FLAG(io.trino.plugin.hive.ViewReaderUtil.PRESTO_VIEW_FLAG) HdfsContext(io.trino.plugin.hive.HdfsEnvironment.HdfsContext) List(java.util.List) Optional(java.util.Optional) CacheBuilder(com.google.common.cache.CacheBuilder) Pattern(java.util.regex.Pattern) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) RetryDriver(io.trino.plugin.hive.util.RetryDriver) HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Logger(io.airlift.log.Logger) MetastoreConfig(io.trino.plugin.hive.metastore.MetastoreConfig) Type(io.trino.spi.type.Type) Partition(org.apache.hadoop.hive.metastore.api.Partition) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) TxnToWriteId(org.apache.hadoop.hive.metastore.api.TxnToWriteId) Inject(javax.inject.Inject) HashSet(java.util.HashSet) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) LockLevel(org.apache.hadoop.hive.metastore.api.LockLevel) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) HIVE_METASTORE_ERROR(io.trino.plugin.hive.HiveErrorCode.HIVE_METASTORE_ERROR) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) Objects.requireNonNull(java.util.Objects.requireNonNull) TApplicationException(org.apache.thrift.TApplicationException) FALSE(java.lang.Boolean.FALSE) TABLE(org.apache.hadoop.hive.metastore.api.HiveObjectType.TABLE) Iterator(java.util.Iterator) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) TupleDomain(io.trino.spi.predicate.TupleDomain) ThriftMetastoreUtil.fromRolePrincipalGrants(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromRolePrincipalGrants) ThriftMetastoreUtil.createMetastoreColumnStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.createMetastoreColumnStatistics) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) ThriftMetastoreUtil.parsePrivilege(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.parsePrivilege) Closeable(java.io.Closeable) Database(org.apache.hadoop.hive.metastore.api.Database) Collections(java.util.Collections) HiveConfig(io.trino.plugin.hive.HiveConfig) SECONDS(java.util.concurrent.TimeUnit.SECONDS) HivePartition(io.trino.plugin.hive.HivePartition) ThriftMetastoreUtil.toMetastoreApiPartition(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiPartition) Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) TrinoException(io.trino.spi.TrinoException) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) HiveType(io.trino.plugin.hive.HiveType)

Example 13 with HiveType

use of io.trino.plugin.hive.HiveType in project trino by trinodb.

the class ThriftHiveMetastore method storePartitionColumnStatistics.

private void storePartitionColumnStatistics(HiveIdentity identity, String databaseName, String tableName, String partitionName, PartitionWithStatistics partitionWithStatistics) {
    PartitionStatistics statistics = partitionWithStatistics.getStatistics();
    Map<String, HiveColumnStatistics> columnStatistics = statistics.getColumnStatistics();
    if (columnStatistics.isEmpty()) {
        return;
    }
    Map<String, HiveType> columnTypes = partitionWithStatistics.getPartition().getColumns().stream().collect(toImmutableMap(Column::getName, Column::getType));
    setPartitionColumnStatistics(identity, databaseName, tableName, partitionName, columnTypes, columnStatistics, statistics.getBasicStatistics().getRowCount());
}
Also used : PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) HiveType(io.trino.plugin.hive.HiveType)

Example 14 with HiveType

use of io.trino.plugin.hive.HiveType in project trino by trinodb.

the class OrcTypeToHiveTypeTranslator method fromOrcTypeToHiveType.

public static HiveType fromOrcTypeToHiveType(OrcType orcType, ColumnMetadata<OrcType> columnMetadata) {
    switch(orcType.getOrcTypeKind()) {
        case BOOLEAN:
            return HIVE_BOOLEAN;
        case FLOAT:
            return HIVE_FLOAT;
        case DOUBLE:
            return HIVE_DOUBLE;
        case BYTE:
            return HIVE_BYTE;
        case DATE:
            return HIVE_DATE;
        case SHORT:
            return HIVE_SHORT;
        case INT:
            return HIVE_INT;
        case LONG:
            return HIVE_LONG;
        case DECIMAL:
            checkArgument(orcType.getPrecision().isPresent(), "orcType.getPrecision() is not present");
            checkArgument(orcType.getScale().isPresent(), "orcType.getScale() is not present");
            return toHiveType(new DecimalTypeInfo(orcType.getPrecision().get(), orcType.getScale().get()));
        case TIMESTAMP:
            return HIVE_TIMESTAMP;
        case BINARY:
            return HIVE_BINARY;
        case CHAR:
        case VARCHAR:
        case STRING:
            return HIVE_STRING;
        case LIST:
            {
                HiveType elementType = fromOrcTypeToHiveType(columnMetadata.get(orcType.getFieldTypeIndex(0)), columnMetadata);
                return toHiveType(getListTypeInfo(elementType.getTypeInfo()));
            }
        case MAP:
            {
                HiveType keyType = getHiveType(orcType, 0, columnMetadata);
                HiveType elementType = getHiveType(orcType, 1, columnMetadata);
                return toHiveType(getMapTypeInfo(keyType.getTypeInfo(), elementType.getTypeInfo()));
            }
        case STRUCT:
            {
                ImmutableList.Builder<TypeInfo> fieldTypeInfo = ImmutableList.builder();
                for (int fieldId = 0; fieldId < orcType.getFieldCount(); fieldId++) {
                    fieldTypeInfo.add(getHiveType(orcType, fieldId, columnMetadata).getTypeInfo());
                }
                return toHiveType(getStructTypeInfo(orcType.getFieldNames(), fieldTypeInfo.build()));
            }
        case TIMESTAMP_INSTANT:
        case UNION:
            // unsupported
            break;
    }
    throw new VerifyException("Unhandled ORC type: " + orcType.getOrcTypeKind());
}
Also used : DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) VerifyException(com.google.common.base.VerifyException) HiveType(io.trino.plugin.hive.HiveType) HiveType.toHiveType(io.trino.plugin.hive.HiveType.toHiveType)

Example 15 with HiveType

use of io.trino.plugin.hive.HiveType in project trino by trinodb.

the class TestHiveBucketing method assertBucketsEqual.

private static void assertBucketsEqual(List<String> hiveTypeStrings, List<List<Object>> hiveValues, int bucketCount, Optional<Set<Integer>> expectedBucketsV1, Optional<Set<Integer>> expectedBucketsV2) {
    List<HiveType> hiveTypes = hiveTypeStrings.stream().map(HiveType::valueOf).collect(toImmutableList());
    List<TypeInfo> hiveTypeInfos = hiveTypes.stream().map(HiveType::getTypeInfo).collect(toImmutableList());
    List<Type> trinoTypes = hiveTypes.stream().map(type -> type.getType(TESTING_TYPE_MANAGER)).collect(toImmutableList());
    ImmutableList.Builder<List<NullableValue>> values = ImmutableList.builder();
    for (int i = 0; i < hiveValues.size(); i++) {
        List<Object> valueList = hiveValues.get(i);
        Type trinoType = trinoTypes.get(i);
        values.add(valueList.stream().map(value -> new NullableValue(trinoType, toNativeContainerValue(trinoType, value))).collect(toImmutableList()));
    }
    assertEquals(getHiveBuckets(BUCKETING_V1, bucketCount, hiveTypeInfos, values.build()), expectedBucketsV1);
    assertEquals(getHiveBuckets(BUCKETING_V2, bucketCount, hiveTypeInfos, values.build()), expectedBucketsV2);
}
Also used : DateType(io.trino.spi.type.DateType) BUCKETING_V2(io.trino.plugin.hive.util.HiveBucketing.BucketingVersion.BUCKETING_V2) Test(org.testng.annotations.Test) Date(org.apache.hadoop.hive.common.type.Date) BooleanType(io.trino.spi.type.BooleanType) BUCKETING_V1(io.trino.plugin.hive.util.HiveBucketing.BucketingVersion.BUCKETING_V1) Block(io.trino.spi.block.Block) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) Map(java.util.Map) AssertionsForClassTypes.assertThatThrownBy(org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Double.longBitsToDouble(java.lang.Double.longBitsToDouble) SmallintType(io.trino.spi.type.SmallintType) RowType(io.trino.spi.type.RowType) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ArrayType(io.trino.spi.type.ArrayType) TypeUtils.writeNativeValue(io.trino.spi.type.TypeUtils.writeNativeValue) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) BucketingVersion(io.trino.plugin.hive.util.HiveBucketing.BucketingVersion) Entry(java.util.Map.Entry) Optional(java.util.Optional) TypeInfoFactory.timestampTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo) TypeInfoUtils(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils) JavaHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveVarcharObjectInspector) NullableValue(io.trino.spi.predicate.NullableValue) DoubleType(io.trino.spi.type.DoubleType) Type(io.trino.spi.type.Type) Page(io.trino.spi.Page) Assert.assertEquals(org.testng.Assert.assertEquals) HiveBucketing.getHiveBuckets(io.trino.plugin.hive.util.HiveBucketing.getHiveBuckets) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) ObjectInspectorUtils(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorUtils) TimestampType(io.trino.spi.type.TimestampType) ArrayList(java.util.ArrayList) HiveType(io.trino.plugin.hive.HiveType) BigintType(io.trino.spi.type.BigintType) VarcharType(io.trino.spi.type.VarcharType) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) ImmutableList(com.google.common.collect.ImmutableList) TinyintType(io.trino.spi.type.TinyintType) IntegerType(io.trino.spi.type.IntegerType) MapType(io.trino.spi.type.MapType) TESTING_TYPE_MANAGER(io.trino.type.InternalTypeManager.TESTING_TYPE_MANAGER) Maps(com.google.common.collect.Maps) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) RealType(io.trino.spi.type.RealType) BlockBuilder(io.trino.spi.block.BlockBuilder) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) NullableValue(io.trino.spi.predicate.NullableValue) TypeInfoFactory.timestampTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.timestampTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) DateType(io.trino.spi.type.DateType) BooleanType(io.trino.spi.type.BooleanType) TimestampType.createTimestampType(io.trino.spi.type.TimestampType.createTimestampType) SmallintType(io.trino.spi.type.SmallintType) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) DoubleType(io.trino.spi.type.DoubleType) Type(io.trino.spi.type.Type) TimestampType(io.trino.spi.type.TimestampType) HiveType(io.trino.plugin.hive.HiveType) BigintType(io.trino.spi.type.BigintType) VarcharType(io.trino.spi.type.VarcharType) TinyintType(io.trino.spi.type.TinyintType) IntegerType(io.trino.spi.type.IntegerType) MapType(io.trino.spi.type.MapType) RealType(io.trino.spi.type.RealType) Arrays.asList(java.util.Arrays.asList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) HiveType(io.trino.plugin.hive.HiveType)

Aggregations

HiveType (io.trino.plugin.hive.HiveType)15 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)8 ImmutableList (com.google.common.collect.ImmutableList)7 Column (io.trino.plugin.hive.metastore.Column)6 HiveColumnStatistics (io.trino.plugin.hive.metastore.HiveColumnStatistics)5 TrinoException (io.trino.spi.TrinoException)5 List (java.util.List)5 Map (java.util.Map)5 Optional (java.util.Optional)5 Type (io.trino.spi.type.Type)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 PartitionStatistics (io.trino.plugin.hive.PartitionStatistics)3 Set (java.util.Set)3 BinaryColumnStatisticsData (com.amazonaws.services.glue.model.BinaryColumnStatisticsData)2 BooleanColumnStatisticsData (com.amazonaws.services.glue.model.BooleanColumnStatisticsData)2 ColumnStatistics (com.amazonaws.services.glue.model.ColumnStatistics)2 ColumnStatisticsData (com.amazonaws.services.glue.model.ColumnStatisticsData)2 DateColumnStatisticsData (com.amazonaws.services.glue.model.DateColumnStatisticsData)2 DecimalColumnStatisticsData (com.amazonaws.services.glue.model.DecimalColumnStatisticsData)2