varun-lakhyani commented on code in PR #16729: URL: https://github.com/apache/iceberg/pull/16729#discussion_r3463066770
########## core/src/main/java/org/apache/iceberg/io/EagerInputFile.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: Have to use byte[] as IOUtil.readFully strictly expects bytes[]. Caching byte[] at the EagerInputFile level would pin it for the entire task group lifetime means when whole taskgroup is done then it will be eligible for GC. Current approach lets each task's buffer become GC-eligible immediately after the task completes and stream closes. Also currently there is not case where same file calls multiple newstream. So keeping it as it is. -- 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]
