Skip to content

Commit

Permalink
SparkRowInfoJNI class ref
Browse files Browse the repository at this point in the history
  • Loading branch information
lgbo-ustc committed Feb 21, 2025
1 parent 7f69516 commit 12c9ff6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
16 changes: 4 additions & 12 deletions cpp-ch/local-engine/Parser/CHColumnToSparkRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <DataTypes/ObjectUtils.h>
#include <jni/jni_common.h>
#include <Common/Exception.h>
#include <Resource/JVMClassReference.h>

namespace DB
{
Expand Down Expand Up @@ -948,17 +949,7 @@ void FixedLengthDataWriter::unsafeWrite(const char * __restrict src, char * __re

namespace SparkRowInfoJNI
{
static jclass spark_row_info_class;
static jmethodID spark_row_info_constructor;
void init(JNIEnv * env)
{
spark_row_info_class = CreateGlobalClassReference(env, "Lorg/apache/gluten/row/SparkRowInfo;");
spark_row_info_constructor = GetMethodID(env, spark_row_info_class, "<init>", "([J[JJJJ)V");
}
void destroy(JNIEnv * env)
{
env->DeleteGlobalRef(spark_row_info_class);
}

jobject create(JNIEnv * env, const SparkRowInfo & spark_row_info)
{
auto * offsets_arr = env->NewLongArray(spark_row_info.getNumRows());
Expand All @@ -971,8 +962,9 @@ jobject create(JNIEnv * env, const SparkRowInfo & spark_row_info)
int64_t column_number = spark_row_info.getNumCols();
int64_t total_size = spark_row_info.getTotalBytes();

auto & spark_row_info_class_ref = JVM_CLASS_REFERENCE(spark_row_info_class);
return env->NewObject(
spark_row_info_class, spark_row_info_constructor, offsets_arr, lengths_arr, address, column_number, total_size);
spark_row_info_class_ref(), spark_row_info_class_ref["<init>"], offsets_arr, lengths_arr, address, column_number, total_size);
}
}

Expand Down
2 changes: 0 additions & 2 deletions cpp-ch/local-engine/Parser/CHColumnToSparkRow.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ class FixedLengthDataWriter

namespace SparkRowInfoJNI
{
void init(JNIEnv *);
void destroy(JNIEnv *);
jobject create(JNIEnv * env, const SparkRowInfo & spark_row_info);
}

Expand Down
4 changes: 2 additions & 2 deletions cpp-ch/local-engine/Resource/JVMClassReference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
* limitations under the License.
*/
#include "JVMClassReference.h"
#include <iostream>
#include <Common/ErrorCodes.h>
#include <Common/Exception.h>
#include <Common/logger_useful.h>

namespace DB::ErrorCodes
{
Expand Down Expand Up @@ -151,4 +149,6 @@ REGISTER_JVM_CLASS_REFERENCE(cache_manager_result_class, "Lorg/apache/gluten/exe

// Used in SparkMergeTreeWriterJNI
REGISTER_JVM_CLASS_REFERENCE(merge_tree_committer_helper, "Lorg/apache/spark/sql/execution/datasources/v1/clickhouse/MergeTreeCommiterHelper;", "setCurrentTaskWriteInfo", "(Ljava/lang/String;Ljava/lang/String;)V")

REGISTER_JVM_CLASS_REFERENCE(spark_row_info_class, "Lorg/apache/gluten/row/SparkRowInfo;", "<init>", "([J[JJJJ)V")
}
8 changes: 0 additions & 8 deletions cpp-ch/local-engine/local_engine_jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
#include <Resource/ResourceManager.h>
#include <Resource/JVMClassReference.h>

#include <iostream>

#ifdef __cplusplus
namespace DB
{
Expand Down Expand Up @@ -104,10 +102,6 @@ JNIEXPORT jint JNI_OnLoad(JavaVM * vm, void * /*reserved*/)
return JNI_ERR;

local_engine::JNIEnvResourceManager::instance().initialize(env);
std::cout << "xxx \n" << local_engine::JNIEnvResourceManager::instance().dumpInitializeDependencyDAG() << std::endl;

local_engine::SparkRowInfoJNI::init(env);

local_engine::JNIUtils::vm = vm;
return JNI_VERSION_1_8;
}
Expand All @@ -121,8 +115,6 @@ JNIEXPORT void JNI_OnUnload(JavaVM * vm, void * /*reserved*/)
vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_8);

local_engine::JNIEnvResourceManager::instance().destroy(env);

local_engine::SparkRowInfoJNI::destroy(env);
}

JNIEXPORT void Java_org_apache_gluten_vectorized_ExpressionEvaluatorJniWrapper_nativeInitNative(JNIEnv * env, jclass, jbyteArray conf_plan)
Expand Down

0 comments on commit 12c9ff6

Please sign in to comment.