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


##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/updater/metrics/storage/jdbc/JdbcMetricsRepository.java:
##########
@@ -230,208 +228,83 @@ private void executeSchemaSql(Connection connection, 
String sqlContent) throws S
   }
 
   @Override
-  public void storeTableMetrics(List<TableMetricWriteRequest> metrics) {
+  public void storeMetrics(List<MetricPoint> metrics) {
     Preconditions.checkArgument(metrics != null, "metrics must not be null");
     if (metrics.isEmpty()) {
       return;
     }
 
-    String insertSql =
+    String tableInsertSql =
         "INSERT INTO table_metrics (table_identifier, metric_name, 
table_partition, metric_ts, metric_value) VALUES (?, ?, ?, ?, ?)";
+    String jobInsertSql =
+        "INSERT INTO job_metrics (job_identifier, metric_name, metric_ts, 
metric_value) VALUES (?, ?, ?, ?)";
 
     try (Connection conn = getConnection();
-        PreparedStatement insertStmt = conn.prepareStatement(insertSql)) {
-      int batchCount = 0;
-      for (TableMetricWriteRequest request : metrics) {
-        Preconditions.checkArgument(request != null, "table metric request 
must not be null");
-        validateWriteArguments(
-            request.nameIdentifier(), request.metricName(), 
request.partition(), request.metric());
-        String normalizedIdentifier = 
normalizeIdentifier(request.nameIdentifier());
-        String normalizedMetricName = 
normalizeMetricName(request.metricName());
-        Optional<String> normalizedPartition = 
normalizePartition(request.partition());
-        MetricRecord metric = request.metric();
-        insertStmt.setString(1, normalizedIdentifier);
-        insertStmt.setString(2, normalizedMetricName);
-        insertStmt.setString(3, normalizedPartition.orElse(null));
-        insertStmt.setLong(4, metric.getTimestamp());
-        insertStmt.setString(5, metric.getValue());
-        insertStmt.addBatch();
-        batchCount++;
-        if (batchCount >= BATCH_UPDATE_SIZE) {
-          insertStmt.executeBatch();
-          batchCount = 0;
+        PreparedStatement tableInsertStmt = 
conn.prepareStatement(tableInsertSql);
+        PreparedStatement jobInsertStmt = conn.prepareStatement(jobInsertSql)) 
{
+      int tableBatchCount = 0;

Review Comment:
   refactored



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