From c9c8266647ca48c02df957881cf682d3826b60be Mon Sep 17 00:00:00 2001 From: Chang Chen Date: Sat, 29 Jun 2024 23:22:17 +0800 Subject: [PATCH] return JString --- .../org/apache/gluten/vectorized/BatchIterator.java | 7 ++++--- cpp-ch/local-engine/local_engine_jni.cpp | 13 ++----------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/backends-clickhouse/src/main/java/org/apache/gluten/vectorized/BatchIterator.java b/backends-clickhouse/src/main/java/org/apache/gluten/vectorized/BatchIterator.java index d674c6e90defd..1fbb6053a2afc 100644 --- a/backends-clickhouse/src/main/java/org/apache/gluten/vectorized/BatchIterator.java +++ b/backends-clickhouse/src/main/java/org/apache/gluten/vectorized/BatchIterator.java @@ -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; @@ -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 { @@ -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 diff --git a/cpp-ch/local-engine/local_engine_jni.cpp b/cpp-ch/local-engine/local_engine_jni.cpp index b4f671be1d5e5..429750219c0fd 100644 --- a/cpp-ch/local-engine/local_engine_jni.cpp +++ b/cpp-ch/local-engine/local_engine_jni.cpp @@ -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; @@ -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, "", "(Ljava/lang/String;)V"); - local_engine::BroadCastJoinBuilder::init(env); local_engine::JNIUtils::vm = vm; @@ -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) @@ -314,7 +306,7 @@ 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. @@ -322,8 +314,7 @@ JNIEXPORT jobject Java_org_apache_gluten_vectorized_BatchIterator_nativeFetchMet 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) }