rdblue commented on code in PR #7337:
URL: https://github.com/apache/iceberg/pull/7337#discussion_r1170603646


##########
core/src/main/java/org/apache/iceberg/TableScanContext.java:
##########
@@ -353,17 +352,29 @@ TableScanContext planWith(ExecutorService executor) {
         toSnapshotId,
         executor,
         fromSnapshotInclusive,
-        metricsReporters);
+        metricsReporter);
   }
 
-  Collection<MetricsReporter> metricsReporters() {
-    return metricsReporters;
+  MetricsReporter metricsReporter() {
+    return metricsReporter;
   }
 
   TableScanContext reportWith(MetricsReporter reporter) {
-    ImmutableList.Builder<MetricsReporter> builder = ImmutableList.builder();
-    builder.addAll(metricsReporters);
-    builder.add(reporter);
+    CompositeMetricsReporter compositeReporter;
+    if (metricsReporter instanceof CompositeMetricsReporter) {
+      compositeReporter = (CompositeMetricsReporter) metricsReporter;
+    } else {
+      compositeReporter = new CompositeMetricsReporter();

Review Comment:
   Rather than creating a reporter and calling register, the pattern we use 
most often is to have a factory method. That factory method can detect 
duplicates and return a single reporter, or can return a composite reporter.
   
   ```java
     MetricsReporter r1 = MetricsReporters.combine(LoggingReporter.INSTANCE, 
LoggingReporter.INSTANCE); // produces LoggingReporter.INSTANCE
     MetricsReporter c1 = MetricsReporters.combine(r1, r2); // produces 
CompositeMetricsRerporter
     MetricsReporter c2 = MetricsReporters.combine(c1, r3); // produces 
CompositeMetricsRerporter
   ```



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to