fix(fs): stop depending on the optional FileSystem#getScheme() (#19470)
* fix(fs): stop depending on the optional FileSystem#getScheme()
FileSystem#getScheme() is optional in Hadoop: the base implementation throws
UnsupportedOperationException, and proxy implementations such as Presto's
PrestoS3FileSystem do not override it. Hudi called it unguarded on filesystems it
did not implement, so opening a log file on such a filesystem failed with
"Not implemented by the PrestoS3FileSystem FileSystem implementation" instead of
reading anything (HUDI-4602).
Adds HadoopFSUtils#getScheme(FileSystem), which returns fs.getScheme() and falls
back to fs.getUri().getScheme() when it is unimplemented. getUri() is abstract, so
every implementation supplies it, and its scheme is what getScheme() returns
wherever both are present. This is the same conclusion as #793, which stopped
HoodieWrapperFileSystem calling getScheme() on the filesystem it wraps.
Routes the seven unguarded call sites through it: isGCSFileSystem and
isCHDFileSystem (the reported read path), registerFileSystem,
HoodieWrapperFileSystem#convertToHoodiePath, HoodieRetryWrapperFileSystem#getScheme,
WriteMarkersFactory's HDFS gate, and HoodieHadoopStorage#getScheme, which is what
the seven HoodieStorage#getScheme callers reach.
isGCSFileSystem's comparison is also flipped to put the constant first, matching
isCHDFileSystem, so a filesystem whose URI carries no scheme returns false rather
than throwing NullPointerException.
* test(fs): say which branch of the helper each assertion covers
Review nit: the assertion messages did not make clear what had gone wrong. Each
now names the filesystem and the branch of the helper it pins - LocalFileSystem
overriding getScheme() so the helper returns what it reports, FilterFileSystem not
overriding it so the helper falls back to getUri().getScheme().
* fix(fs): fail loudly on an unresolvable scheme, and cover the sites this reroutes
Review feedback, all of it well founded.
The fallback no longer returns null. InLineFileSystem is the counter-example in this
module: getScheme() is "inlinefs" while getUri() is URI.create("inlinefs"), which has no
colon and so no scheme, so the two are not interchangeable and the javadoc claim that
they agree was simply wrong. A null surfaced far from the cause as "does not support
scheme null" or "Unsupported scheme :null" with the UnsupportedOperationException
discarded; it now throws with that exception chained. HoodieException rather than
HoodieIOException, since the latter only accepts an IOException cause.
HoodieHadoopStorage memoizes the scheme. On a filesystem without getScheme() the
fallback costs a thrown-and-caught exception, and this is called once per log block via
StorageSchemes.isWriteTransactional and three times per immutable-file write via
needCreateTempFile. A lazy field keeps all five constructors untouched.
Test coverage for what this actually reroutes, none of which any test reached:
- registerFileSystem, HoodieWrapperFileSystem#convertToHoodiePath (the write path) and
HoodieHadoopStorage#getScheme, via a LocalFileSystem subclass whose getScheme() throws,
registered as fs.file.impl so it is reached through FileSystem.get.
- isGCSFileSystem and isCHDFileSystem, which become reachable for proxy filesystems for
the first time here and select different stream wrappers: a scheme-less filesystem
reporting gs:// now yields SchemeAwareFSDataInputStream and ofs:// yields
BoundedFsDataInputStream.
- the new unresolvable-scheme failure.
TestFSUtilsWithRetryWrapperEnable#testGetSchema has been inert since HUDI-5286 added it:
it asserted on HoodieWrapperFileSystem#getScheme, which is uri.getScheme() and never
dispatches into the retry wrapper, and FakeRemoteFileSystem overrode getScheme() to
delegate to a real LocalFileSystem so it could not throw. Dropping that override gives
the fake the PrestoS3FileSystem shape and the assertion now targets the retry wrapper,
so it guards both HUDI-5286 and this change. Verified: it fails with the pre-PR helper.
Also drops the try/catch in convertToHoodiePath that only rethrew HoodieIOException
unchanged, dead since ef70de2bba7b, and the duplicated fixture and redundant nested
close in TestHadoopFSUtils.Apache Hudi is an open data lakehouse platform, built on a high-performance open table format to ingest, index, store, serve, transform and manage your data across multiple cloud data environments.
Hudi stores all data and metadata on cloud storage in open formats, providing the following features across different aspects.
Hudi supports different types of queries, on top of a single table.
Learn more about Hudi at https://hudi.apache.org
Prerequisites for building Apache Hudi:
# Checkout code and build git clone https://github.com/apache/hudi.git && cd hudi mvn clean package -DskipTests -Dspark3.5 -Dflink2.1 # Start command spark-3.5.0-bin-hadoop3/bin/spark-shell \ --jars `ls packaging/hudi-spark-bundle/target/hudi-spark3.5-bundle_2.12-*.*.*-SNAPSHOT.jar` \ --conf 'spark.serializer=org.apache.spark.serializer.KryoSerializer' \ --conf 'spark.sql.extensions=org.apache.spark.sql.hudi.HoodieSparkSessionExtension' \ --conf 'spark.sql.catalog.spark_catalog=org.apache.spark.sql.hudi.catalog.HoodieCatalog' \ --conf 'spark.kryo.registrator=org.apache.spark.HoodieSparkKryoRegistrar'
To build for integration tests that include hudi-integ-test-bundle, use -Dintegration-tests.
To build the Javadoc for all Java and Scala classes (project should be already compiled):
# Javadoc generated under target/site/apidocs mvn javadoc:aggregate -Pjavadocs
The default Spark 3.x version, corresponding to spark3 profile is 3.5.3. The default Scala version is 2.12. Scala 2.13 is supported for Spark 3.5 and above.
Refer to the table below for building with different Spark and Scala versions.
| Maven build options | Expected Spark bundle jar name | Notes |
|---|---|---|
| (empty) | hudi-spark3.5-bundle_2.12 | For Spark 3.5.x and Scala 2.12 (default options) |
-Dspark3.3 | hudi-spark3.3-bundle_2.12 | For Spark 3.3.2+ and Scala 2.12 |
-Dspark3.4 | hudi-spark3.4-bundle_2.12 | For Spark 3.4.x and Scala 2.12 |
-Dspark3.5 -Dscala-2.12 | hudi-spark3.5-bundle_2.12 | For Spark 3.5.x and Scala 2.12 (same as default) |
-Dspark3.5 -Dscala-2.13 | hudi-spark3.5-bundle_2.13 | For Spark 3.5.x and Scala 2.13 |
-Dspark4.0 | hudi-spark4.0-bundle_2.13 | For Spark 4.0 and Scala 2.13 (Needs java 17) |
-Dspark4.1 | hudi-spark4.1-bundle_2.13 | For Spark 4.1 and Scala 2.13 (Needs java 17) |
-Dspark4.2 | hudi-spark4.2-bundle_2.13 | For Spark 4.2 and Scala 2.13 (Needs java 17) |
-Dspark3 | hudi-spark3-bundle_2.12 (legacy bundle name) | For Spark 3.5.x and Scala 2.12 |
Please note that only Spark-related bundles, i.e., hudi-spark-bundle, hudi-utilities-bundle, hudi-utilities-slim-bundle, can be built using scala-2.13 profile. Hudi Flink bundle cannot be built using scala-2.13 profile. To build these bundles on Scala 2.13, use the following command:
# Build against Spark 3.5.x and Scala 2.13 mvn clean package -DskipTests -Dspark3.5 -Dscala-2.13 -pl packaging/hudi-spark-bundle,packaging/hudi-utilities-bundle,packaging/hudi-utilities-slim-bundle -am
For example,
# Build against Spark 3.5.x mvn clean package -DskipTests -Dspark3.5 -Dflink2.1 # Build against Spark 3.4.x mvn clean package -DskipTests -Dspark3.4 -Dflink2.1
Starting from versions 0.11, Hudi no longer requires spark-avro to be specified using --packages
The default Flink version supported is 2.1. The default Flink 2.1.x version, corresponding to the flink2.1 profile, is 2.1.1. Flink is Scala-free since 1.15.x, there is no need to specify the Scala version for Flink 1.15.x and above versions. Refer to the table below for building with different Flink and Scala versions.
| Maven build options | Expected Flink bundle jar name | Notes |
|---|---|---|
| (empty) | hudi-flink2.1-bundle | For Flink 2.1 (default options) |
-Dflink2.1 | hudi-flink2.1-bundle | For Flink 2.1 (same as default) |
-Dflink2.0 | hudi-flink2.0-bundle | For Flink 2.0 |
-Dflink1.20 | hudi-flink1.20-bundle | For Flink 1.20 |
-Dflink1.19 | hudi-flink1.19-bundle | For Flink 1.19 |
-Dflink1.18 | hudi-flink1.18-bundle | For Flink 1.18 |
For example,
# Build against Flink 2.1.x mvn clean package -DskipTests -Dflink2.1
Unit tests can be run with maven profile unit-tests.
mvn -Punit-tests test
Functional tests, which are tagged with @Tag("functional"), can be run with maven profile functional-tests.
mvn -Pfunctional-tests test
Integration tests can be run with maven profile integration-tests.
mvn -Pintegration-tests verify
To run tests with spark event logging enabled, define the Spark event log directory. This allows visualizing test DAG and stages using Spark History Server UI.
mvn -Punit-tests test -DSPARK_EVLOG_DIR=/path/for/spark/event/log
Please visit https://hudi.apache.org/docs/quick-start-guide.html to quickly explore Hudi's capabilities using spark-shell.
Please check out our contribution guide to learn more about how to contribute. For code contributions, please refer to the developer setup.