Skip to content

Commit

Permalink
isin init
Browse files Browse the repository at this point in the history
  • Loading branch information
R-JunmingChen committed Aug 18, 2023
1 parent 60bbb14 commit b79a4dc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 207 deletions.
36 changes: 25 additions & 11 deletions cpp/src/arrow/compute/api_scalar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ static auto kRoundToMultipleOptionsType = GetFunctionOptionsType<RoundToMultiple
DataMember("round_mode", &RoundToMultipleOptions::round_mode));
static auto kSetLookupOptionsType = GetFunctionOptionsType<SetLookupOptions>(
DataMember("value_set", &SetLookupOptions::value_set),
DataMember("skip_nulls", &SetLookupOptions::skip_nulls));
DataMember("skip_nulls", &SetLookupOptions::skip_nulls),
DataMember("null_matching_behavior", &SetLookupOptions::null_matching_behavior));
static auto kSliceOptionsType = GetFunctionOptionsType<SliceOptions>(
DataMember("start", &SliceOptions::start), DataMember("stop", &SliceOptions::stop),
DataMember("step", &SliceOptions::step));
Expand Down Expand Up @@ -540,8 +541,29 @@ constexpr char RoundToMultipleOptions::kTypeName[];
SetLookupOptions::SetLookupOptions(Datum value_set, bool skip_nulls)
: FunctionOptions(internal::kSetLookupOptionsType),
value_set(std::move(value_set)),
skip_nulls(skip_nulls) {}
SetLookupOptions::SetLookupOptions() : SetLookupOptions({}, false) {}
skip_nulls(skip_nulls) {
if (skip_nulls) {
this->null_matching_behavior = SetLookupOptions::NullMatchingBehavior::SKIP;
} else {
this->null_matching_behavior = SetLookupOptions::NullMatchingBehavior::MATCH;
}
}
SetLookupOptions::SetLookupOptions(
Datum value_set, SetLookupOptions::NullMatchingBehavior null_matching_behavior)
: FunctionOptions(internal::kSetLookupOptionsType),
value_set(std::move(value_set)),
null_matching_behavior(std::move(null_matching_behavior)) {}
SetLookupOptions::SetLookupOptions()
: SetLookupOptions({}, SetLookupOptions::NullMatchingBehavior::MATCH) {}
SetLookupOptions::NullMatchingBehavior SetLookupOptions::getNullMatchingBehavior() {
if (this->skip_nulls == std::nullopt) {
return this->null_matching_behavior;
} else if (this->skip_nulls) {
return SetLookupOptions::NullMatchingBehavior::SKIP;
} else {
return SetLookupOptions::NullMatchingBehavior::MATCH;
}
}
constexpr char SetLookupOptions::kTypeName[];

SliceOptions::SliceOptions(int64_t start, int64_t stop, int64_t step)
Expand Down Expand Up @@ -745,14 +767,6 @@ Result<Datum> MinElementWise(const std::vector<Datum>& args,
// ----------------------------------------------------------------------
// Set-related operations

Result<Datum> In(const Datum& values, const SetLookupOptions& options, ExecContext* ctx) {
return CallFunction("in", {values}, &options, ctx);
}

Result<Datum> In(const Datum& values, const Datum& value_set, ExecContext* ctx) {
return In(values, SetLookupOptions{value_set}, ctx);
}

Result<Datum> IsIn(const Datum& values, const SetLookupOptions& options,
ExecContext* ctx) {
return CallFunction("is_in", {values}, &options, ctx);
Expand Down
37 changes: 12 additions & 25 deletions cpp/src/arrow/compute/api_scalar.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,28 @@ class ARROW_EXPORT ExtractRegexOptions : public FunctionOptions {
/// Options for IsIn and IndexIn functions
class ARROW_EXPORT SetLookupOptions : public FunctionOptions {
public:
explicit SetLookupOptions(Datum value_set, bool skip_nulls = false);
SetLookupOptions();
enum NullMatchingBehavior { MATCH, SKIP, EMIT_NULL, INCONCLUSIVE };

explicit SetLookupOptions(Datum value_set, NullMatchingBehavior = MATCH);
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();

// DEPRECATED(use null_matching_behavior instead)
/// Whether nulls in `value_set` count for lookup.
///
/// If true, any null in `value_set` is ignored and nulls in the input
/// produce null (IndexIn) or false (IsIn) values in the output.
/// If false, any null in `value_set` is successfully matched in
/// the input.
bool skip_nulls;
std::optional<bool> skip_nulls;
};

/// Options for struct_field function
Expand Down Expand Up @@ -1089,28 +1098,6 @@ ARROW_EXPORT
Result<Datum> KleeneAndNot(const Datum& left, const Datum& right,
ExecContext* ctx = NULLPTR);

/// \brief In returns true for each element of `values` that is contained in
/// `value_set`.
/// In is sql-compatible, null in `values` will directly output null,
/// each elelement of `values` that isn't contained in `value_set`
/// will output null if the `value_set` contains null and output
/// false if the `value_set` doesn't contain null.
///
/// In ignore the parameter skip_nulls in SetLookupOptions.
///
/// \param[in] values array-like input to look up in value_set
/// \param[in] options SetLookupOptions
/// \param[in] ctx the function execution context, optional
/// \return the resulting datum
///
/// \since 12.0.1
/// \note API not yet finalized
ARROW_EXPORT
Result<Datum> In(const Datum& values, const SetLookupOptions& options,
ExecContext* ctx = NULLPTR);
ARROW_EXPORT
Result<Datum> In(const Datum& values, const Datum& value_set, ExecContext* ctx = NULLPTR);

/// \brief IsIn returns true for each element of `values` that is contained in
/// `value_set`
///
Expand Down
Loading

0 comments on commit b79a4dc

Please sign in to comment.