FANNG1 commented on code in PR #10138:
URL: https://github.com/apache/gravitino/pull/10138#discussion_r2875939722
##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/updater/Updater.java:
##########
@@ -102,140 +94,216 @@ public void update(
List<NameIdentifier> nameIdentifiers,
UpdateType updateType) {
StatisticsCalculator calculator =
getStatisticsCalculator(statisticsCalculatorName);
- List<TableMetricWriteRequest> tableMetricWriteRequests = new ArrayList<>();
- List<JobMetricWriteRequest> jobMetricWriteRequests = new ArrayList<>();
+
+ if (UpdateType.STATISTICS.equals(updateType)) {
+ updateStatisticsForIdentifiers(statisticsCalculatorName,
nameIdentifiers, calculator);
+ return;
+ }
+
+ updateMetricsForIdentifiers(statisticsCalculatorName, nameIdentifiers,
calculator);
+ }
+
+ /**
+ * Updates statistics or metrics for all identifiers returned by the
calculator.
+ *
+ * @param statisticsCalculatorName The provider name of the statistics
calculator.
+ * @param updateType The target update type: statistics or metrics.
+ */
+ public void updateAll(String statisticsCalculatorName, UpdateType
updateType) {
+ StatisticsCalculator calculator =
getStatisticsCalculator(statisticsCalculatorName);
+
+ if (UpdateType.STATISTICS.equals(updateType)) {
+ updateAllStatistics(statisticsCalculatorName, calculator);
+ return;
+ }
+
+ updateAllMetrics(statisticsCalculatorName, calculator);
+ }
+
+ @VisibleForTesting
+ public MetricsUpdater getMetricsUpdater() {
+ return metricsUpdater;
+ }
+
+ @Override
+ public void close() throws Exception {
+ closeableGroup.close();
+ }
+
+ private void updateStatisticsForIdentifiers(
+ String statisticsCalculatorName,
+ List<NameIdentifier> nameIdentifiers,
+ StatisticsCalculator calculator) {
+ long tableRecords = 0;
+ long partitionRecords = 0;
+
+ for (NameIdentifier nameIdentifier : nameIdentifiers) {
+ if (!(calculator instanceof SupportsCalculateTableStatistics)) {
+ continue;
+ }
+ SupportsCalculateTableStatistics supportTableStatistics =
+ (SupportsCalculateTableStatistics) calculator;
+ TableAndPartitionStatistics bundle =
+ supportTableStatistics.calculateTableStatistics(nameIdentifier);
+ List<StatisticEntry<?>> statistics = bundle != null ?
bundle.tableStatistics() : List.of();
+ Map<PartitionPath, List<StatisticEntry<?>>> partitionStatistics =
+ bundle != null ? bundle.partitionStatistics() : Map.of();
+
+ tableRecords += countStatistics(statistics);
+ partitionRecords += countPartitionStatistics(partitionStatistics);
+ LOG.info(
+ "Updating table statistics: calculator={}, identifier={}",
+ statisticsCalculatorName,
+ nameIdentifier);
+
+ updateTableStatistics(statistics, nameIdentifier);
+ updatePartitionStatistics(partitionStatistics, nameIdentifier);
+ }
+
+ System.out.println(
+ String.format(
+ "SUMMARY: %s totalRecords=%d tableRecords=%d partitionRecords=%d
jobRecords=%d",
+ UpdateType.STATISTICS.name().toLowerCase(Locale.ROOT),
+ tableRecords + partitionRecords,
+ tableRecords,
+ partitionRecords,
+ 0L));
Review Comment:
will move system.out to CLI side in another PR
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]