Search in sources :

Example 6 with DoubleRange

use of io.trino.spi.statistics.DoubleRange 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 DoubleRange

use of io.trino.spi.statistics.DoubleRange in project trino by trinodb.

the class TestTpcdsMetadataStatistics method testNullFraction.

@Test
public void testNullFraction() {
    SchemaTableName schemaTableName = new SchemaTableName("sf1", Table.WEB_SITE.getName());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(session, schemaTableName);
    TableStatistics tableStatistics = metadata.getTableStatistics(session, tableHandle, alwaysTrue());
    Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle);
    // some null values
    assertColumnStatistics(tableStatistics.getColumnStatistics().get(columnHandles.get(WebSiteColumn.WEB_REC_END_DATE.getName())), ColumnStatistics.builder().setNullsFraction(Estimate.of(0.5)).setDistinctValuesCount(Estimate.of(3)).setRange(new DoubleRange(10819L, 11549L)).build());
}
Also used : ColumnHandle(io.trino.spi.connector.ColumnHandle) DoubleRange(io.trino.spi.statistics.DoubleRange) TableStatistics(io.trino.spi.statistics.TableStatistics) SchemaTableName(io.trino.spi.connector.SchemaTableName) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Test(org.testng.annotations.Test)

Aggregations

DoubleRange (io.trino.spi.statistics.DoubleRange)7 TableStatistics (io.trino.spi.statistics.TableStatistics)7 SchemaTableName (io.trino.spi.connector.SchemaTableName)4 Test (org.testng.annotations.Test)4 HiveBasicStatistics (io.trino.plugin.hive.HiveBasicStatistics)3 HiveColumnHandle (io.trino.plugin.hive.HiveColumnHandle)3 PartitionStatistics (io.trino.plugin.hive.PartitionStatistics)3 ColumnHandle (io.trino.spi.connector.ColumnHandle)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 HivePartition (io.trino.plugin.hive.HivePartition)2 MetastoreHiveStatisticsProvider.validatePartitionStatistics (io.trino.plugin.hive.statistics.MetastoreHiveStatisticsProvider.validatePartitionStatistics)2 TrinoException (io.trino.spi.TrinoException)2 ColumnStatistics (io.trino.spi.statistics.ColumnStatistics)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Verify.verify (com.google.common.base.Verify.verify)1 Verify.verifyNotNull (com.google.common.base.Verify.verifyNotNull)1