Skip to content

Commit

Permalink
Quality of life fixes for easier hacking (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kontinuation authored Oct 2, 2024
1 parent 18150fb commit afd28b9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/org/apache/comet/NativeBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static synchronized void load() {

// Try to load Comet library from the java.library.path.
try {
System.loadLibrary(libraryToLoad);
System.loadLibrary(NATIVE_LIB_NAME);
loaded = true;
} catch (UnsatisfiedLinkError ex) {
// Doesn't exist, so proceed to loading bundled library.
Expand Down
8 changes: 6 additions & 2 deletions native/core/src/jvm_bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ fn get_throwable_message(
throwable: &JThrowable,
) -> CometResult<String> {
unsafe {
let message = env
let message: JString = env
.call_method_unchecked(
throwable,
jvm_classes.throwable_get_message_method,
Expand All @@ -348,7 +348,11 @@ fn get_throwable_message(
)?
.l()?
.into();
let message_str = env.get_string(&message)?.into();
let message_str = if !message.is_null() {
env.get_string(&message)?.into()
} else {
String::from("null")
};

let cause: JThrowable = env
.call_method_unchecked(
Expand Down
51 changes: 51 additions & 0 deletions spark/src/test/scala/org/apache/comet/CometNativeSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.comet

import org.apache.spark.SparkException
import org.apache.spark.sql.CometTestBase
import org.apache.spark.sql.catalyst.expressions.PrettyAttribute
import org.apache.spark.sql.comet.{CometExec, CometExecUtils}
import org.apache.spark.sql.types.LongType
import org.apache.spark.sql.vectorized.ColumnarBatch

class CometNativeSuite extends CometTestBase {
test("test handling NPE thrown by JVM") {
val rdd = spark.range(0, 1).rdd.map { value =>
val limitOp =
CometExecUtils.getLimitNativePlan(Seq(PrettyAttribute("test", LongType)), 100).get
val cometIter = CometExec.getCometIterator(
Seq(new Iterator[ColumnarBatch] {
override def hasNext: Boolean = true
override def next(): ColumnarBatch = throw new NullPointerException()
}),
1,
limitOp)
cometIter.next()
cometIter.close()
value
}

val exception = intercept[SparkException] {
rdd.collect()
}
assert(exception.getMessage contains "java.lang.NullPointerException")
}
}

0 comments on commit afd28b9

Please sign in to comment.