Copilot commented on code in PR #4209:
URL: https://github.com/apache/gobblin/pull/4209#discussion_r4259472774


##########
gobblin-runtime/src/main/java/org/apache/gobblin/runtime/DatasetTaskSummary.java:
##########
@@ -51,11 +51,17 @@ public class DatasetTaskSummary {
   // run can commit more than one snapshot/partition); null = 
unsupported/unreported.
   private String snapshotsCommitted;
   private String partitionsCommitted;
+  // Retention (data-deletion) counts, likewise not @NonNull and populated 
during JSON deserialization of
+  // events that carry them (e.g. DDM retention runs); null = not a deletion 
job.
+  private Long versionsTotal;
+  private Long versionsDeleted;
+  private Long directoriesPruned;
 
   /**
    * Convert a {@link DatasetTaskSummary} to a {@link DatasetMetric}.
    */
   public static DatasetMetric toDatasetMetric(DatasetTaskSummary 
datasetTaskSummary) {
-    return new DatasetMetric(datasetTaskSummary.getDatasetUrn(), 
datasetTaskSummary.getBytesWritten(), datasetTaskSummary.getRecordsWritten(), 
datasetTaskSummary.isSuccessfullyCommitted(), 
datasetTaskSummary.getDataQualityStatus(), 
datasetTaskSummary.getSnapshotsCommitted(), 
datasetTaskSummary.getPartitionsCommitted());
+    return new DatasetMetric(datasetTaskSummary.getDatasetUrn(), 
datasetTaskSummary.getBytesWritten(), datasetTaskSummary.getRecordsWritten(), 
datasetTaskSummary.isSuccessfullyCommitted(), 
datasetTaskSummary.getDataQualityStatus(), 
datasetTaskSummary.getSnapshotsCommitted(), 
datasetTaskSummary.getPartitionsCommitted(),
+        datasetTaskSummary.getVersionsTotal(), 
datasetTaskSummary.getVersionsDeleted(), 
datasetTaskSummary.getDirectoriesPruned());

Review Comment:
   Using a long positional constructor call is brittle and easy to break as the 
Avro schema evolves (parameter order errors are hard to spot in review). Prefer 
constructing `DatasetMetric` via its Avro builder (or setters) so fields are 
clearly named and adding future fields is less error-prone.



##########
gobblin-runtime/src/test/java/org/apache/gobblin/runtime/DatasetTaskSummaryTest.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.runtime;
+
+import java.lang.reflect.Type;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.gson.reflect.TypeToken;
+
+import org.apache.gobblin.metrics.DatasetMetric;
+import org.apache.gobblin.runtime.util.GsonUtils;
+
+
+public class DatasetTaskSummaryTest {
+
+  private static final Type SUMMARY_LIST = new 
TypeToken<List<DatasetTaskSummary>>() { }.getType();
+
+  @Test
+  public void testToDatasetMetricMapsRetentionCountsFromJson() {
+    // The shape a DDM retention run emits: nothing written, deletion counts 
set.
+    String json = 
"[{\"datasetUrn\":\"hdfs://nn/data/foo\",\"recordsWritten\":0,\"bytesWritten\":0,"
+        + 
"\"successfullyCommitted\":true,\"versionsTotal\":10,\"versionsDeleted\":4,\"directoriesPruned\":1}]";
+    List<DatasetTaskSummary> summaries = 
GsonUtils.GSON_WITH_DATE_HANDLING.fromJson(json, SUMMARY_LIST);

Review Comment:
   The constant name `SUMMARY_LIST` is a bit ambiguous since it’s actually a 
`Type` token for a list of summaries. Consider renaming to something clearer 
like `SUMMARY_LIST_TYPE` (or similar) to reflect what it represents.



##########
gobblin-runtime/src/test/java/org/apache/gobblin/runtime/DatasetTaskSummaryTest.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gobblin.runtime;
+
+import java.lang.reflect.Type;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.google.gson.reflect.TypeToken;
+
+import org.apache.gobblin.metrics.DatasetMetric;
+import org.apache.gobblin.runtime.util.GsonUtils;
+
+
+public class DatasetTaskSummaryTest {
+
+  private static final Type SUMMARY_LIST = new 
TypeToken<List<DatasetTaskSummary>>() { }.getType();
+
+  @Test
+  public void testToDatasetMetricMapsRetentionCountsFromJson() {
+    // The shape a DDM retention run emits: nothing written, deletion counts 
set.
+    String json = 
"[{\"datasetUrn\":\"hdfs://nn/data/foo\",\"recordsWritten\":0,\"bytesWritten\":0,"
+        + 
"\"successfullyCommitted\":true,\"versionsTotal\":10,\"versionsDeleted\":4,\"directoriesPruned\":1}]";
+    List<DatasetTaskSummary> summaries = 
GsonUtils.GSON_WITH_DATE_HANDLING.fromJson(json, SUMMARY_LIST);
+
+    DatasetMetric metric = 
DatasetTaskSummary.toDatasetMetric(summaries.get(0));
+
+    Assert.assertEquals(metric.getDatasetUrn(), "hdfs://nn/data/foo");
+    Assert.assertEquals(metric.getEntitiesWritten(), Long.valueOf(0L));
+    Assert.assertEquals(metric.getVersionsTotal(), Long.valueOf(10L));
+    Assert.assertEquals(metric.getVersionsDeleted(), Long.valueOf(4L));
+    Assert.assertEquals(metric.getDirectoriesPruned(), Long.valueOf(1L));

Review Comment:
   This test validates the new retention counters, but it doesn’t assert other 
key fields present in the JSON (e.g., `bytesWritten` and 
`successfullyCommitted`). Adding assertions for those fields would better 
protect against regressions in JSON deserialization or mapping (e.g., fields 
getting dropped/renamed).



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