Search in sources :

Example 31 with SchemaTableName

use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.

the class FileHiveMetastore method dropColumn.

@Override
public synchronized void dropColumn(String databaseName, String tableName, String columnName) {
    alterTable(databaseName, tableName, oldTable -> {
        verifyCanDropColumn(this, databaseName, tableName, columnName);
        if (oldTable.getColumn(columnName).isEmpty()) {
            SchemaTableName name = new SchemaTableName(databaseName, tableName);
            throw new ColumnNotFoundException(name, columnName);
        }
        ImmutableList.Builder<Column> newDataColumns = ImmutableList.builder();
        for (Column fieldSchema : oldTable.getDataColumns()) {
            if (!fieldSchema.getName().equals(columnName)) {
                newDataColumns.add(fieldSchema);
            }
        }
        return oldTable.withDataColumns(currentVersion, newDataColumns.build());
    });
}
Also used : ColumnNotFoundException(io.trino.spi.connector.ColumnNotFoundException) 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) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 32 with SchemaTableName

use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.

the class FileHiveMetastore method getTableStatistics.

private synchronized PartitionStatistics getTableStatistics(String databaseName, String tableName) {
    Path tableMetadataDirectory = getTableMetadataDirectory(databaseName, tableName);
    TableMetadata tableMetadata = readSchemaFile(TABLE, tableMetadataDirectory, tableCodec).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
    checkVersion(tableMetadata.getWriterVersion());
    HiveBasicStatistics basicStatistics = getHiveBasicStatistics(tableMetadata.getParameters());
    Map<String, HiveColumnStatistics> columnStatistics = tableMetadata.getColumnStatistics();
    return new PartitionStatistics(basicStatistics, columnStatistics);
}
Also used : Path(org.apache.hadoop.fs.Path) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HiveColumnStatistics(io.trino.plugin.hive.metastore.HiveColumnStatistics) ThriftMetastoreUtil.getHiveBasicStatistics(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.getHiveBasicStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 33 with SchemaTableName

use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.

the class BridgingHiveMetastore method renameTable.

@Override
public void renameTable(String databaseName, String tableName, String newDatabaseName, String newTableName) {
    Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(identity, databaseName, tableName);
    if (source.isEmpty()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    org.apache.hadoop.hive.metastore.api.Table table = source.get();
    table.setDbName(newDatabaseName);
    table.setTableName(newTableName);
    alterTable(databaseName, tableName, table);
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) Table(io.trino.plugin.hive.metastore.Table) ThriftMetastoreUtil.toMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiTable) ThriftMetastoreUtil.isCsvTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isCsvTable) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 34 with SchemaTableName

use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.

the class BridgingHiveMetastore method addColumn.

@Override
public void addColumn(String databaseName, String tableName, String columnName, HiveType columnType, String columnComment) {
    Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(identity, databaseName, tableName);
    if (source.isEmpty()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    org.apache.hadoop.hive.metastore.api.Table table = source.get();
    table.getSd().getCols().add(new FieldSchema(columnName, columnType.getHiveTypeName().toString(), columnComment));
    alterTable(databaseName, tableName, table);
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) Table(io.trino.plugin.hive.metastore.Table) ThriftMetastoreUtil.toMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiTable) ThriftMetastoreUtil.isCsvTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isCsvTable) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) SchemaTableName(io.trino.spi.connector.SchemaTableName)

Example 35 with SchemaTableName

use of io.trino.spi.connector.SchemaTableName in project trino by trinodb.

the class BridgingHiveMetastore method commentTable.

@Override
public void commentTable(String databaseName, String tableName, Optional<String> comment) {
    Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(identity, databaseName, tableName);
    if (source.isEmpty()) {
        throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
    }
    org.apache.hadoop.hive.metastore.api.Table table = source.get();
    Map<String, String> parameters = table.getParameters().entrySet().stream().filter(entry -> !entry.getKey().equals(TABLE_COMMENT)).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    comment.ifPresent(value -> parameters.put(TABLE_COMMENT, value));
    table.setParameters(parameters);
    alterTable(databaseName, tableName, table);
}
Also used : ThriftMetastoreUtil.fromMetastoreApiDatabase(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiDatabase) UnaryOperator.identity(java.util.function.UnaryOperator.identity) USER(io.trino.spi.security.PrincipalType.USER) ThriftMetastoreUtil.toMetastoreApiDatabase(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiDatabase) Database(io.trino.plugin.hive.metastore.Database) AcidOperation(io.trino.plugin.hive.acid.AcidOperation) SchemaNotFoundException(io.trino.spi.connector.SchemaNotFoundException) ThriftMetastoreUtil.csvSchemaFields(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.csvSchemaFields) AcidTransactionOwner(io.trino.plugin.hive.metastore.AcidTransactionOwner) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Map(java.util.Map) PartitionWithStatistics(io.trino.plugin.hive.metastore.PartitionWithStatistics) TABLE_COMMENT(io.trino.plugin.hive.HiveMetadata.TABLE_COMMENT) HiveIdentity(io.trino.plugin.hive.authentication.HiveIdentity) AcidTransaction(io.trino.plugin.hive.acid.AcidTransaction) Table(io.trino.plugin.hive.metastore.Table) ImmutableMap(com.google.common.collect.ImmutableMap) HivePartition(io.trino.plugin.hive.HivePartition) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) Collectors(java.util.stream.Collectors) SchemaTableName(io.trino.spi.connector.SchemaTableName) ThriftMetastoreUtil.toMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiTable) List(java.util.List) ThriftMetastoreUtil.isCsvTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isCsvTable) Optional(java.util.Optional) HivePrivilegeInfo(io.trino.plugin.hive.metastore.HivePrivilegeInfo) Partition(io.trino.plugin.hive.metastore.Partition) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) HivePrincipal(io.trino.plugin.hive.metastore.HivePrincipal) HiveUtil(io.trino.plugin.hive.util.HiveUtil) MetastoreUtil.isAvroTableWithSchemaSet(io.trino.plugin.hive.metastore.MetastoreUtil.isAvroTableWithSchemaSet) Type(io.trino.spi.type.Type) ThriftMetastoreUtil.isAvroTableWithSchemaSet(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isAvroTableWithSchemaSet) Function(java.util.function.Function) DataOperationType(org.apache.hadoop.hive.metastore.api.DataOperationType) HiveType(io.trino.plugin.hive.HiveType) OptionalLong(java.util.OptionalLong) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) Objects.requireNonNull(java.util.Objects.requireNonNull) TupleDomain(io.trino.spi.predicate.TupleDomain) RoleGrant(io.trino.spi.security.RoleGrant) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) MetastoreUtil.verifyCanDropColumn(io.trino.plugin.hive.metastore.MetastoreUtil.verifyCanDropColumn) PrincipalPrivileges(io.trino.plugin.hive.metastore.PrincipalPrivileges) HivePrivilege(io.trino.plugin.hive.metastore.HivePrivilegeInfo.HivePrivilege) ThriftMetastoreUtil.fromMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.fromMetastoreApiTable) Table(io.trino.plugin.hive.metastore.Table) ThriftMetastoreUtil.toMetastoreApiTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toMetastoreApiTable) ThriftMetastoreUtil.isCsvTable(io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.isCsvTable) SchemaTableName(io.trino.spi.connector.SchemaTableName) TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

SchemaTableName (io.trino.spi.connector.SchemaTableName)446 Test (org.testng.annotations.Test)212 ImmutableList (com.google.common.collect.ImmutableList)131 ImmutableMap (com.google.common.collect.ImmutableMap)106 List (java.util.List)102 TrinoException (io.trino.spi.TrinoException)100 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)98 ConnectorSession (io.trino.spi.connector.ConnectorSession)98 CatalogSchemaTableName (io.trino.spi.connector.CatalogSchemaTableName)92 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)89 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)86 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)86 Optional (java.util.Optional)78 Map (java.util.Map)67 ColumnHandle (io.trino.spi.connector.ColumnHandle)66 TupleDomain (io.trino.spi.predicate.TupleDomain)59 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)58 Path (org.apache.hadoop.fs.Path)55 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)53 ImmutableSet (com.google.common.collect.ImmutableSet)52