Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ FEATURES_ARG := $(shell ! [ -z $(COMET_FEATURES) ] && echo '--features=$(COMET_F
all: core jvm

core:
cd native && cargo build
cd native && cargo build $(FEATURES_ARG)
test-rust:
# We need to compile CometException so that the cargo test can pass
./mvnw compile -pl common -DskipTests $(PROFILES)
Expand Down
8 changes: 8 additions & 0 deletions common/src/main/java/org/apache/comet/NativeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,12 @@ private static String resourceName() {
* @param logConfPath location to the native log configuration file
*/
static native void init(String logConfPath);

/**
* Check if a specific feature is enabled in the native library.
*
* @param featureName The name of the feature to check (e.g., "hdfs", "jemalloc", "hdfs-opendal")
* @return true if the feature is enabled, false otherwise
*/
public static native boolean isFeatureEnabled(String featureName);
}
29 changes: 29 additions & 0 deletions native/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,35 @@ pub extern "system" fn Java_org_apache_comet_NativeBase_init(

const LOG_PATTERN: &str = "{d(%y/%m/%d %H:%M:%S)} {l} {f}: {m}{n}";

/// JNI method to check if a specific feature is enabled in the native Rust code.
/// # Arguments
/// * `feature_name` - The name of the feature to check. Supported features:
/// - "jemalloc" - tikv-jemallocator memory allocator
/// - "hdfs" - HDFS object store support
/// - "hdfs-opendal" - HDFS support via OpenDAL
/// # Returns
/// * `1` (true) if the feature is enabled
/// * `0` (false) if the feature is disabled or unknown
#[no_mangle]
pub extern "system" fn Java_org_apache_comet_NativeBase_isFeatureEnabled(
Copy link
Contributor

Choose a reason for hiding this comment

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

@parthchandra please help me to understand where the feature comes from?
Another thing would it support multiple features like https://doc.rust-lang.org/cargo/reference/features.html#command-line-feature-options
features=f1,f2 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name of the feature comes from the features specified in cargo.toml. And no, this is one feature at a time.

env: JNIEnv,
_: JClass,
feature_name: JString,
) -> jni::sys::jboolean {
try_unwrap_or_throw(&env, |mut env| {
let feature: String = env.get_string(&feature_name)?.into();

let enabled = match feature.as_str() {
"jemalloc" => cfg!(feature = "jemalloc"),
"hdfs" => cfg!(feature = "hdfs"),
"hdfs-opendal" => cfg!(feature = "hdfs-opendal"),
_ => false, // Unknown features return false
};

Ok(if enabled { 1 } else { 0 })
})
}

// Creates a default log4rs config, which logs to console with `INFO` level.
fn default_logger_config() -> CometResult<Config> {
let console_append = ConsoleAppender::builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import org.apache.spark.sql.comet.CometNativeScanExec
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.functions.{col, sum}

import org.apache.comet.CometConf
import org.apache.comet.{CometConf, NativeBase}
import org.apache.comet.hadoop.fs.FakeHDFSFileSystem

class ParquetReadFromFakeHadoopFsSuite extends CometTestBase with AdaptiveSparkPlanHelper {
Expand Down Expand Up @@ -74,7 +74,18 @@ class ParquetReadFromFakeHadoopFsSuite extends CometTestBase with AdaptiveSparkP
.startsWith(FakeHDFSFileSystem.PREFIX))
}

ignore("test native_datafusion scan on fake fs") {
// This test fails for 'hdfs' but succeeds for 'open-dal'. 'hdfs' requires this fix
// https://github.com/datafusion-contrib/fs-hdfs/pull/29
test("test native_datafusion scan on fake fs") {
// Skip test if HDFS feature is not enabled in native library
val hdfsEnabled =
try {
Copy link
Member

Choose a reason for hiding this comment

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

Should we extract this try...catch block into a common method in NativeBase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done

NativeBase.isFeatureEnabled("hdfs-opendal")
} catch {
case _: Throwable =>
false
}
assume(hdfsEnabled)
val testFilePath =
s"${FakeHDFSFileSystem.PREFIX}${fake_root_dir.getAbsolutePath}/data/test-file.parquet"
writeTestParquetFile(testFilePath)
Expand Down
Loading