arina-ielchiieva commented on a change in pull request #1907: DRILL-7450:
Improve performance for ANALYZE command
URL: https://github.com/apache/drill/pull/1907#discussion_r350232283
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/ConvertMetadataAggregateToDirectScanRule.java
##########
@@ -232,40 +223,51 @@ private DirectGroupScan
populateRecords(Collection<SchemaPath> interestingColumn
statsValue = columnStatistics.get(statisticsKind);
}
String columnStatisticsFieldName =
AnalyzeColumnUtils.getColumnStatisticsFieldName(schemaPath.getRootSegmentPath(),
statisticsKind);
- fieldIndexes.putIfAbsent(columnStatisticsFieldName, index++);
- record.add(fieldIndexes.get(columnStatisticsFieldName), statsValue);
if (statsValue != null) {
schema.putIfAbsent(
columnStatisticsFieldName,
statsValue.getClass());
+ recordsTable.put(columnStatisticsFieldName, rowIndex, statsValue);
}
}
}
// populates record list with row group metadata
for (StatisticsKind<?> statisticsKind :
AnalyzeColumnUtils.META_STATISTICS_FUNCTIONS.keySet()) {
String metadataStatisticsFieldName =
AnalyzeColumnUtils.getMetadataStatisticsFieldName(statisticsKind);
- fieldIndexes.putIfAbsent(metadataStatisticsFieldName, index++);
- record.add(fieldIndexes.get(metadataStatisticsFieldName),
rowGroupMetadata.getStatistic(statisticsKind));
+ Object statisticsValue = rowGroupMetadata.getStatistic(statisticsKind);
+
+ if (statisticsValue != null) {
+ schema.putIfAbsent(metadataStatisticsFieldName,
statisticsValue.getClass());
+ recordsTable.put(metadataStatisticsFieldName, rowIndex,
statisticsValue);
+ }
}
// populates record list internal columns
- record.add(fieldIndexes.get(MetastoreAnalyzeConstants.SCHEMA_FIELD),
rowGroupMetadata.getSchema().jsonString());
- record.add(fieldIndexes.get(rgs),
Long.toString(rowGroupMetadata.getStatistic(() ->
ExactStatisticsConstants.START)));
- record.add(fieldIndexes.get(rgl),
Long.toString(rowGroupMetadata.getStatistic(() ->
ExactStatisticsConstants.LENGTH)));
- record.add(fieldIndexes.get(lmt),
String.valueOf(fileSystem.getFileStatus(path).getModificationTime()));
+ recordsTable.put(MetastoreAnalyzeConstants.SCHEMA_FIELD, rowIndex,
rowGroupMetadata.getSchema().jsonString());
+ recordsTable.put(rgs, rowIndex,
Long.toString(rowGroupMetadata.getStatistic(() ->
ExactStatisticsConstants.START)));
+ recordsTable.put(rgl, rowIndex,
Long.toString(rowGroupMetadata.getStatistic(() ->
ExactStatisticsConstants.LENGTH)));
+ recordsTable.put(lmt, rowIndex,
String.valueOf(fileSystem.getFileStatus(path).getModificationTime()));
- records.add(record);
+ rowIndex++;
}
- LinkedHashMap<String, Class<?>> orderedSchema = new LinkedHashMap<>();
-
// DynamicPojoRecordReader requires LinkedHashMap with fields order
// which corresponds to the value position in record list.
- // Sorts fieldIndexes by index and puts field names in required order to
orderedSchema
- fieldIndexes.entrySet().stream()
- .sorted(Comparator.comparingInt(Map.Entry::getValue))
- .forEach(entry -> orderedSchema.put(entry.getKey(),
schema.get(entry.getKey())));
+ LinkedHashMap<String, Class<?>> orderedSchema =
recordsTable.rowKeySet().stream()
+ .collect(Collectors.toMap(
+ Function.identity(),
+ column -> schema.getOrDefault(column, Integer.class),
+ (a, b) -> b,
Review comment:
Better use: (o, n) -> n
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services