use of io.trino.spi.statistics.TableStatistics 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);
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class MetadataManager method getTableStatistics.
@Override
public TableStatistics getTableStatistics(Session session, TableHandle tableHandle, Constraint constraint) {
CatalogName catalogName = tableHandle.getCatalogName();
ConnectorMetadata metadata = getMetadata(session, catalogName);
TableStatistics tableStatistics = metadata.getTableStatistics(session.toConnectorSession(catalogName), tableHandle.getConnectorHandle(), constraint);
verifyNotNull(tableStatistics, "%s returned null tableStatistics for %s", metadata, tableHandle);
return tableStatistics;
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class BaseIcebergConnectorTest method testStatisticsConstraints.
@Test
public void testStatisticsConstraints() {
String tableName = "iceberg.tpch.test_simple_partitioned_table_statistics";
assertUpdate("CREATE TABLE iceberg.tpch.test_simple_partitioned_table_statistics (col1 BIGINT, col2 BIGINT) WITH (partitioning = ARRAY['col1'])");
String insertStart = "INSERT INTO iceberg.tpch.test_simple_partitioned_table_statistics";
assertUpdate(insertStart + " VALUES (1, 101), (2, 102), (3, 103), (4, 104)", 4);
TableStatistics tableStatistics = getTableStatistics(tableName, new Constraint(TupleDomain.all()));
IcebergColumnHandle col1Handle = getColumnHandleFromStatistics(tableStatistics, "col1");
IcebergColumnHandle col2Handle = getColumnHandleFromStatistics(tableStatistics, "col2");
// Constraint.predicate is currently not supported, because it's never provided by the engine.
// TODO add (restore) test coverage when this changes.
// predicate on a partition column
assertThatThrownBy(() -> getTableStatistics(tableName, new Constraint(TupleDomain.all(), new TestRelationalNumberPredicate("col1", 3, i1 -> i1 >= 0), Set.of(col1Handle)))).isInstanceOf(VerifyException.class).hasMessage("Unexpected Constraint predicate");
// predicate on a non-partition column
assertThatThrownBy(() -> getTableStatistics(tableName, new Constraint(TupleDomain.all(), new TestRelationalNumberPredicate("col2", 102, i -> i >= 0), Set.of(col2Handle)))).isInstanceOf(VerifyException.class).hasMessage("Unexpected Constraint predicate");
dropTable(tableName);
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class TestDeltaLakeMetastoreStatistics method testStatisticsParquetParsedStatisticsNullCount.
@Test
public void testStatisticsParquetParsedStatisticsNullCount() {
// The transaction log for this table was created so that the checkpoints only write struct statistics, not json statistics
// The table has one INTEGER column 'i' where 3 of the 9 values are null
DeltaLakeTableHandle tableHandle = registerTable("parquet_struct_statistics_null_count");
TableStatistics stats = deltaLakeMetastore.getTableStatistics(SESSION, tableHandle, Constraint.alwaysTrue());
assertEquals(stats.getRowCount(), Estimate.of(9));
Map<ColumnHandle, ColumnStatistics> statisticsMap = stats.getColumnStatistics();
ColumnStatistics columnStats = statisticsMap.get(new DeltaLakeColumnHandle("i", INTEGER, REGULAR));
assertEquals(columnStats.getNullsFraction(), Estimate.of(3.0 / 9.0));
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class TestDeltaLakeMetastoreStatistics method testStatisticsNegativeInfinityAndNaN.
@Test
public void testStatisticsNegativeInfinityAndNaN() {
// Stats with NaN values cannot be used
DeltaLakeTableHandle tableHandle = registerTable("negative_infinity_nan");
TableStatistics stats = deltaLakeMetastore.getTableStatistics(SESSION, tableHandle, Constraint.alwaysTrue());
ColumnStatistics columnStatistics = stats.getColumnStatistics().get(COLUMN_HANDLE);
assertEquals(columnStatistics.getRange().get().getMin(), NEGATIVE_INFINITY);
assertEquals(columnStatistics.getRange().get().getMax(), POSITIVE_INFINITY);
}
Aggregations