@VisibleForTesting static ColumnStatisticMetadata deserialize(String value) { int separatorIndex = value.indexOf(':'); checkArgument(separatorIndex >= 0, "separator not found: %s", value); String statisticType = value.substring(0, separatorIndex); String column = value.substring(separatorIndex + 1); return new ColumnStatisticMetadata(column, ColumnStatisticType.valueOf(statisticType)); } }
@VisibleForTesting static String serialize(ColumnStatisticMetadata value) { return value.getStatisticType().name() + ":" + value.getColumnName(); } }
private static Map<String, Map<ColumnStatisticType, Block>> createColumnToComputedStatisticsMap(Map<ColumnStatisticMetadata, Block> computedStatistics) { Map<String, Map<ColumnStatisticType, Block>> result = new HashMap<>(); computedStatistics.forEach((metadata, block) -> { Map<ColumnStatisticType, Block> columnStatistics = result.computeIfAbsent(metadata.getColumnName(), key -> new HashMap<>()); columnStatistics.put(metadata.getStatisticType(), block); }); return result.entrySet() .stream() .collect(toImmutableMap(Entry::getKey, entry -> ImmutableMap.copyOf(entry.getValue()))); }
private List<ColumnStatisticMetadata> getColumnStatisticMetadata(String columnName, Set<ColumnStatisticType> statisticTypes) { return statisticTypes.stream() .map(type -> new ColumnStatisticMetadata(columnName, type)) .collect(toImmutableList()); }
private void printStatisticAggregationsInfo( Map<TableStatisticType, Symbol> tableStatistics, Map<ColumnStatisticMetadata, Symbol> columnStatistics, Map<Symbol, Aggregation> aggregations, int indent) { print(indent, "aggregations =>"); for (Map.Entry<TableStatisticType, Symbol> tableStatistic : tableStatistics.entrySet()) { print( indent + 1, "%s => [%s := %s]", tableStatistic.getValue(), tableStatistic.getKey(), aggregations.get(tableStatistic.getValue()).getCall()); } for (Map.Entry<ColumnStatisticMetadata, Symbol> columnStatistic : columnStatistics.entrySet()) { print( indent + 1, "%s[%s] => [%s := %s]", columnStatistic.getKey().getStatisticType(), columnStatistic.getKey().getColumnName(), columnStatistic.getValue(), aggregations.get(columnStatistic.getValue()).getCall()); } }
@Test public void testColumnStatisticMetadataKeySerializationRoundTrip() { for (String column : COLUMNS) { for (ColumnStatisticType type : ColumnStatisticType.values()) { ColumnStatisticMetadata expected = new ColumnStatisticMetadata(column, type); assertEquals(deserialize(serialize(expected)), expected); } } }
String columnName = columnStatisticMetadata.getColumnName(); ColumnStatisticType statisticType = columnStatisticMetadata.getStatisticType(); Symbol inputSymbol = columnToSymbolMap.get(columnName); verify(inputSymbol != null, "inputSymbol is null");
ColumnStatisticMetadata statisticMetadata = new ColumnStatisticMetadata("column", MAX_VALUE); StatisticAggregationsDescriptor<Integer> descriptor = new StatisticAggregationsDescriptor<>( ImmutableMap.of(),
private static StatisticAggregationsDescriptor<Symbol> createTestDescriptor() { StatisticAggregationsDescriptor.Builder<Symbol> builder = StatisticAggregationsDescriptor.builder(); SymbolAllocator symbolAllocator = new SymbolAllocator(); for (String column : COLUMNS) { for (ColumnStatisticType type : ColumnStatisticType.values()) { builder.addColumnStatistic(new ColumnStatisticMetadata(column, type), testSymbol(symbolAllocator)); } builder.addGrouping(column, testSymbol(symbolAllocator)); } builder.addTableStatistic(ROW_COUNT, testSymbol(symbolAllocator)); return builder.build(); }