Source:
<code>private void assertTableStatsComputed( SchemaTableName tableName, Set<String> expectedColumnStatsColumns) { try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); ConnectorSession session = newSession(); ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName); TableStatistics tableStatistics = metadata.getTableStatistics(session, tableHandle, Constraint.alwaysTrue()); assertFalse(tableStatistics.getRowCount().isValueUnknown(), "row count is unknown"); Map<String, ColumnStatistics> columnsStatistics = tableStatistics .getColumnStatistics() .entrySet() .stream() .collect( toImmutableMap( entry -> ((HiveColumnHandle) entry.getKey()).getName(), Map.Entry::getValue)); assertEquals(columnsStatistics.keySet(), expectedColumnStatsColumns, "columns with statistics"); columnsStatistics.forEach((columnName, columnStatistics) -> { <START> ColumnHandle columnHandle = metadata.getColumnHandles(session, tableHandle).get(columnName); <END> Type columnType = metadata.getColumnMetadata(session, tableHandle, columnHandle).getType(); assertFalse( columnStatistics.getNullsFraction().isValueUnknown(), "unknown nulls fraction for " + columnName); RangeColumnStatistics rangeColumnStatistics = columnStatistics.getOnlyRangeColumnStatistics(); assertFalse( rangeColumnStatistics.getDistinctValuesCount().isValueUnknown(), "unknown range distinct values count for " + columnName); assertFalse( rangeColumnStatistics.getFraction().isValueUnknown(), "unknown range non-null fraction for " + columnName); if (isVarcharType(columnType)) { assertFalse( rangeColumnStatistics.getDataSize().isValueUnknown(), "unknown range data size for " + columnName); } else { assertTrue( rangeColumnStatistics.getDataSize().isValueUnknown(), "known range data size for" + columnName); } }); } }</code><technical_language>nit: Move metadata.getColumnHandles(session, tableHandle) out of loop</technical_language>

Target:
private void assertTableStatsComputed( SchemaTableName tableName, Set<String> expectedColumnStatsColumns) { try (Transaction transaction = newTransaction()) { ConnectorMetadata metadata = transaction.getMetadata(); ConnectorSession session = newSession(); ConnectorTableHandle tableHandle = getTableHandle(metadata, tableName); TableStatistics tableStatistics = metadata.getTableStatistics(session, tableHandle, Constraint.alwaysTrue()); assertFalse(tableStatistics.getRowCount().isValueUnknown(), "row count is unknown"); Map<String, ColumnStatistics> columnsStatistics = tableStatistics .getColumnStatistics() .entrySet() .stream() .collect( toImmutableMap( entry -> ((HiveColumnHandle) entry.getKey()).getName(), Map.Entry::getValue)); assertEquals(columnsStatistics.keySet(), expectedColumnStatsColumns, "columns with statistics"); Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle); columnsStatistics.forEach((columnName, columnStatistics) -> { ColumnHandle columnHandle = columnHandles.get(columnName); Type columnType = metadata.getColumnMetadata(session, tableHandle, columnHandle).getType(); assertFalse( columnStatistics.getNullsFraction().isValueUnknown(), "unknown nulls fraction for " + columnName); RangeColumnStatistics rangeColumnStatistics = columnStatistics.getOnlyRangeColumnStatistics(); assertFalse( rangeColumnStatistics.getDistinctValuesCount().isValueUnknown(), "unknown range distinct values count for " + columnName); assertFalse( rangeColumnStatistics.getFraction().isValueUnknown(), "unknown range non-null fraction for " + columnName); if (isVarcharType(columnType)) { assertFalse( rangeColumnStatistics.getDataSize().isValueUnknown(), "unknown range data size for " + columnName); } else { assertTrue( rangeColumnStatistics.getDataSize().isValueUnknown(), "known range data size for" + columnName); } }); } }