Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions java/gandiva/src/main/cpp/jni_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include <arrow/builder.h>
#include <arrow/record_batch.h>
#include <arrow/status.h>
#include <arrow/type.h>
#include <gandiva/configuration.h>
#include <gandiva/decimal_scalar.h>
Expand Down Expand Up @@ -712,30 +713,18 @@ class JavaResizableBuffer : public arrow::ResizableBuffer {

Status Resize(const int64_t new_size, bool shrink_to_fit) override;

Status Reserve(const int64_t new_capacity) override {
return Status::NotImplemented("reserve not implemented");
}
Status Reserve(const int64_t new_capacity) override;

private:
JNIEnv* env_;
jobject jexpander_;
int32_t vector_idx_;
};

Status JavaResizableBuffer::Resize(const int64_t new_size, bool shrink_to_fit) {
if (shrink_to_fit == true) {
return Status::NotImplemented("shrink not implemented");
}

if (ARROW_PREDICT_TRUE(new_size < capacity())) {
// no need to expand.
size_ = new_size;
return Status::OK();
}

Status JavaResizableBuffer::Reserve(const int64_t new_capacity) {
// callback into java to expand the buffer
jobject ret =
env_->CallObjectMethod(jexpander_, vector_expander_method_, vector_idx_, new_size);
jobject ret = env_->CallObjectMethod(jexpander_, vector_expander_method_, vector_idx_,
new_capacity);
if (env_->ExceptionCheck()) {
env_->ExceptionDescribe();
env_->ExceptionClear();
Expand All @@ -744,14 +733,29 @@ Status JavaResizableBuffer::Resize(const int64_t new_size, bool shrink_to_fit) {

jlong ret_address = env_->GetLongField(ret, vector_expander_ret_address_);
jlong ret_capacity = env_->GetLongField(ret, vector_expander_ret_capacity_);
DCHECK_GE(ret_capacity, new_size);

data_ = reinterpret_cast<uint8_t*>(ret_address);
size_ = new_size;
capacity_ = ret_capacity;
return Status::OK();
}

Status JavaResizableBuffer::Resize(const int64_t new_size, bool shrink_to_fit) {
if (shrink_to_fit == true) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we don't need to implement this because it's not used currently?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not needed by gandiva

return Status::NotImplemented("shrink not implemented");
}

if (ARROW_PREDICT_TRUE(new_size <= capacity())) {
// no need to expand.
size_ = new_size;
return Status::OK();
}

RETURN_NOT_OK(Reserve(new_size));
DCHECK_GE(capacity_, new_size);
size_ = new_size;
return Status::OK();
}

#define CHECK_OUT_BUFFER_IDX_AND_BREAK(idx, len) \
if (idx >= len) { \
status = gandiva::Status::Invalid("insufficient number of out_buf_addrs"); \
Expand Down