Skip to content

Commit

Permalink
return JString
Browse files Browse the repository at this point in the history
  • Loading branch information
baibaichen committed Jun 29, 2024
1 parent f7e87eb commit c9c8266
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.gluten.vectorized;

import org.apache.gluten.metrics.IMetrics;
import org.apache.gluten.metrics.NativeMetrics;

import org.apache.spark.sql.execution.utils.CHExecUtil;
import org.apache.spark.sql.vectorized.ColumnVector;
Expand Down Expand Up @@ -50,7 +51,7 @@ public String getId() {

private native void nativeCancel(long nativeHandle);

private native IMetrics nativeFetchMetrics(long nativeHandle);
private native String nativeFetchMetrics(long nativeHandle);

@Override
public boolean hasNextInternal() throws IOException {
Expand All @@ -72,8 +73,8 @@ public ColumnarBatch nextInternal() throws IOException {
}

@Override
public IMetrics getMetricsInternal() throws IOException, ClassNotFoundException {
return nativeFetchMetrics(handle);
public IMetrics getMetricsInternal() {
return new NativeMetrics(nativeFetchMetrics(handle));
}

@Override
Expand Down
13 changes: 2 additions & 11 deletions cpp-ch/local-engine/local_engine_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ static jmethodID block_stripes_constructor;
static jclass split_result_class;
static jmethodID split_result_constructor;

static jclass native_metrics_class;
static jmethodID native_metrics_constructor;

JNIEXPORT jint JNI_OnLoad(JavaVM * vm, void * /*reserved*/)
{
JNIEnv * env;
Expand Down Expand Up @@ -178,10 +175,6 @@ JNIEXPORT jint JNI_OnLoad(JavaVM * vm, void * /*reserved*/)
local_engine::ReservationListenerWrapper::reservation_listener_currentMemory
= local_engine::GetMethodID(env, local_engine::ReservationListenerWrapper::reservation_listener_class, "currentMemory", "()J");


native_metrics_class = local_engine::CreateGlobalClassReference(env, "Lorg/apache/gluten/metrics/NativeMetrics;");
native_metrics_constructor = local_engine::GetMethodID(env, native_metrics_class, "<init>", "(Ljava/lang/String;)V");

local_engine::BroadCastJoinBuilder::init(env);

local_engine::JNIUtils::vm = vm;
Expand All @@ -208,7 +201,6 @@ JNIEXPORT void JNI_OnUnload(JavaVM * vm, void * /*reserved*/)
env->DeleteGlobalRef(local_engine::SourceFromJavaIter::serialized_record_batch_iterator_class);
env->DeleteGlobalRef(local_engine::SparkRowToCHColumn::spark_row_interator_class);
env->DeleteGlobalRef(local_engine::ReservationListenerWrapper::reservation_listener_class);
env->DeleteGlobalRef(native_metrics_class);
}

JNIEXPORT void Java_org_apache_gluten_vectorized_ExpressionEvaluatorJniWrapper_nativeInitNative(JNIEnv * env, jobject, jbyteArray conf_plan)
Expand Down Expand Up @@ -314,16 +306,15 @@ JNIEXPORT void Java_org_apache_gluten_vectorized_BatchIterator_nativeClose(JNIEn
LOCAL_ENGINE_JNI_METHOD_END(env, )
}

JNIEXPORT jobject Java_org_apache_gluten_vectorized_BatchIterator_nativeFetchMetrics(JNIEnv * env, jobject /*obj*/, jlong executor_address)
JNIEXPORT jstring Java_org_apache_gluten_vectorized_BatchIterator_nativeFetchMetrics(JNIEnv * env, jobject /*obj*/, jlong executor_address)
{
LOCAL_ENGINE_JNI_METHOD_START
/// Collect metrics only if optimizations are disabled, otherwise coredump would happen.
const local_engine::LocalExecutor * executor = reinterpret_cast<local_engine::LocalExecutor *>(executor_address);
const auto metric = executor->getMetric();
const String metrics_json = metric ? local_engine::RelMetricSerializer::serializeRelMetric(metric) : "";

const jstring result_metrics = local_engine::charTojstring(env, metrics_json.c_str());
return env->NewObject(native_metrics_class, native_metrics_constructor, result_metrics);
return local_engine::charTojstring(env, metrics_json.c_str());
LOCAL_ENGINE_JNI_METHOD_END(env, nullptr)
}

Expand Down

0 comments on commit c9c8266

Please sign in to comment.