Skip to content

Commit

Permalink
ARROW-18019: [C++][Gandiva] Improve Projector evaluation performance (#…
Browse files Browse the repository at this point in the history
…14394)

1. Some dynamic_casts are not necessary because the safety is checked already.
2. RecordBatch's column(int i) function involves atomic operation and column_data(int i) doesn't. So we prefer to use column_data() instead if column()->data().

Authored-by: Jin Shang <shangjin1997@gmail.com>
Signed-off-by: Sutou Kouhei <kou@clear-code.com>
  • Loading branch information
js8544 committed Oct 17, 2022
1 parent 48b4828 commit 63e1756
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/src/gandiva/annotator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ EvalBatchPtr Annotator::PrepareEvalBatch(const arrow::RecordBatch& record_batch,
continue;
}

PrepareBuffersForField(*(found->second), *(record_batch.column(i))->data(),
PrepareBuffersForField(*(found->second), *(record_batch.column_data(i)),
eval_batch.get(), false /*is_output*/);
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/gandiva/projector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Status Projector::AllocArrayData(const DataTypePtr& type, int64_t num_records,
// The output vector always has a data array.
int64_t data_len;
if (arrow::is_primitive(type_id) || type_id == arrow::Type::DECIMAL) {
const auto& fw_type = dynamic_cast<const arrow::FixedWidthType&>(*type);
const auto& fw_type = static_cast<const arrow::FixedWidthType&>(*type);
data_len = arrow::bit_util::BytesForBits(num_records * fw_type.bit_width());
} else if (arrow::is_binary_like(type_id)) {
// we don't know the expected size for varlen output vectors.
Expand Down Expand Up @@ -267,7 +267,7 @@ Status Projector::ValidateArrayDataCapacity(const arrow::ArrayData& array_data,
Status::Invalid("data buffer for varlen output vectors must be resizable"));
} else if (arrow::is_primitive(type_id) || type_id == arrow::Type::DECIMAL) {
// verify size of data buffer.
const auto& fw_type = dynamic_cast<const arrow::FixedWidthType&>(*field.type());
const auto& fw_type = static_cast<const arrow::FixedWidthType&>(*field.type());
int64_t min_data_len =
arrow::bit_util::BytesForBits(num_records * fw_type.bit_width());
int64_t data_len = array_data.buffers[1]->capacity();
Expand Down

0 comments on commit 63e1756

Please sign in to comment.