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


##########
api/src/main/java/org/apache/iceberg/metrics/ScanReport.java:
##########
@@ -0,0 +1,251 @@
+/*
+ * 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.time.Duration;
+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 int matchingDataFiles;
+  private final int matchingDataManifests;
+  private final int totalDataManifestsRead;
+  private final int addedDataFiles;
+  private final int deletedDataFiles;
+  private final Duration totalPlanningDuration;
+  private final long totalFileSizeBytes;
+
+  private ScanReport(
+      String tableName, long snapshotId, Expression filter, Schema projection,
+      int matchingDataFiles, int matchingDataManifests, int 
totalDataManifestsRead,
+      int addedDataFiles, int deletedDataFiles, Duration totalPlanningDuration,
+      long totalFileSizeBytes) {
+    this.tableName = tableName;
+    this.snapshotId = snapshotId;
+    this.filter = filter;
+    this.projection = projection;
+    this.matchingDataFiles = matchingDataFiles;
+    this.matchingDataManifests = matchingDataManifests;
+    this.totalDataManifestsRead = totalDataManifestsRead;
+    this.addedDataFiles = addedDataFiles;
+    this.deletedDataFiles = deletedDataFiles;
+    this.totalPlanningDuration = totalPlanningDuration;
+    this.totalFileSizeBytes = totalFileSizeBytes;
+  }
+
+  public String tableName() {
+    return tableName;
+  }
+
+  public long snapshotId() {
+    return snapshotId;
+  }
+
+  public Expression filter() {
+    return filter;
+  }
+
+  public Schema projection() {
+    return projection;
+  }
+
+  public int matchingDataFiles() {
+    return matchingDataFiles;
+  }
+
+  public int matchingDataManifests() {
+    return matchingDataManifests;
+  }
+
+  public int totalDataManifestsRead() {
+    return totalDataManifestsRead;
+  }
+
+  public int addedDataFiles() {
+    return addedDataFiles;
+  }
+
+  public int deletedDataFiles() {
+    return deletedDataFiles;
+  }
+
+  public Duration totalPlanningDuration() {
+    return totalPlanningDuration;
+  }
+
+  public long totalFileSizeBytes() {
+    return totalFileSizeBytes;
+  }
+
+  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("matchingDataFiles", matchingDataFiles)
+        .add("matchingDataManifests", matchingDataManifests)
+        .add("totalDataManifestsRead", totalDataManifestsRead)
+        .add("addedDataFiles", addedDataFiles)
+        .add("deletedDataFiles", deletedDataFiles)
+        .add("totalScanDuration", totalPlanningDuration)
+        .add("totalFileSizeBytes", totalFileSizeBytes)
+        .toString();
+  }
+
+  @SuppressWarnings("HiddenField")
+  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 tableName) {
+      this.tableName = tableName;
+      return this;
+    }
+
+    public Builder withSnapshotId(long snapshotId) {
+      this.snapshotId = snapshotId;
+      return this;
+    }
+
+    public Builder withFilter(Expression filter) {
+      this.filter = filter;
+      return this;
+    }
+
+    public Builder withProjection(Schema projection) {
+      this.projection = projection;
+      return this;
+    }
+
+    public Builder fromScanMetrics(ScanMetrics scanMetrics) {
+      this.scanMetrics = scanMetrics;
+      return this;
+    }
+
+    public ScanReport build() {
+      Preconditions.checkArgument(null != tableName, "TableName must be 
non-null");
+      Preconditions.checkArgument(null != filter, "Expression filter must be 
non-null");
+      Preconditions.checkArgument(null != projection, "Schema projection must 
be non-null");
+      Preconditions.checkArgument(null != scanMetrics, "ScanMetrics must be 
non-null");
+      return new ScanReport(tableName, snapshotId, filter, projection,
+          scanMetrics.matchingDataFiles().count().orElse(-1),

Review Comment:
   I'm rather thinking of the case where someone would want to send the 
`ScanReport` over the wire. For example, with the REST catalog we might want to 
send the `ScanReport` to an endpoint via a `POST`. Having actual `Counters` / 
`Timers` in the `ScanReport` makes things difficult. Does that make sense? 



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