FANNG1 commented on code in PR #10138:
URL: https://github.com/apache/gravitino/pull/10138#discussion_r2876353852


##########
maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/updater/metrics/storage/BaseGenericJdbcMetricsRepositoryTest.java:
##########
@@ -308,18 +311,98 @@ protected List<String> getMetricValues(List<MetricRecord> 
metrics) {
     return metrics.stream().map(MetricRecord::getValue).toList();
   }
 
+  protected Map<String, List<MetricRecord>> getTableMetrics(
+      NameIdentifier nameIdentifier, long fromSecs, long toSecs) {
+    return convertToMetricRecords(
+        storage.getMetrics(MetricScope.forTable(nameIdentifier), fromSecs, 
toSecs));
+  }
+
+  protected Map<String, List<MetricRecord>> getPartitionMetrics(
+      NameIdentifier nameIdentifier, String partition, long fromSecs, long 
toSecs) {
+    return convertToMetricRecords(
+        storage.getMetrics(
+            MetricScope.forPartition(nameIdentifier, 
parsePartitionPath(partition)),
+            fromSecs,
+            toSecs));
+  }
+
+  protected Map<String, List<MetricRecord>> getJobMetrics(
+      NameIdentifier nameIdentifier, long fromSecs, long toSecs) {
+    return convertToMetricRecords(
+        storage.getMetrics(MetricScope.forJob(nameIdentifier), fromSecs, 
toSecs));
+  }
+
   protected void storeTableMetric(
       NameIdentifier nameIdentifier,
       String metricName,
       Optional<String> partition,
       MetricRecord metric) {
-    storage.storeTableMetrics(
-        List.of(new TableMetricWriteRequest(nameIdentifier, metricName, 
partition, metric)));
+    MetricPoint metricPoint;
+    if (metric == null) {
+      metricPoint = null;
+    } else if (partition != null && partition.isPresent()) {
+      metricPoint =
+          MetricPoint.forPartition(
+              nameIdentifier,
+              parsePartitionPath(partition.get()),
+              metricName,
+              toStatisticValue(metric.getValue()),
+              metric.getTimestamp());
+    } else {
+      metricPoint =
+          MetricPoint.forTable(
+              nameIdentifier,
+              metricName,
+              toStatisticValue(metric.getValue()),
+              metric.getTimestamp());
+    }
+    storage.storeMetrics(List.of(metricPoint));
   }

Review Comment:
   updated



##########
maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/updater/metrics/storage/BaseGenericJdbcMetricsRepositoryTest.java:
##########
@@ -308,18 +311,98 @@ protected List<String> getMetricValues(List<MetricRecord> 
metrics) {
     return metrics.stream().map(MetricRecord::getValue).toList();
   }
 
+  protected Map<String, List<MetricRecord>> getTableMetrics(
+      NameIdentifier nameIdentifier, long fromSecs, long toSecs) {
+    return convertToMetricRecords(
+        storage.getMetrics(MetricScope.forTable(nameIdentifier), fromSecs, 
toSecs));
+  }
+
+  protected Map<String, List<MetricRecord>> getPartitionMetrics(
+      NameIdentifier nameIdentifier, String partition, long fromSecs, long 
toSecs) {
+    return convertToMetricRecords(
+        storage.getMetrics(
+            MetricScope.forPartition(nameIdentifier, 
parsePartitionPath(partition)),
+            fromSecs,
+            toSecs));
+  }
+
+  protected Map<String, List<MetricRecord>> getJobMetrics(
+      NameIdentifier nameIdentifier, long fromSecs, long toSecs) {
+    return convertToMetricRecords(
+        storage.getMetrics(MetricScope.forJob(nameIdentifier), fromSecs, 
toSecs));
+  }
+
   protected void storeTableMetric(
       NameIdentifier nameIdentifier,
       String metricName,
       Optional<String> partition,
       MetricRecord metric) {
-    storage.storeTableMetrics(
-        List.of(new TableMetricWriteRequest(nameIdentifier, metricName, 
partition, metric)));
+    MetricPoint metricPoint;
+    if (metric == null) {
+      metricPoint = null;
+    } else if (partition != null && partition.isPresent()) {
+      metricPoint =
+          MetricPoint.forPartition(
+              nameIdentifier,
+              parsePartitionPath(partition.get()),
+              metricName,
+              toStatisticValue(metric.getValue()),
+              metric.getTimestamp());
+    } else {
+      metricPoint =
+          MetricPoint.forTable(
+              nameIdentifier,
+              metricName,
+              toStatisticValue(metric.getValue()),
+              metric.getTimestamp());
+    }
+    storage.storeMetrics(List.of(metricPoint));
   }
 
   protected void storeJobMetric(
       NameIdentifier nameIdentifier, String metricName, MetricRecord metric) {
-    storage.storeJobMetrics(List.of(new JobMetricWriteRequest(nameIdentifier, 
metricName, metric)));
+    MetricPoint metricPoint =
+        metric == null
+            ? null
+            : MetricPoint.forJob(
+                nameIdentifier,
+                metricName,
+                toStatisticValue(metric.getValue()),
+                metric.getTimestamp());
+    storage.storeMetrics(List.of(metricPoint));
+  }

Review Comment:
   updated



-- 
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]

Reply via email to