Search in sources :

Example 16 with Partition

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

the class ThriftMetastoreUtil method fromMetastoreApiPartition.

public static Partition fromMetastoreApiPartition(org.apache.hadoop.hive.metastore.api.Partition partition, List<FieldSchema> schema) {
    StorageDescriptor storageDescriptor = partition.getSd();
    if (storageDescriptor == null) {
        throw new TrinoException(HIVE_INVALID_METADATA, "Partition does not contain a storage descriptor: " + partition);
    }
    Partition.Builder partitionBuilder = Partition.builder().setDatabaseName(partition.getDbName()).setTableName(partition.getTableName()).setValues(partition.getValues()).setColumns(schema.stream().map(ThriftMetastoreUtil::fromMetastoreApiFieldSchema).collect(toImmutableList())).setParameters(partition.getParameters());
    // TODO is bucketing_version set on partition level??
    fromMetastoreApiStorageDescriptor(partition.getParameters(), storageDescriptor, partitionBuilder.getStorageBuilder(), format("%s.%s", partition.getTableName(), partition.getValues()));
    return partitionBuilder.build();
}
Also used : Partition(io.trino.plugin.hive.metastore.Partition) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) TrinoException(io.trino.spi.TrinoException)

Example 17 with Partition

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

the class AbstractTestHive method eraseStatistics.

private void eraseStatistics(SchemaTableName schemaTableName) {
    HiveMetastore metastoreClient = getMetastoreClient();
    metastoreClient.updateTableStatistics(schemaTableName.getSchemaName(), schemaTableName.getTableName(), NO_ACID_TRANSACTION, statistics -> new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of()));
    Table table = metastoreClient.getTable(schemaTableName.getSchemaName(), schemaTableName.getTableName()).orElseThrow(() -> new TableNotFoundException(schemaTableName));
    List<String> partitionColumns = table.getPartitionColumns().stream().map(Column::getName).collect(toImmutableList());
    if (!table.getPartitionColumns().isEmpty()) {
        List<String> partitionNames = metastoreClient.getPartitionNamesByFilter(schemaTableName.getSchemaName(), schemaTableName.getTableName(), partitionColumns, TupleDomain.all()).orElse(ImmutableList.of());
        List<Partition> partitions = metastoreClient.getPartitionsByNames(table, partitionNames).entrySet().stream().map(Map.Entry::getValue).filter(Optional::isPresent).map(Optional::get).collect(toImmutableList());
        for (Partition partition : partitions) {
            metastoreClient.updatePartitionStatistics(table, makePartName(partitionColumns, partition.getValues()), statistics -> new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of()));
        }
    }
}
Also used : TableNotFoundException(io.trino.spi.connector.TableNotFoundException) Partition(io.trino.plugin.hive.metastore.Partition) Table(io.trino.plugin.hive.metastore.Table) Optional(java.util.Optional) HiveMetastore(io.trino.plugin.hive.metastore.HiveMetastore) BridgingHiveMetastore(io.trino.plugin.hive.metastore.thrift.BridgingHiveMetastore) CachingHiveMetastore.cachingHiveMetastore(io.trino.plugin.hive.metastore.cache.CachingHiveMetastore.cachingHiveMetastore) ThriftHiveMetastore(io.trino.plugin.hive.metastore.thrift.ThriftHiveMetastore) SemiTransactionalHiveMetastore(io.trino.plugin.hive.metastore.SemiTransactionalHiveMetastore) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorBucketNodeMap(io.trino.spi.connector.ConnectorBucketNodeMap) HashMap(java.util.HashMap)

Example 18 with Partition

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

the class BaseTestHiveOnDataLake method renamePartitionResourcesOutsideTrino.

private void renamePartitionResourcesOutsideTrino(String tableName, String partitionColumn, String regionKey) {
    String partitionName = format("%s=%s", partitionColumn, regionKey);
    String partitionS3KeyPrefix = format("%s/%s/%s", HIVE_TEST_SCHEMA, tableName, partitionName);
    String renamedPartitionSuffix = "CP";
    // Copy whole partition to new location
    AmazonS3 amazonS3 = dockerizedS3DataLake.getS3Client();
    amazonS3.listObjects(bucketName).getObjectSummaries().forEach(object -> {
        String objectKey = object.getKey();
        if (objectKey.startsWith(partitionS3KeyPrefix)) {
            String fileName = objectKey.substring(objectKey.lastIndexOf('/'));
            String destinationKey = partitionS3KeyPrefix + renamedPartitionSuffix + fileName;
            amazonS3.copyObject(bucketName, objectKey, bucketName, destinationKey);
        }
    });
    // Delete old partition and update metadata to point to location of new copy
    Table hiveTable = metastoreClient.getTable(HIVE_TEST_SCHEMA, tableName).get();
    Partition hivePartition = metastoreClient.getPartition(hiveTable, List.of(regionKey)).get();
    Map<String, PartitionStatistics> partitionStatistics = metastoreClient.getPartitionStatistics(hiveTable, List.of(hivePartition));
    metastoreClient.dropPartition(HIVE_TEST_SCHEMA, tableName, List.of(regionKey), true);
    metastoreClient.addPartitions(HIVE_TEST_SCHEMA, tableName, List.of(new PartitionWithStatistics(Partition.builder(hivePartition).withStorage(builder -> builder.setLocation(hivePartition.getStorage().getLocation() + renamedPartitionSuffix)).build(), partitionName, partitionStatistics.get(partitionName))));
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) Partition(io.trino.plugin.hive.metastore.Partition) Table(io.trino.plugin.hive.metastore.Table) PartitionWithStatistics(io.trino.plugin.hive.metastore.PartitionWithStatistics)

Example 19 with Partition

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

the class TestCachingHiveMetastore method testInvalidGetPartitionsByNames.

@Test
public void testInvalidGetPartitionsByNames() {
    Table table = metastore.getTable(TEST_DATABASE, TEST_TABLE).get();
    Map<String, Optional<Partition>> partitionsByNames = metastore.getPartitionsByNames(table, ImmutableList.of(BAD_PARTITION));
    assertEquals(partitionsByNames.size(), 1);
    Optional<Partition> onlyElement = Iterables.getOnlyElement(partitionsByNames.values());
    assertFalse(onlyElement.isPresent());
}
Also used : Partition(io.trino.plugin.hive.metastore.Partition) Table(io.trino.plugin.hive.metastore.Table) Optional(java.util.Optional) Test(org.testng.annotations.Test)

Example 20 with Partition

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

the class TestCachingHiveMetastore method testGetPartitionStatistics.

@Test
public void testGetPartitionStatistics() {
    assertEquals(mockClient.getAccessCount(), 0);
    Table table = metastore.getTable(TEST_DATABASE, TEST_TABLE).get();
    assertEquals(mockClient.getAccessCount(), 1);
    Partition partition = metastore.getPartition(table, TEST_PARTITION_VALUES1).get();
    assertEquals(mockClient.getAccessCount(), 2);
    assertEquals(metastore.getPartitionStatistics(table, ImmutableList.of(partition)), ImmutableMap.of(TEST_PARTITION1, TEST_STATS));
    assertEquals(mockClient.getAccessCount(), 3);
    assertEquals(metastore.getPartitionStatisticsStats().getRequestCount(), 1);
    assertEquals(metastore.getPartitionStatisticsStats().getHitRate(), 0.0);
    assertEquals(metastore.getTableStats().getRequestCount(), 3);
    assertEquals(metastore.getTableStats().getHitRate(), 2.0 / 3);
    assertEquals(metastore.getPartitionStats().getRequestCount(), 2);
    assertEquals(metastore.getPartitionStats().getHitRate(), 0.5);
}
Also used : Partition(io.trino.plugin.hive.metastore.Partition) Table(io.trino.plugin.hive.metastore.Table) Test(org.testng.annotations.Test)

Aggregations

Partition (io.trino.plugin.hive.metastore.Partition)42 Table (io.trino.plugin.hive.metastore.Table)33 TrinoException (io.trino.spi.TrinoException)31 List (java.util.List)28 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)27 ImmutableMap (com.google.common.collect.ImmutableMap)27 Map (java.util.Map)26 Optional (java.util.Optional)26 ImmutableList (com.google.common.collect.ImmutableList)25 ArrayList (java.util.ArrayList)23 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)21 TableNotFoundException (io.trino.spi.connector.TableNotFoundException)21 SchemaTableName (io.trino.spi.connector.SchemaTableName)20 Objects.requireNonNull (java.util.Objects.requireNonNull)20 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)19 Column (io.trino.plugin.hive.metastore.Column)19 HivePrincipal (io.trino.plugin.hive.metastore.HivePrincipal)19 TupleDomain (io.trino.spi.predicate.TupleDomain)19 Type (io.trino.spi.type.Type)19 OptionalLong (java.util.OptionalLong)19