nastra commented on code in PR #5268:
URL: https://github.com/apache/iceberg/pull/5268#discussion_r932058161


##########
api/src/main/java/org/apache/iceberg/metrics/ScanReport.java:
##########
@@ -0,0 +1,260 @@
+/*
+ * 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.iceberg.metrics;
+
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.metrics.MetricsContext.Counter;
+import org.apache.iceberg.relocated.com.google.common.base.MoreObjects;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/**
+ * A Table Scan report that contains all relevant information from a Table 
Scan.
+ */
+public class ScanReport implements Serializable {
+
+  private final String tableName;
+  private final long snapshotId;
+  private final Expression filter;
+  private final Schema projection;
+  private final ScanMetrics scanMetrics;
+
+  private ScanReport(
+      String tableName, long snapshotId, Expression filter, Schema projection,
+      ScanMetrics scanMetrics) {
+    this.tableName = tableName;
+    this.snapshotId = snapshotId;
+    this.filter = filter;
+    this.projection = projection;
+    this.scanMetrics = scanMetrics;
+  }
+
+  public String tableName() {
+    return tableName;
+  }
+
+  public long snapshotId() {
+    return snapshotId;
+  }
+
+  public Expression filter() {
+    return filter;
+  }
+
+  public Schema projection() {
+    return projection;
+  }
+
+  public ScanMetrics scanMetrics() {
+    return scanMetrics;
+  }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  @Override
+  public String toString() {
+    return MoreObjects.toStringHelper(this)
+        .add("tableName", tableName)
+        .add("snapshotId", snapshotId)
+        .add("filter", filter)
+        .add("projection", projection)
+        .add("scanMetrics", scanMetrics)
+        .toString();
+  }
+
+  public static class Builder {
+    private String tableName;
+    private long snapshotId = -1L;
+    private Expression filter;
+    private Schema projection;
+    private ScanMetrics scanMetrics;
+
+    private Builder() {
+    }
+
+    public Builder withTableName(String newTableName) {
+      this.tableName = newTableName;
+      return this;
+    }
+
+    public Builder withSnapshotId(long newSnapshotId) {
+      this.snapshotId = newSnapshotId;
+      return this;
+    }
+
+    public Builder withFilter(Expression newFilter) {
+      this.filter = newFilter;
+      return this;
+    }
+
+    public Builder withProjection(Schema newProjection) {
+      this.projection = newProjection;
+      return this;
+    }
+
+    public Builder fromScanMetrics(ScanMetrics newScanMetrics) {

Review Comment:
   It feels a bit odd to me to use the `ScanReport.Builder` to retrieve 
`ScanMetrics`. To me the `ScanReport` feels like something that is final and 
you'd only want to create at the very end. 
   
   However, I think we can still simplify `ScanReporter` and make it a 
`FunctionalInterface` that only has `void reportScan(ScanReport scanReport)` 
and nothing else. 
   `BaseTableScan` doesn't need the `ScanReporter` to init the metrics. It 
could just do
   ```
   protected ScanReport.ScanMetrics scanMetrics() {
       if (scanMetrics == null) {
         this.scanMetrics = new ScanReport.ScanMetrics(new 
DefaultMetricsContext());
       }
   
       return scanMetrics;
     }
   ```
   where it can specify whatever metrics context should be used.
   
   Then we just build the `ScanReport` from `ScanMetrics` (and other info) and 
send it off via `context().scanReporter().reportScan(scanReport)`.
   



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