Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add experimental remote HDFS support for native DataFusion reader #1359

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

comphead
Copy link
Contributor

@comphead comphead commented Jan 31, 2025

Which issue does this PR close?

Closes #1337.
Depends on #1368

Rationale for this change

What changes are included in this PR?

How are these changes tested?

Manually starting a remote hdfs cluster and running

  test("get_struct_field with DataFusion ParquetExec - simple case - remote HDFS") {

    Seq("parquet").foreach { v1List =>
      withSQLConf(
        SQLConf.USE_V1_SOURCE_LIST.key -> v1List,
        CometConf.COMET_ENABLED.key -> "true",
        CometConf.COMET_EXPLAIN_FALLBACK_ENABLED.key -> "false",
        CometConf.COMET_NATIVE_SCAN_IMPL.key -> CometConf.SCAN_NATIVE_DATAFUSION,
        "spark.hadoop.fs.defaultFS" -> "hdfs://namenode:9000",
        "spark.hadoop.dfs.client.use.datanode.hostname" -> "true",
        "dfs.client.use.datanode.hostname" -> "true") {

        val df = spark.read
          .parquet("hdfs://namenode:9000/user/test4")
          .select("id", "first_name", "personal_info")
        df.printSchema()
        df.explain("formatted")
        df.show(false)
        // checkSparkAnswerAndOperator(df.select("nested1.id"))
      }
    }
  }

@@ -77,6 +77,7 @@ datafusion-comet-proto = { workspace = true }
object_store = { workspace = true }
url = { workspace = true }
chrono = { workspace = true }
datafusion-objectstore-hdfs = { git = "https://github.com/comphead/datafusion-objectstore-hdfs", branch = "master", optional = true }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andygrove I'm keeping the updated HDFS object storage in personal repo for now, let me know if there any concerns

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an expected timeline for when we can move to an official release? Meantime, since we have pointed to a personal repo in the past, it is reasonable to do so for this as well (especially since this is already behind some configuration flags).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be addressed in #1368

@@ -1220,7 +1217,7 @@ impl PhysicalPlanner {
// TODO: I think we can remove partition_count in the future, but leave for testing.
assert_eq!(file_groups.len(), partition_count);

let object_store_url = ObjectStoreUrl::local_filesystem();
let object_store_url = ObjectStoreUrl::parse("hdfs://namenode:9000").unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be addressed in #1360

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The url should be available as part of the file path passed in. (see line 1178 above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @parthchandra it is already fixed.

session_context: Arc<SessionContext>,
) -> Result<(), ExecutionError> {
// TODO: read the namenode configuration from file schema or from spark.defaultFS
let url = Url::try_from("hdfs://namenode:9000").unwrap();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be addressed in #1360

@@ -1861,6 +1864,40 @@ fn trim_end(s: &str) -> &str {
}
}

#[cfg(not(feature = "hdfs"))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hdfs cargo feature makes a conditional compilation if hdfs needed

pub(crate) fn register_object_store(
session_context: Arc<SessionContext>,
) -> Result<(), ExecutionError> {
let object_store = object_store::local::LocalFileSystem::new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to be only a local file system.

Copy link
Contributor Author

@comphead comphead Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the feature enabled for the Comet. LocalFileSystem is by default if no specific features selected.
the annotation on this method is

#[cfg(not(feature = "hdfs"))]

This allows to plugin other features like S3, etc

This particular method is responsible for no remote feature selected e.g. for local filesystem.
If a feature selected the conditional compilation will register an object store related to the feature, like HDFS or S3

@@ -1220,7 +1217,7 @@ impl PhysicalPlanner {
// TODO: I think we can remove partition_count in the future, but leave for testing.
assert_eq!(file_groups.len(), partition_count);

let object_store_url = ObjectStoreUrl::local_filesystem();
let object_store_url = ObjectStoreUrl::parse("hdfs://namenode:9000").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The url should be available as part of the file path passed in. (see line 1178 above)

@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 39.16%. Comparing base (f09f8af) to head (a2130e8).
Report is 19 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##               main    #1359       +/-   ##
=============================================
- Coverage     56.12%   39.16%   -16.96%     
- Complexity      976     2065     +1089     
=============================================
  Files           119      262      +143     
  Lines         11743    60323    +48580     
  Branches       2251    12836    +10585     
=============================================
+ Hits           6591    23627    +17036     
- Misses         4012    32223    +28211     
- Partials       1140     4473     +3333     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@comphead
Copy link
Contributor Author

comphead commented Feb 2, 2025

@andygrove @parthchandra @mbutrovich @kazuyukitanimura can I have a review please?

Copy link
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to 'mock' hdfs and write a unit test? I suppose using the hdfs support to read a local file should do just as well.

Makefile Outdated
@@ -95,7 +98,7 @@ release-linux: clean
cd native && RUSTFLAGS="-Ctarget-cpu=native -Ctarget-feature=-prefer-256-bit" cargo build --release
./mvnw install -Prelease -DskipTests $(PROFILES)
release:
cd native && RUSTFLAGS="-Ctarget-cpu=native" cargo build --release
cd native && RUSTFLAGS="$(RUSTFLAGS) -Ctarget-cpu=native" && RUSTFLAGS=$$RUSTFLAGS cargo build --release $(FEATURES_ARG)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$$RUSTFLAGS ? Never seen this pattern before. What does this do?

Copy link
Contributor Author

@comphead comphead Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makefile syntax lightly different from bash from what I learned.
so in order to access environment variable created on fly it is needed to access it with $$.

It gets created on fly to concatenate release specific RUSTFLAGS with ones that user can set

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Learnt something new today :)

.register_object_store(&url, Arc::new(object_store));
// By default, local FS object store registered
// if `hdfs` feature enabled then HDFS file object store registered
let object_store_url = register_object_store(Arc::clone(&self.session_ctx))?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update this function (get_file_path) as well?
It's currently used by NATIVE_ICEBERG_COMPAT but the goal is to unify it with COMET_DATAFUSION.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point, to verify it we probably need to read Iceberg from HDFS which can be done in #1367

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to wait for actual iceberg integration. CometScan will use COMPAT_ICEBERG if the configuration is set (That's how we are able to run the unit tests).

@comphead
Copy link
Contributor Author

comphead commented Feb 3, 2025

Thanks @parthchandra the integration test will be addressed as part of #1367. We also need to think should it be a separate flow in CI?

Makefile Outdated Show resolved Hide resolved
@comphead comphead marked this pull request as draft February 5, 2025 00:24
pub(crate) fn register_object_store(
session_context: Arc<SessionContext>,
) -> Result<ObjectStoreUrl, ExecutionError> {
// TODO: read the namenode configuration from file schema or from spark.defaultFS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to register object store from native_scan.file_partitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wForget I'm not sure I'm getting it, do you mean the better place to register the object store will be inside file_partitions iterator loop ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean the better place to register the object store will be inside file_partitions iterator loop ?

Yes, is it possible that native scan paths correspond to multiple object stores or are different from spark.defaultFs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for HDFS/S3 the default fs can be taken from spark.hadoop.fs.defaultFS parameter.
To support multiple object stores that is interesting idea however I'm not sure when it can be addressed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for HDFS/S3 the default fs can be taken from spark.hadoop.fs.defaultFS parameter.

Sometimes I also access other hdfs ns like:

select * from `parquet`.`hdfs://other-ns:8020/warehouse/db/table`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is interesting scenario, I'll add a separate test case for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create optional HDFS feature for Comet
5 participants