findepi commented on code in PR #4537: URL: https://github.com/apache/iceberg/pull/4537#discussion_r872407417
########## core/src/main/java/org/apache/iceberg/stats/StatsReader.java: ########## @@ -0,0 +1,183 @@ +/* + * 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.stats; + +import java.io.Closeable; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.util.AbstractMap.SimpleEntry; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Stream; +import org.apache.iceberg.io.InputFile; +import org.apache.iceberg.io.SeekableInputStream; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.io.ByteStreams; + +public class StatsReader implements Closeable { + + private final long fileLength; + private final SeekableInputStream input; + private Optional<Integer> knownFooterSize; + private Optional<FileMetadata> knownFileMetadata = Optional.empty(); + + public StatsReader(InputFile inputFile, Optional<Integer> footerSize) { + this.fileLength = inputFile.getLength(); + this.input = Preconditions.checkNotNull(inputFile, "inputFile is null").newStream(); + this.knownFooterSize = Preconditions.checkNotNull(footerSize, "footerSize is null"); + footerSize.ifPresent(size -> + Preconditions.checkArgument(0 < size && size <= fileLength - StatsFormat.getMagic().length, + "Invalid footer size: %s", size)); + } + + public FileMetadata getFileMetadata() throws IOException { + if (!knownFileMetadata.isPresent()) { + int footerSize = getFooterSize(); + byte[] footer = readInput(fileLength - footerSize, footerSize); Review Comment: I don't do additional HEAD request, because file size and footer size are known. (https://github.com/apache/iceberg-docs/pull/77) i see that with `RangeReadable.readTail` i could remove the file size and footer size from the table snapshot, which would be a good thing. To do this, i would need to assume some maximum for a "reasonable" footer size and do a `readTail` read with that size (i saw a suggestion to read 16kB, that would work). It wouldn't change number of requests sent (since currently file size and footer size are known), but it would slightly reduce amount of data kept in a table. I assume we don't want to make such an improvement for some file systems while actually degrading performance on other file systems, right? What file systems is RangeReadable available on? -- 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]
