RussellSpitzer commented on code in PR #16729:
URL: https://github.com/apache/iceberg/pull/16729#discussion_r3453404078


##########
core/src/main/java/org/apache/iceberg/io/SingleFetchInputFile.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * 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.io;
+
+import java.io.IOException;
+import org.apache.iceberg.exceptions.RuntimeIOException;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+
+/**
+ * A decorator that collapses multiple object-store requests into one by 
fetching the entire file on
+ * the first call when the file size is at or below the configured threshold.
+ */
+public class SingleFetchInputFile implements InputFile {
+
+  private final InputFile delegate;
+  private final long fileSize;
+  private final long threshold;
+
+  public SingleFetchInputFile(InputFile delegate, long fileSize, long 
threshold) {
+    Preconditions.checkNotNull(delegate, "delegate is null");
+    Preconditions.checkArgument(fileSize >= 0, "fileSize is negative: %s", 
fileSize);
+    this.delegate = delegate;
+    this.fileSize = fileSize;
+    this.threshold = threshold;
+  }
+
+  @Override
+  public long getLength() {
+    return fileSize;
+  }
+
+  @Override
+  public String location() {
+    return delegate.location();
+  }
+
+  @Override
+  public boolean exists() {
+    return delegate.exists();
+  }
+
+  @Override
+  public SeekableInputStream newStream() {

Review Comment:
   We could potentially make it so multiple calls to newStream re-use the same 
byte[] or other buffer construct. I'm not sure we have a use case for this yet, 
but it would be a nice behavior to have all inputstreams" from this file re-use 
the same memory. 



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