Skip to content

Commit 5448e50

Browse files
committed
wip: feature specific tests
1 parent 65bbe43 commit 5448e50

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,37 @@ 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+
///
105+
/// # Arguments
106+
/// * `feature_name` - The name of the feature to check. Supported features:
107+
/// - "jemalloc" - tikv-jemallocator memory allocator
108+
/// - "hdfs" - HDFS object store support
109+
/// - "hdfs-opendal" - HDFS support via OpenDAL
110+
///
111+
/// # Returns
112+
/// * `1` (true) if the feature is enabled
113+
/// * `0` (false) if the feature is disabled or unknown
114+
#[no_mangle]
115+
pub extern "system" fn Java_org_apache_comet_NativeBase_isFeatureEnabled(
116+
env: JNIEnv,
117+
_: JClass,
118+
feature_name: JString,
119+
) -> jni::sys::jboolean {
120+
try_unwrap_or_throw(&env, |mut env| {
121+
let feature: String = env.get_string(&feature_name)?.into();
122+
123+
let enabled = match feature.as_str() {
124+
"jemalloc" => cfg!(feature = "jemalloc"),
125+
"hdfs" => cfg!(feature = "hdfs"),
126+
"hdfs-opendal" => cfg!(feature = "hdfs-opendal"),
127+
_ => false, // Unknown features return false
128+
};
129+
130+
Ok(if enabled { 1 } else { 0 })
131+
})
132+
}
133+
103134
// Creates a default log4rs config, which logs to console with `INFO` level.
104135
fn default_logger_config() -> CometResult<Config> {
105136
let console_append = ConsoleAppender::builder()

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import java.io.File
2323
import java.nio.file.Files
2424
import java.util.UUID
2525

26+
import org.junit.Assume
27+
2628
import org.apache.commons.io.FileUtils
2729
import org.apache.spark.SparkConf
2830
import org.apache.spark.sql.{CometTestBase, DataFrame, SaveMode}
2931
import org.apache.spark.sql.comet.CometNativeScanExec
3032
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
3133
import org.apache.spark.sql.functions.{col, sum}
3234

33-
import org.apache.comet.CometConf
35+
import org.apache.comet.{CometConf, NativeBase}
3436
import org.apache.comet.hadoop.fs.FakeHDFSFileSystem
3537

3638
class ParquetReadFromFakeHadoopFsSuite extends CometTestBase with AdaptiveSparkPlanHelper {
@@ -74,7 +76,16 @@ class ParquetReadFromFakeHadoopFsSuite extends CometTestBase with AdaptiveSparkP
7476
.startsWith(FakeHDFSFileSystem.PREFIX))
7577
}
7678

77-
ignore("test native_datafusion scan on fake fs") {
79+
test("test native_datafusion scan on fake fs") {
80+
// Skip test if HDFS feature is not enabled in native library
81+
val hdfsEnabled =
82+
try {
83+
NativeBase.isFeatureEnabled("hdfs")
84+
} catch {
85+
case _: Throwable =>
86+
false
87+
}
88+
assume(hdfsEnabled)
7889
val testFilePath =
7990
s"${FakeHDFSFileSystem.PREFIX}${fake_root_dir.getAbsolutePath}/data/test-file.parquet"
8091
writeTestParquetFile(testFilePath)

0 commit comments

Comments
 (0)