diff --git a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java index 2569645ac50e..77ed102c7b4b 100644 --- a/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java +++ b/plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java @@ -1026,7 +1026,7 @@ private TableStatistics readTableStatistics(ConnectorSession session, JdbcTableH RemoteTableName remoteTableName = table.getRequiredNamedRelation().getRemoteTableName(); Map columnStatistics = statisticsDao.getColumnStatistics(remoteTableName.getSchemaName().orElse(null), remoteTableName.getTableName()).stream() - .collect(toImmutableMap(ColumnStatisticsResult::getColumnName, identity())); + .collect(toImmutableMap(ColumnStatisticsResult::columnName, identity())); for (JdbcColumnHandle column : this.getColumns(session, table)) { ColumnStatisticsResult result = columnStatistics.get(column.getColumnName()); @@ -1035,10 +1035,10 @@ private TableStatistics readTableStatistics(ConnectorSession session, JdbcTableH } ColumnStatistics statistics = ColumnStatistics.builder() - .setNullsFraction(result.getNullsFraction() + .setNullsFraction(result.nullsFraction() .map(Estimate::of) .orElseGet(Estimate::unknown)) - .setDistinctValuesCount(result.getDistinctValuesIndicator() + .setDistinctValuesCount(result.distinctValuesIndicator() .map(distinctValuesIndicator -> { if (distinctValuesIndicator >= 0.0) { return distinctValuesIndicator; @@ -1047,9 +1047,9 @@ private TableStatistics readTableStatistics(ConnectorSession session, JdbcTableH }) .map(Estimate::of) .orElseGet(Estimate::unknown)) - .setDataSize(result.getAverageColumnLength() + .setDataSize(result.averageColumnLength() .flatMap(averageColumnLength -> - result.getNullsFraction().map(nullsFraction -> + result.nullsFraction().map(nullsFraction -> Estimate.of(1.0 * averageColumnLength * rowCount * (1 - nullsFraction)))) .orElseGet(Estimate::unknown)) .build(); @@ -1720,39 +1720,18 @@ boolean isPartitionedTable(String schema, String tableName) } } - private static class ColumnStatisticsResult + private record ColumnStatisticsResult( + String columnName, + Optional nullsFraction, + Optional distinctValuesIndicator, + Optional averageColumnLength) { - private final String columnName; - private final Optional nullsFraction; - private final Optional distinctValuesIndicator; - private final Optional averageColumnLength; - - public ColumnStatisticsResult(String columnName, Optional nullsFraction, Optional distinctValuesIndicator, Optional averageColumnLength) - { - this.columnName = columnName; - this.nullsFraction = nullsFraction; - this.distinctValuesIndicator = distinctValuesIndicator; - this.averageColumnLength = averageColumnLength; - } - - public String getColumnName() - { - return columnName; - } - - public Optional getNullsFraction() - { - return nullsFraction; - } - - public Optional getDistinctValuesIndicator() - { - return distinctValuesIndicator; - } - - public Optional getAverageColumnLength() + private ColumnStatisticsResult { - return averageColumnLength; + requireNonNull(columnName, "columnName is null"); + requireNonNull(nullsFraction, "nullsFraction is null"); + requireNonNull(distinctValuesIndicator, "distinctValuesIndicator is null"); + requireNonNull(averageColumnLength, "averageColumnLength is null"); } } }