danielcweeks commented on a change in pull request #4050:
URL: https://github.com/apache/iceberg/pull/4050#discussion_r805218826



##########
File path: core/src/main/java/org/apache/iceberg/hadoop/HadoopFileIOMetrics.java
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.hadoop;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Map;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.io.FileIOMetrics;
+
+import static java.lang.String.format;
+
+/**
+ * FileIO Metrics implementation that delegates to Hadoop FileSystem
+ * statistics implementation using the provided scheme.
+ */
+public class HadoopFileIOMetrics implements FileIOMetrics {
+  public static final String SCHEME = "fileio.scheme";
+
+  private String scheme;
+  private transient FileSystem.Statistics statistics;
+
+  @Override
+  public void initialize(Map<String, String> properties) {
+    ValidationException.check(properties.containsKey(SCHEME),
+        "Scheme is required for Hadoop FileSystem metrics reporting");
+
+    // FileIO has no specific implementation class, but Hadoop will
+    // still track and report for the provided scheme.
+    this.scheme = properties.get(SCHEME);
+    this.statistics = FileSystem.getStatistics(scheme, null);
+  }
+
+  @Override
+  public <T> Counter<T> counter(String name, Class<T> type) {
+    switch (name) {
+      case READ_BYTES:
+        ValidationException.check(type != Long.class, "'%s' requires Long 
type", READ_BYTES);
+        return v -> statistics.incrementBytesRead((Long) v);
+      case READ_OPERATIONS:
+        ValidationException.check(type != Integer.class, "'%s' requires 
Integer type", READ_OPERATIONS);
+        return v -> statistics.incrementReadOps((Integer) v);
+      case WRITE_BYTES:

Review comment:
       After some testing, it appears that spark does not use the write metrics 
from Hadoop FileSystem.Statistics (though they have the utility methods to do 
so).  They appear to only be grabbing them from the input path.  However, we 
can report write metrics as other engines (Hive/Flink) likely use them.




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