andrew4699 commented on code in PR #155:
URL: https://github.com/apache/polaris/pull/155#discussion_r1728058495


##########
polaris-service/src/test/java/io/polaris/service/catalog/MeasuredFileIOFactory.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2024 Snowflake Computing Inc.
+ *
+ * Licensed 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 io.polaris.service.catalog;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.DataFile;
+import org.apache.iceberg.DeleteFile;
+import org.apache.iceberg.ManifestFile;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.InputFile;
+import org.apache.iceberg.io.OutputFile;
+
+public class MeasuredFileIOFactory implements FileIOFactory {
+  private final List<MeasuredFileIO> ios;
+
+  public MeasuredFileIOFactory() {
+    ios = new ArrayList<>();
+  }
+
+  @Override
+  public FileIO loadFileIO(String ioImpl, Map<String, String> properties) {
+    MeasuredFileIO wrapped =
+        new MeasuredFileIO(CatalogUtil.loadFileIO(ioImpl, properties, new 
Configuration()));
+    ios.add(wrapped);
+    return wrapped;
+  }
+
+  public long getInputBytes() {
+    long sum = 0;
+    for (MeasuredFileIO io : ios) {
+      sum += io.inputBytes;
+    }
+    return sum;
+  }
+
+  public long getNumOutputFiles() {
+    long sum = 0;
+    for (MeasuredFileIO io : ios) {
+      sum += io.numOutputFiles;
+    }
+    return sum;
+  }
+
+  public static class MeasuredFileIO implements FileIO {
+    private final FileIO io;
+    private long inputBytes;
+    private int numOutputFiles;
+
+    public MeasuredFileIO(FileIO io) {
+      this.io = io;
+    }
+
+    private InputFile measureInputFile(InputFile inner) {
+      inputBytes += inner.getLength();
+      return inner;
+    }
+
+    @Override
+    public InputFile newInputFile(String path) {
+      return measureInputFile(io.newInputFile(path));
+    }
+
+    @Override
+    public InputFile newInputFile(String path, long length) {
+      return measureInputFile(io.newInputFile(path, length));
+    }
+
+    @Override
+    public InputFile newInputFile(DataFile file) {
+      return measureInputFile(io.newInputFile(file));
+    }
+
+    @Override
+    public InputFile newInputFile(DeleteFile file) {
+      return measureInputFile(io.newInputFile(file));
+    }
+
+    @Override
+    public InputFile newInputFile(ManifestFile manifest) {
+      return measureInputFile(io.newInputFile(manifest));
+    }
+
+    @Override
+    public OutputFile newOutputFile(String path) {
+      numOutputFiles++;
+      return io.newOutputFile(path);
+    }
+
+    @Override
+    public void deleteFile(String path) {
+      io.deleteFile(path);
+    }
+
+    @Override
+    public void deleteFile(InputFile file) {
+      io.deleteFile(file);

Review Comment:
   This implementation isn't that great since it doesn't clean up IOs and its 
metrics may not be super useful, it was just intended to be super simple to 
confirm that File IO is wrapped properly.



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