Search in sources :

Example 21 with Table

use of io.trino.plugin.hive.metastore.Table in project trino by trinodb.

the class GlueHiveMetastore method getPartitionNamesByFilter.

@Override
public Optional<List<String>> getPartitionNamesByFilter(String databaseName, String tableName, List<String> columnNames, TupleDomain<String> partitionKeysFilter) {
    if (partitionKeysFilter.isNone()) {
        return Optional.of(ImmutableList.of());
    }
    Table table = getExistingTable(databaseName, tableName);
    String expression = GlueExpressionUtil.buildGlueExpression(columnNames, partitionKeysFilter, assumeCanonicalPartitionKeys);
    List<Partition> partitions = getPartitions(table, expression);
    return Optional.of(buildPartitionNames(table.getPartitionColumns(), partitions));
}
Also used : GlueInputConverter.convertPartition(io.trino.plugin.hive.metastore.glue.converter.GlueInputConverter.convertPartition) Partition(io.trino.plugin.hive.metastore.Partition) Table(io.trino.plugin.hive.metastore.Table)

Example 22 with Table

use of io.trino.plugin.hive.metastore.Table in project trino by trinodb.

the class GlueHiveMetastore method dropTable.

@Override
public void dropTable(String databaseName, String tableName, boolean deleteData) {
    Table table = getExistingTable(databaseName, tableName);
    try {
        stats.getDeleteTable().call(() -> glueClient.deleteTable(new DeleteTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withName(tableName)));
    } catch (AmazonServiceException e) {
        throw new TrinoException(HIVE_METASTORE_ERROR, e);
    }
    String tableLocation = table.getStorage().getLocation();
    if (deleteData && isManagedTable(table) && !isNullOrEmpty(tableLocation)) {
        deleteDir(hdfsContext, hdfsEnvironment, new Path(tableLocation), true);
    }
}
Also used : DeleteTableRequest(com.amazonaws.services.glue.model.DeleteTableRequest) Path(org.apache.hadoop.fs.Path) Table(io.trino.plugin.hive.metastore.Table) AmazonServiceException(com.amazonaws.AmazonServiceException) TrinoException(io.trino.spi.TrinoException)

Example 23 with Table

use of io.trino.plugin.hive.metastore.Table in project trino by trinodb.

the class GlueHiveMetastore method updateTableStatistics.

@Override
public void updateTableStatistics(String databaseName, String tableName, AcidTransaction transaction, Function<PartitionStatistics, PartitionStatistics> update) {
    Table table = getExistingTable(databaseName, tableName);
    if (transaction.isAcidTransactionRunning()) {
        table = Table.builder(table).setWriteId(OptionalLong.of(transaction.getWriteId())).build();
    }
    PartitionStatistics currentStatistics = getTableStatistics(table);
    PartitionStatistics updatedStatistics = update.apply(currentStatistics);
    try {
        TableInput tableInput = GlueInputConverter.convertTable(table);
        final Map<String, String> statisticsParameters = updateStatisticsParameters(table.getParameters(), updatedStatistics.getBasicStatistics());
        tableInput.setParameters(statisticsParameters);
        table = Table.builder(table).setParameters(statisticsParameters).build();
        stats.getUpdateTable().call(() -> glueClient.updateTable(new UpdateTableRequest().withCatalogId(catalogId).withDatabaseName(databaseName).withTableInput(tableInput)));
        columnStatisticsProvider.updateTableColumnStatistics(table, updatedStatistics.getColumnStatistics());
    } catch (EntityNotFoundException e) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    } catch (AmazonServiceException e) {
        throw new TrinoException(HIVE_METASTORE_ERROR, e);
    }
}
Also used : TableInput(com.amazonaws.services.glue.model.TableInput) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Table(io.trino.plugin.hive.metastore.Table) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) UpdateTableRequest(com.amazonaws.services.glue.model.UpdateTableRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) TrinoException(io.trino.spi.TrinoException) EntityNotFoundException(com.amazonaws.services.glue.model.EntityNotFoundException) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 24 with Table

use of io.trino.plugin.hive.metastore.Table in project trino by trinodb.

the class GlueHiveMetastore method renameColumn.

@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
    Table oldTable = getExistingTable(databaseName, tableName);
    if (oldTable.getPartitionColumns().stream().anyMatch(c -> c.getName().equals(oldColumnName))) {
        throw new TrinoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
    }
    ImmutableList.Builder<Column> newDataColumns = ImmutableList.builder();
    for (Column column : oldTable.getDataColumns()) {
        if (column.getName().equals(oldColumnName)) {
            newDataColumns.add(new Column(newColumnName, column.getType(), column.getComment()));
        } else {
            newDataColumns.add(column);
        }
    }
    Table newTable = Table.builder(oldTable).setDataColumns(newDataColumns.build()).build();
    replaceTable(databaseName, tableName, newTable, null);
}
Also used : Table(io.trino.plugin.hive.metastore.Table) Column(io.trino.plugin.hive.metastore.Column) MetastoreUtil.verifyCanDropColumn(io.trino.plugin.hive.metastore.MetastoreUtil.verifyCanDropColumn) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) TrinoException(io.trino.spi.TrinoException)

Example 25 with Table

use of io.trino.plugin.hive.metastore.Table in project trino by trinodb.

the class ProtoUtils method fromProto.

public static Table fromProto(alluxio.grpc.table.TableInfo table) {
    if (!table.hasLayout()) {
        throw new TrinoException(NOT_SUPPORTED, "Unsupported table metadata. missing layout.: " + table.getTableName());
    }
    Layout layout = table.getLayout();
    if (!alluxio.table.ProtoUtils.isHiveLayout(layout)) {
        throw new TrinoException(NOT_SUPPORTED, "Unsupported table layout: " + layout + " for table: " + table.getTableName());
    }
    try {
        PartitionInfo partitionInfo = alluxio.table.ProtoUtils.toHiveLayout(layout);
        // compute the data columns
        Set<String> partitionColumns = table.getPartitionColsList().stream().map(FieldSchema::getName).collect(toImmutableSet());
        List<FieldSchema> dataColumns = table.getSchema().getColsList().stream().filter((f) -> !partitionColumns.contains(f.getName())).collect(toImmutableList());
        Map<String, String> tableParameters = table.getParametersMap();
        Table.Builder builder = Table.builder().setDatabaseName(table.getDbName()).setTableName(table.getTableName()).setOwner(Optional.ofNullable(table.getOwner())).setTableType(table.getType().toString()).setDataColumns(dataColumns.stream().map(ProtoUtils::fromProto).collect(toImmutableList())).setPartitionColumns(table.getPartitionColsList().stream().map(ProtoUtils::fromProto).collect(toImmutableList())).setParameters(tableParameters).setViewOriginalText(Optional.empty()).setViewExpandedText(Optional.empty());
        alluxio.grpc.table.layout.hive.Storage storage = partitionInfo.getStorage();
        builder.getStorageBuilder().setSkewed(storage.getSkewed()).setStorageFormat(fromProto(storage.getStorageFormat())).setLocation(storage.getLocation()).setBucketProperty(storage.hasBucketProperty() ? fromProto(tableParameters, storage.getBucketProperty()) : Optional.empty()).setSerdeParameters(storage.getStorageFormat().getSerdelibParametersMap());
        return builder.build();
    } catch (InvalidProtocolBufferException e) {
        throw new IllegalArgumentException("Failed to extract PartitionInfo from TableInfo", e);
    }
}
Also used : Date(alluxio.grpc.table.Date) HiveColumnStatistics.createStringColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createStringColumnStatistics) HiveColumnStatistics.createBinaryColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createBinaryColumnStatistics) Database(io.trino.plugin.hive.metastore.Database) HiveColumnStatistics.createDecimalColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createDecimalColumnStatistics) DoubleColumnStatsData(alluxio.grpc.table.DoubleColumnStatsData) BigDecimal(java.math.BigDecimal) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) HiveColumnStatistics.createDateColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createDateColumnStatistics) Column(io.trino.plugin.hive.metastore.Column) HiveBucketing(io.trino.plugin.hive.util.HiveBucketing) Map(java.util.Map) BigInteger(java.math.BigInteger) ThriftMetastoreUtil.fromMetastoreDistinctValuesCount(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreDistinctValuesCount) StorageFormat(io.trino.plugin.hive.metastore.StorageFormat) Table(io.trino.plugin.hive.metastore.Table) BinaryColumnStatsData(alluxio.grpc.table.BinaryColumnStatsData) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Layout(alluxio.grpc.table.Layout) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) DecimalColumnStatsData(alluxio.grpc.table.DecimalColumnStatsData) HiveColumnStatistics.createDoubleColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createDoubleColumnStatistics) PartitionInfo(alluxio.grpc.table.layout.hive.PartitionInfo) List(java.util.List) HiveColumnStatistics.createBooleanColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createBooleanColumnStatistics) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Partition(io.trino.plugin.hive.metastore.Partition) PrincipalType(alluxio.grpc.table.PrincipalType) DateColumnStatsData(alluxio.grpc.table.DateColumnStatsData) OptionalDouble(java.util.OptionalDouble) LongColumnStatsData(alluxio.grpc.table.LongColumnStatsData) HiveBucketProperty(io.trino.plugin.hive.HiveBucketProperty) HiveType(io.trino.plugin.hive.HiveType) OptionalLong(java.util.OptionalLong) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) HIVE_INVALID_METADATA(io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_METADATA) FieldSchema(alluxio.grpc.table.FieldSchema) Lists(com.google.common.collect.Lists) ThriftMetastoreUtil.getTotalSizeInBytes(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getTotalSizeInBytes) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Nullable(javax.annotation.Nullable) ColumnStatisticsData(alluxio.grpc.table.ColumnStatisticsData) InvalidProtocolBufferException(alluxio.shaded.client.com.google.protobuf.InvalidProtocolBufferException) HiveColumnStatistics.createIntegerColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics.createIntegerColumnStatistics) BooleanColumnStatsData(alluxio.grpc.table.BooleanColumnStatsData) Decimal(alluxio.grpc.table.Decimal) SortingColumn(io.trino.plugin.hive.metastore.SortingColumn) StringColumnStatsData(alluxio.grpc.table.StringColumnStatsData) ThriftMetastoreUtil.fromMetastoreNullsCount(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreNullsCount) Table(io.trino.plugin.hive.metastore.Table) FieldSchema(alluxio.grpc.table.FieldSchema) InvalidProtocolBufferException(alluxio.shaded.client.com.google.protobuf.InvalidProtocolBufferException) Layout(alluxio.grpc.table.Layout) TrinoException(io.trino.spi.TrinoException) PartitionInfo(alluxio.grpc.table.layout.hive.PartitionInfo)

Aggregations

Table (io.trino.plugin.hive.metastore.Table)123 TrinoException (io.trino.spi.TrinoException)69 SchemaTableName (io.trino.spi.connector.SchemaTableName)64 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)57 Path (org.apache.hadoop.fs.Path)56 Column (io.trino.plugin.hive.metastore.Column)54 Optional (java.util.Optional)54 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)50 Partition (io.trino.plugin.hive.metastore.Partition)49 List (java.util.List)48 Map (java.util.Map)47 ImmutableMap (com.google.common.collect.ImmutableMap)45 PrincipalPrivileges (io.trino.plugin.hive.metastore.PrincipalPrivileges)45 ConnectorSession (io.trino.spi.connector.ConnectorSession)45 ImmutableList (com.google.common.collect.ImmutableList)43 Set (java.util.Set)43 Objects.requireNonNull (java.util.Objects.requireNonNull)40 HdfsContext (io.trino.plugin.hive.HdfsEnvironment.HdfsContext)39 TupleDomain (io.trino.spi.predicate.TupleDomain)38 Type (io.trino.spi.type.Type)38