RussellSpitzer commented on code in PR #16729: URL: https://github.com/apache/iceberg/pull/16729#discussion_r3492750775
########## 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 EagerInputFile implements InputFile { + + private final InputFile delegate; + private final long fileSize; + private final long threshold; + + public EagerInputFile(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() { + if (threshold <= 0 || fileSize > threshold || fileSize > Integer.MAX_VALUE) { Review Comment: I think this logic probably should be at a higher level. Either we use an eager input file or we don't, having this behave as a wrapper leads to some hard to debug cases where we expected to make an eager input file and it just delegates instead. I think it's better if the creator of this object decides whether or not to use an EagerInputFile or just the plain file and leave this class out of the decision making process. -- 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]
