Search in sources :

Example 6 with HivePartition

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

the class TestMetastoreHiveStatisticsProvider method testGetTableStatisticsUnpartitioned.

@Test
public void testGetTableStatisticsUnpartitioned() {
    PartitionStatistics statistics = PartitionStatistics.builder().setBasicStatistics(new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.of(1000), OptionalLong.empty(), OptionalLong.empty())).setColumnStatistics(ImmutableMap.of(COLUMN, createIntegerColumnStatistics(OptionalLong.of(-100), OptionalLong.of(100), OptionalLong.of(500), OptionalLong.of(300)))).build();
    MetastoreHiveStatisticsProvider statisticsProvider = new MetastoreHiveStatisticsProvider((session, table, hivePartitions) -> ImmutableMap.of(UNPARTITIONED_ID, statistics));
    HiveColumnHandle columnHandle = createBaseColumn(COLUMN, 2, HIVE_LONG, BIGINT, REGULAR, Optional.empty());
    TableStatistics expected = TableStatistics.builder().setRowCount(Estimate.of(1000)).setColumnStatistics(columnHandle, ColumnStatistics.builder().setRange(new DoubleRange(-100, 100)).setNullsFraction(Estimate.of(0.5)).setDistinctValuesCount(Estimate.of(300)).build()).build();
    assertEquals(statisticsProvider.getTableStatistics(SESSION, TABLE, ImmutableMap.of(COLUMN, columnHandle), ImmutableMap.of(COLUMN, BIGINT), ImmutableList.of(new HivePartition(TABLE))), expected);
}
Also used : DoubleRange(io.trino.spi.statistics.DoubleRange) MetastoreHiveStatisticsProvider.validatePartitionStatistics(io.trino.plugin.hive.statistics.MetastoreHiveStatisticsProvider.validatePartitionStatistics) PartitionStatistics(io.trino.plugin.hive.PartitionStatistics) TableStatistics(io.trino.spi.statistics.TableStatistics) HiveBasicStatistics(io.trino.plugin.hive.HiveBasicStatistics) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) HivePartition(io.trino.plugin.hive.HivePartition) Test(org.testng.annotations.Test)

Example 7 with HivePartition

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

the class TestMetastoreHiveStatisticsProvider method testGetPartitionsSample.

@Test
public void testGetPartitionsSample() {
    HivePartition p1 = partition("p1=string1/p2=1234");
    HivePartition p2 = partition("p1=string2/p2=2345");
    HivePartition p3 = partition("p1=string3/p2=3456");
    HivePartition p4 = partition("p1=string4/p2=4567");
    HivePartition p5 = partition("p1=string5/p2=5678");
    assertEquals(getPartitionsSample(ImmutableList.of(p1), 1), ImmutableList.of(p1));
    assertEquals(getPartitionsSample(ImmutableList.of(p1), 2), ImmutableList.of(p1));
    assertEquals(getPartitionsSample(ImmutableList.of(p1, p2), 2), ImmutableList.of(p1, p2));
    assertEquals(getPartitionsSample(ImmutableList.of(p1, p2, p3), 2), ImmutableList.of(p1, p3));
    assertEquals(getPartitionsSample(ImmutableList.of(p1, p2, p3, p4), 1), getPartitionsSample(ImmutableList.of(p1, p2, p3, p4), 1));
    assertEquals(getPartitionsSample(ImmutableList.of(p1, p2, p3, p4), 3), getPartitionsSample(ImmutableList.of(p1, p2, p3, p4), 3));
    assertEquals(getPartitionsSample(ImmutableList.of(p1, p2, p3, p4, p5), 3), ImmutableList.of(p1, p5, p4));
}
Also used : HivePartition(io.trino.plugin.hive.HivePartition) Test(org.testng.annotations.Test)

Aggregations

HivePartition (io.trino.plugin.hive.HivePartition)7 SchemaTableName (io.trino.spi.connector.SchemaTableName)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 HiveBasicStatistics (io.trino.plugin.hive.HiveBasicStatistics)3 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)3 PartitionStatistics (io.trino.plugin.hive.PartitionStatistics)3 DoubleRange (io.trino.spi.statistics.DoubleRange)3 TableStatistics (io.trino.spi.statistics.TableStatistics)3 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 Verify.verify (com.google.common.base.Verify.verify)2 Verify.verifyNotNull (com.google.common.base.Verify.verifyNotNull)2 VerifyException (com.google.common.base.VerifyException)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 Maps.immutableEntry (com.google.common.collect.Maps.immutableEntry)2 HashFunction (com.google.common.hash.HashFunction)2 Hashing.murmur3_128 (com.google.common.hash.Hashing.murmur3_128)2