adamreeve commented on code in PR #55425:
URL: https://github.com/apache/arrow/pull/55425#discussion_r4675369300
##########
cpp/src/arrow/util/binary_view_util.h:
##########
@@ -98,6 +98,45 @@ bool EqualBinaryView(BinaryViewType::c_type l,
BinaryViewType::c_type r,
l.size() - BinaryViewType::kPrefixSize) == 0;
}
+/// \brief Compare a BinaryView value with contiguous string data.
+///
+/// Performs prefix-accelerated early rejection by checking string length and
the
+/// 4-byte inline prefix before dereferencing variadic buffers.
+template <typename BufferPtr>
+bool EqualBinaryViewString(BinaryViewType::c_type v, const uint8_t* str_data,
+ int64_t str_len, const BufferPtr* v_buffers) {
+ if (v.size() != str_len) return false;
+ if (v.size() == 0) return true;
+
+ if (v.size() < BinaryViewType::kPrefixSize) {
+ return memcmp(v.inline_data(), str_data, v.size()) == 0;
+ }
+
+ uint32_t v_prefix, str_prefix;
Review Comment:
There's an implicit assumption here that `BinaryViewType::kPrefixSize ==
sizeof(uint32_t)`. I think it's worth making this explicit to help improve the
code readability, with a `static_assert(BinaryViewType::kPrefixSize ==
sizeof(uint32_t))`
##########
cpp/src/arrow/compute/kernels/scalar_compare.cc:
##########
@@ -380,6 +381,232 @@ struct VarArgsCompareFunction : ScalarFunction {
}
};
+// Shared equality comparison between a BinaryView array and any
BaseBinaryScalar.
+// Pins scalar length and 4-byte prefix in registers for early rejection before
+// dereferencing view variadic buffers.
+template <typename Op>
+Status ViewArrayCompareBinaryScalarEqual(KernelContext* ctx, const ArraySpan&
arg0,
+ const Scalar& arg1, ExecResult* out) {
+ constexpr bool kIsEqual = std::is_same_v<Op, Equal>;
+ if (!arg1.is_valid) {
+ return applicator::OutputAdapter<BooleanType>::Write(ctx,
out->array_span_mutable(),
+ []() -> bool { return
false; });
+ }
+ const auto& scalar = checked_cast<const BaseBinaryScalar&>(arg1);
+ std::string_view s = scalar.view();
+
+ if (ARROW_PREDICT_FALSE(s.size() >
+
static_cast<size_t>(std::numeric_limits<int32_t>::max()))) {
+ return applicator::OutputAdapter<BooleanType>::Write(
+ ctx, out->array_span_mutable(), [&]() -> bool { return !kIsEqual; });
+ }
+
+ const auto* views0 = arg0.GetValues<BinaryViewType::c_type>(1);
+ const auto* buffers0 = arg0.GetVariadicBuffers().data();
+ BinaryViewType::c_type s_val = util::ToBinaryView(s, 0, 0);
+ const uint8_t* s_data = reinterpret_cast<const uint8_t*>(s.data());
+ int32_t s_len = s_val.size();
+
+ int64_t s_sp;
Review Comment:
It's a little hard to read some of the functions in this file due to the
short variable names, eg. I'm not sure what `s_sp` means exactly. Could you
please use more descriptive variable names?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]