Skip to content

Commit aa4f43a

Browse files
parthchandraSteve Vaughan Jr
authored andcommitted
feat: feature specific tests (apache#2372)
* feat: feature specific tests
1 parent f295e8f commit aa4f43a

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ FEATURES_ARG := $(shell ! [ -z $(COMET_FEATURES) ] && echo '--features=$(COMET_F
2727
all: core jvm
2828

2929
core:
30-
cd native && cargo build
30+
cd native && cargo build $(FEATURES_ARG)
3131
test-rust:
3232
# We need to compile CometException so that the cargo test can pass
3333
./mvnw compile -pl common -DskipTests $(PROFILES)

common/src/main/java/org/apache/comet/NativeBase.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,12 @@ private static String resourceName() {
284284
* @param logConfPath location to the native log configuration file
285285
*/
286286
static native void init(String logConfPath);
287+
288+
/**
289+
* Check if a specific feature is enabled in the native library.
290+
*
291+
* @param featureName The name of the feature to check (e.g., "hdfs", "jemalloc", "hdfs-opendal")
292+
* @return true if the feature is enabled, false otherwise
293+
*/
294+
public static native boolean isFeatureEnabled(String featureName);
287295
}

native/core/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,35 @@ pub extern "system" fn Java_org_apache_comet_NativeBase_init(
100100

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

103+
/// JNI method to check if a specific feature is enabled in the native Rust code.
104+
/// # Arguments
105+
/// * `feature_name` - The name of the feature to check. Supported features:
106+
/// - "jemalloc" - tikv-jemallocator memory allocator
107+
/// - "hdfs" - HDFS object store support
108+
/// - "hdfs-opendal" - HDFS support via OpenDAL
109+
/// # Returns
110+
/// * `1` (true) if the feature is enabled
111+
/// * `0` (false) if the feature is disabled or unknown
112+
#[no_mangle]
113+
pub extern "system" fn Java_org_apache_comet_NativeBase_isFeatureEnabled(
114+
env: JNIEnv,
115+
_: JClass,
116+
feature_name: JString,
117+
) -> jni::sys::jboolean {
118+
try_unwrap_or_throw(&env, |mut env| {
119+
let feature: String = env.get_string(&feature_name)?.into();
120+
121+
let enabled = match feature.as_str() {
122+
"jemalloc" => cfg!(feature = "jemalloc"),
123+
"hdfs" => cfg!(feature = "hdfs"),
124+
"hdfs-opendal" => cfg!(feature = "hdfs-opendal"),
125+
_ => false, // Unknown features return false
126+
};
127+
128+
Ok(enabled as u8)
129+
})
130+
}
131+
103132
// Creates a default log4rs config, which logs to console with `INFO` level.
104133
fn default_logger_config() -> CometResult<Config> {
105134
let console_append = ConsoleAppender::builder()

spark/src/test/scala/org/apache/comet/parquet/ParquetReadFromFakeHadoopFsSuite.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ class ParquetReadFromFakeHadoopFsSuite extends CometTestBase with AdaptiveSparkP
7474
.startsWith(FakeHDFSFileSystem.PREFIX))
7575
}
7676

77-
ignore("test native_datafusion scan on fake fs") {
77+
// This test fails for 'hdfs' but succeeds for 'open-dal'. 'hdfs' requires this fix
78+
// https://github.com/datafusion-contrib/fs-hdfs/pull/29
79+
test("test native_datafusion scan on fake fs") {
80+
// Skip test if HDFS feature is not enabled in native library
81+
assume(isFeatureEnabled("hdfs-opendal"))
7882
val testFilePath =
7983
s"${FakeHDFSFileSystem.PREFIX}${fake_root_dir.getAbsolutePath}/data/test-file.parquet"
8084
writeTestParquetFile(testFilePath)

spark/src/test/scala/org/apache/spark/sql/CometTestBase.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ abstract class CometTestBase
8888
conf
8989
}
9090

91+
protected def isFeatureEnabled(feature: String): Boolean = {
92+
try {
93+
NativeBase.isFeatureEnabled(feature)
94+
} catch {
95+
case _: Throwable =>
96+
false
97+
}
98+
}
99+
91100
/**
92101
* A helper function for comparing Comet DataFrame with Spark result using absolute tolerance.
93102
*/

0 commit comments

Comments
 (0)