steveloughran commented on code in PR #3678:
URL: https://github.com/apache/parquet-java/pull/3678#discussion_r3622651660
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/util/HadoopInputFile.java:
##########
@@ -61,6 +65,27 @@ public static HadoopInputFile fromPath(Path path,
Configuration conf) throws IOE
return new HadoopInputFile(fs, fs.getFileStatus(path), conf);
}
+ /**
+ * Creates an input file using a caller-supplied file length.
+ *
+ * <p>The length is trusted and no file status lookup is performed. Callers
must provide the exact
+ * length of the file that will be opened. The file is not validated until
it is opened.
Review Comment:
declare that the existence of the file may not be checked until the first
read, and the length may be trusted; if it is wrong then reads may fail.
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/util/HadoopInputFile.java:
##########
@@ -61,6 +65,27 @@ public static HadoopInputFile fromPath(Path path,
Configuration conf) throws IOE
return new HadoopInputFile(fs, fs.getFileStatus(path), conf);
}
+ /**
+ * Creates an input file using a caller-supplied file length.
+ *
+ * <p>The length is trusted and no file status lookup is performed. Callers
must provide the exact
+ * length of the file that will be opened. The file is not validated until
it is opened.
+ *
+ * @param path file path
+ * @param length exact file length in bytes
+ * @param conf configuration used to resolve the file system
+ * @return an input file that uses the supplied length
+ * @throws IllegalArgumentException if {@code length} is negative
+ * @throws IOException if the file system cannot be resolved
+ */
+ public static HadoopInputFile fromPath(Path path, long length, Configuration
conf) throws IOException {
+ if (length < 0) {
+ throw new IllegalArgumentException("Invalid file length: " + length);
+ }
+ FileSystem fs = path.getFileSystem(conf);
+ return new HadoopInputFile(fs, path, length, conf);
Review Comment:
this is the only place the new ctor is called, isn't it? so it can never be
invoked with a length that is unknown.
##########
parquet-hadoop/src/test/java/org/apache/parquet/hadoop/util/TestHadoopOpenFile.java:
##########
@@ -101,10 +102,41 @@ public void testOpenFileGoodPath() throws Throwable {
// this looks up the FS binding via the status file path.
openAndRead(fileFromStatus());
+ assertThat(opener.getFileStatus()).as("file status").isSameAs(status);
+
// The fallback call of open(path) never took place.
Mockito.verify(mockFS, never()).open(path);
}
+ /**
+ * A caller-supplied length avoids a status lookup and is passed to
openFile().
+ */
+ @Test
+ public void testOpenFileWithKnownLength() throws Throwable {
Review Comment:
add a test opening a nonexistent file with a declared length. For cloud
storage, it may not fail until the first read(); for local fs it will fail
immediately. In both cases it must fail with FileNotFoundException.
--
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]