use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class MetastoreHiveStatisticsProvider method createZeroStatistics.
private TableStatistics createZeroStatistics(Map<String, ColumnHandle> columns, Map<String, Type> columnTypes) {
TableStatistics.Builder result = TableStatistics.builder();
result.setRowCount(Estimate.of(0));
columns.forEach((columnName, columnHandle) -> {
Type columnType = columnTypes.get(columnName);
verifyNotNull(columnType, "columnType is missing for column: %s", columnName);
ColumnStatistics.Builder columnStatistics = ColumnStatistics.builder();
columnStatistics.setNullsFraction(Estimate.of(0));
columnStatistics.setDistinctValuesCount(Estimate.of(0));
if (hasDataSize(columnType)) {
columnStatistics.setDataSize(Estimate.of(0));
}
result.setColumnStatistics(columnHandle, columnStatistics.build());
});
return result.build();
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class AbstractTestHive method testPartitionStatisticsSampling.
protected void testPartitionStatisticsSampling(List<ColumnMetadata> columns, PartitionStatistics statistics) throws Exception {
SchemaTableName tableName = temporaryTable("test_partition_statistics_sampling");
try {
createDummyPartitionedTable(tableName, columns);
HiveMetastoreClosure metastoreClient = new HiveMetastoreClosure(getMetastoreClient());
metastoreClient.updatePartitionStatistics(tableName.getSchemaName(), tableName.getTableName(), "ds=2016-01-01", actualStatistics -> statistics);
metastoreClient.updatePartitionStatistics(tableName.getSchemaName(), tableName.getTableName(), "ds=2016-01-02", actualStatistics -> statistics);
try (Transaction transaction = newTransaction()) {
ConnectorSession session = newSession();
ConnectorMetadata metadata = transaction.getMetadata();
ConnectorTableHandle tableHandle = metadata.getTableHandle(session, tableName);
TableStatistics unsampledStatistics = metadata.getTableStatistics(sampleSize(2), tableHandle, Constraint.alwaysTrue());
TableStatistics sampledStatistics = metadata.getTableStatistics(sampleSize(1), tableHandle, Constraint.alwaysTrue());
assertEquals(sampledStatistics, unsampledStatistics);
}
} finally {
dropTable(tableName);
}
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class TestDeltaLakeMetastoreStatistics method testStatisticsNaNWithMultipleFiles.
@Test
public void testStatisticsNaNWithMultipleFiles() {
// Stats with NaN values cannot be used. This transaction combines a file with NaN min/max values with one with 0.0 min/max values
DeltaLakeTableHandle tableHandle = registerTable("nan_multi_file");
TableStatistics stats = deltaLakeMetastore.getTableStatistics(SESSION, tableHandle, Constraint.alwaysTrue());
ColumnStatistics columnStatistics = stats.getColumnStatistics().get(COLUMN_HANDLE);
assertEquals(columnStatistics.getRange(), Optional.empty());
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class TestDeltaLakeMetastoreStatistics method testStatisticsZeroAndNegativeInfinity.
@Test
public void testStatisticsZeroAndNegativeInfinity() {
DeltaLakeTableHandle tableHandle = registerTable("zero_negative_infinity");
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(), 0.0);
}
use of io.trino.spi.statistics.TableStatistics in project trino by trinodb.
the class TestDeltaLakeMetastoreStatistics method testStatisticsZeroAndNaN.
@Test
public void testStatisticsZeroAndNaN() {
// Stats with NaN values cannot be used
DeltaLakeTableHandle tableHandle = registerTable("zero_nan");
TableStatistics stats = deltaLakeMetastore.getTableStatistics(SESSION, tableHandle, Constraint.alwaysTrue());
ColumnStatistics columnStatistics = stats.getColumnStatistics().get(COLUMN_HANDLE);
assertEquals(columnStatistics.getRange().get().getMin(), 0.0);
assertEquals(columnStatistics.getRange().get().getMax(), POSITIVE_INFINITY);
}
Aggregations