Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
Signed-off-by: stdpain <[email protected]>
  • Loading branch information
stdpain committed Sep 3, 2024
1 parent 3c8e144 commit 381bdf3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
34 changes: 21 additions & 13 deletions be/src/exprs/table_function/java_udtf_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,28 @@ std::pair<Columns, UInt32Column::Ptr> JavaUDTFFunction::process(RuntimeState* ru

std::vector<jvalue> call_stack;
std::vector<jobject> rets;
DeferOp defer = DeferOp([&]() {
// clean up arrays
for (auto& ret : rets) {
if (ret) {
env->DeleteLocalRef(ret);
}
}
});
size_t num_rows = cols[0]->size();
size_t num_cols = cols.size();
state->set_processed_rows(num_rows);

call_stack.reserve(num_cols);
rets.resize(num_rows);

// reserve 16 local refs
DeferOp defer = DeferOp([&]() {
// clean up arrays
env->PopLocalFrame(nullptr);
});
env->PushLocalFrame(num_cols * num_rows + 16);

for (int i = 0; i < num_rows; ++i) {
DeferOp defer = DeferOp([&]() {
for (int j = 0; j < num_cols; ++j) {
release_jvalue(stateUDTF->method_process()->method_desc[j + 1].is_box, call_stack[j]);
}
call_stack.clear();
});

for (int j = 0; j < num_cols; ++j) {
auto method_type = stateUDTF->method_process()->method_desc[j + 1];
jvalue val = cast_to_jvalue<true>(method_type.type, method_type.is_box, cols[j].get(), i);
Expand All @@ -161,11 +168,13 @@ std::pair<Columns, UInt32Column::Ptr> JavaUDTFFunction::process(RuntimeState* ru

rets[i] = env->CallObjectMethodA(stateUDTF->handle(), methodID, call_stack.data());

for (int j = 0; j < num_cols; ++j) {
release_jvalue(stateUDTF->method_process()->method_desc[j + 1].is_box, call_stack[j]);
if (auto jthr = helper.getEnv()->ExceptionOccurred(); jthr != nullptr) {
std::string err = fmt::format("execute UDF Function meet Exception:{}", helper.dumpExceptionString(jthr));
LOG(WARNING) << err;
helper.getEnv()->ExceptionClear();
state->set_status(Status::InternalError(err));
return std::make_pair(Columns{}, nullptr);
}

call_stack.clear();
}

// Build Return Type
Expand All @@ -192,7 +201,6 @@ std::pair<Columns, UInt32Column::Ptr> JavaUDTFFunction::process(RuntimeState* ru
return std::make_pair(Columns{}, nullptr);
}
append_jvalue(method_desc, col.get(), {.l = vi});
release_jvalue(method_desc.is_box, {.l = vi});
}
}

Expand Down
22 changes: 15 additions & 7 deletions be/src/udf/java/java_data_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "column/type_traits.h"
#include "common/compiler_util.h"
#include "common/status.h"
#include "udf/java/java_udf.h"
#include "util/defer_op.h"

#define APPLY_FOR_NUMBERIC_TYPE(M) \
Expand Down Expand Up @@ -231,12 +232,16 @@ Status check_type_matched(MethodTypeDescriptor method_type_desc, jobject val) {
auto* env = helper.getEnv();

switch (method_type_desc.type) {
#define INSTANCE_OF_TYPE(NAME, TYPE) \
case NAME: { \
if (!env->IsInstanceOf(val, helper.TYPE##_class())) { \
return Status::InternalError("Type not matched"); \
} \
break; \
#define INSTANCE_OF_TYPE(NAME, TYPE) \
case NAME: { \
if (!env->IsInstanceOf(val, helper.TYPE##_class())) { \
auto clazz = env->GetObjectClass(val); \
LOCAL_REF_GUARD(clazz); \
return Status::InternalError(fmt::format("Type not matched, expect {}, but got {}", \
helper.to_string(helper.TYPE##_class()), \
helper.to_string(clazz))); \
} \
break; \
}
INSTANCE_OF_TYPE(TYPE_BOOLEAN, uint8_t)
INSTANCE_OF_TYPE(TYPE_TINYINT, int8_t)
Expand All @@ -248,7 +253,10 @@ Status check_type_matched(MethodTypeDescriptor method_type_desc, jobject val) {
case TYPE_VARCHAR: {
std::string buffer;
if (!env->IsInstanceOf(val, helper.string_clazz())) {
return Status::InternalError("Type not matched");
auto clazz = env->GetObjectClass(val);
LOCAL_REF_GUARD(clazz);
return Status::InternalError(
fmt::format("Type not matched, expect string, but got {}", helper.to_string(clazz)));
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion test/sql/test_udf/R/test_jvm_udf
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ select count(udtfstring) from t0, udtfstring(c1);
-- !result
select count(udtfstring_wrong_match) from t0, udtfstring_wrong_match(c1);
-- result:
E: (1064, 'Type not matched')
E: (1064, 'Type not matched, expect class java.lang.Integer, but got class java.lang.String')
-- !result
select count(udtfint) from t0, udtfint(c1);
-- result:
Expand Down

0 comments on commit 381bdf3

Please sign in to comment.