in gandiva/src/main/cpp/jni_common.cc [905:978]
JNIEXPORT jlong JNICALL Java_org_apache_arrow_gandiva_evaluator_JniWrapper_buildFilter(
JNIEnv* env, jobject obj, jbyteArray schema_arr, jbyteArray condition_arr,
jlong configuration_id) {
jlong module_id = 0LL;
std::shared_ptr<Filter> filter;
std::shared_ptr<FilterHolder> holder;
gandiva::types::Schema schema;
jsize schema_len = env->GetArrayLength(schema_arr);
jbyte* schema_bytes = env->GetByteArrayElements(schema_arr, 0);
gandiva::types::Condition condition;
jsize condition_len = env->GetArrayLength(condition_arr);
jbyte* condition_bytes = env->GetByteArrayElements(condition_arr, 0);
ConditionPtr condition_ptr;
SchemaPtr schema_ptr;
gandiva::Status status;
std::shared_ptr<Configuration> config = ConfigHolder::MapLookup(configuration_id);
std::stringstream ss;
if (config == nullptr) {
ss << "configuration is mandatory.";
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
goto err_out;
}
if (!ParseProtobuf(reinterpret_cast<uint8_t*>(schema_bytes), schema_len, &schema)) {
ss << "Unable to parse schema protobuf\n";
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
goto err_out;
}
if (!ParseProtobuf(reinterpret_cast<uint8_t*>(condition_bytes), condition_len,
&condition)) {
ss << "Unable to parse condition protobuf\n";
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
goto err_out;
}
// convert gandiva::types::Schema to arrow::Schema
schema_ptr = ProtoTypeToSchema(schema);
if (schema_ptr == nullptr) {
ss << "Unable to construct arrow schema object from schema protobuf\n";
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
goto err_out;
}
condition_ptr = ProtoTypeToCondition(condition);
if (condition_ptr == nullptr) {
ss << "Unable to construct condition object from condition protobuf\n";
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
goto err_out;
}
// good to invoke the filter builder now
status = Filter::Make(schema_ptr, condition_ptr, config, &filter);
if (!status.ok()) {
ss << "Failed to make LLVM module due to " << status.message() << "\n";
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
goto err_out;
}
// store the result in a map
holder = std::shared_ptr<FilterHolder>(new FilterHolder(schema_ptr, std::move(filter)));
module_id = filter_modules_.Insert(holder);
releaseFilterInput(schema_arr, schema_bytes, condition_arr, condition_bytes, env);
return module_id;
err_out:
env->ThrowNew(gandiva_exception_, ss.str().c_str());
return module_id;
}