Skip to content

Commit

Permalink
ARROW-36420
Browse files Browse the repository at this point in the history
  • Loading branch information
R-JunmingChen committed Aug 18, 2023
1 parent b79a4dc commit 5be997c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
29 changes: 26 additions & 3 deletions cpp/src/arrow/compute/api_scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ struct EnumTraits<compute::MapLookupOptions::Occurrence>
}
};

template <>
struct EnumTraits<compute::SetLookupOptions::NullMatchingBehavior>
: BasicEnumTraits<compute::SetLookupOptions::NullMatchingBehavior,
compute::SetLookupOptions::NullMatchingBehavior::MATCH,
compute::SetLookupOptions::NullMatchingBehavior::SKIP,
compute::SetLookupOptions::NullMatchingBehavior::EMIT_NULL,
compute::SetLookupOptions::NullMatchingBehavior::INCONCLUSIVE> {
static std::string name() { return "SetLookupOptions::NullMatchingBehavior"; }
static std::string value_name(compute::SetLookupOptions::NullMatchingBehavior value) {
switch (value) {
case compute::SetLookupOptions::NullMatchingBehavior::MATCH:
return "MATCH";
case compute::SetLookupOptions::NullMatchingBehavior::SKIP:
return "SKIP";
case compute::SetLookupOptions::NullMatchingBehavior::EMIT_NULL:
return "EMIT_NULL";
case compute::SetLookupOptions::NullMatchingBehavior::INCONCLUSIVE:
return "INCONCLUSIVE";
}
return "<INVALID>";
}
};

} // namespace internal

namespace compute {
Expand Down Expand Up @@ -555,13 +578,13 @@ SetLookupOptions::SetLookupOptions(
null_matching_behavior(std::move(null_matching_behavior)) {}
SetLookupOptions::SetLookupOptions()
: SetLookupOptions({}, SetLookupOptions::NullMatchingBehavior::MATCH) {}
SetLookupOptions::NullMatchingBehavior SetLookupOptions::getNullMatchingBehavior() {
SetLookupOptions::NullMatchingBehavior SetLookupOptions::getNullMatchingBehavior() const {
if (this->skip_nulls == std::nullopt) {
return this->null_matching_behavior;
} else if (this->skip_nulls) {
return SetLookupOptions::NullMatchingBehavior::SKIP;
return SetLookupOptions::SKIP;
} else {
return SetLookupOptions::NullMatchingBehavior::MATCH;
return SetLookupOptions::MATCH;
}
}
constexpr char SetLookupOptions::kTypeName[];
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/arrow/compute/api_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,18 @@ class ARROW_EXPORT SetLookupOptions : public FunctionOptions {
enum NullMatchingBehavior { MATCH, SKIP, EMIT_NULL, INCONCLUSIVE };

explicit SetLookupOptions(Datum value_set, NullMatchingBehavior = MATCH);
explicit SetLookupOptions(Datum value_set, bool skip_nulls); SetLookupOptions();
explicit SetLookupOptions(Datum value_set, bool skip_nulls);
SetLookupOptions();
static constexpr char const kTypeName[] = "SetLookupOptions";

/// The set of values to look up input values into.
Datum value_set;

NullMatchingBehavior null_matching_behavior;

// DEPRECATED(will be removed after removing of skip_nulls)
NullMatchingBehavior const getNullMatchingBehavior();
NullMatchingBehavior getNullMatchingBehavior() const;

// DEPRECATED(use null_matching_behavior instead)
/// Whether nulls in `value_set` count for lookup.
///
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/arrow/compute/kernels/scalar_set_lookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ struct IndexInVisitor {
const auto& state = checked_cast<const SetLookupState<NullType>&>(*ctx->state());

if (data.length != 0) {
// skip_nulls is honored for consistency with other types
bit_util::SetBitsTo(out_bitmap, out->offset, out->length, state.value_set_has_null);
bit_util::SetBitsTo(out_bitmap, out->offset, out->length,
state.null_matching_behavior == SetLookupOptions::MATCH &&
state.value_set_has_null);

// Set all values to 0, which will be unmasked only if null is in the value_set
// and null_matching_behavior is equal to MATCH
std::memset(out->GetValues<int32_t>(1), 0x00, out->length * sizeof(int32_t));
}
return Status::OK();
Expand Down Expand Up @@ -311,7 +313,8 @@ struct IndexInVisitor {
bitmap_writer.Next();
},
[&]() {
if (state.null_index != -1) {
if (state.null_index != -1 &&
state.null_matching_behavior == SetLookupOptions::MATCH) {
bitmap_writer.Set();

// value_set included null
Expand Down

0 comments on commit 5be997c

Please sign in to comment.