Skip to content

Commit d027c95

Browse files
committed
apacheGH-29839: [C++][Python][R] Rename binary set lookup functions
1 parent 4375193 commit d027c95

8 files changed

Lines changed: 86 additions & 38 deletions

File tree

‎cpp/src/arrow/compute/kernels/scalar_set_lookup.cc‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ const FunctionDoc is_in_doc{
579579
"SetLookupOptions",
580580
/*options_required=*/true};
581581

582-
const FunctionDoc is_in_meta_doc{
582+
const FunctionDoc is_in_binary_doc{
583583
"Find each element in a set of values",
584584
("For each element in `values`, return true if it is found in `value_set`,\n"
585585
"false otherwise."),
@@ -596,38 +596,38 @@ const FunctionDoc index_in_doc{
596596
"SetLookupOptions",
597597
/*options_required=*/true};
598598

599-
const FunctionDoc index_in_meta_doc{
599+
const FunctionDoc index_in_binary_doc{
600600
"Return index of each element in a set of values",
601601
("For each element in `values`, return its index in the `value_set`,\n"
602602
"or null if it is not found there."),
603603
{"values", "value_set"}};
604604

605605
// Enables calling is_in with CallFunction as though it were binary.
606-
class IsInMetaBinary : public MetaFunction {
606+
class IsInBinary : public MetaFunction {
607607
public:
608-
IsInMetaBinary() : MetaFunction("is_in_meta_binary", Arity::Binary(), is_in_meta_doc) {}
608+
IsInBinary() : MetaFunction("is_in_binary", Arity::Binary(), is_in_binary_doc) {}
609609

610610
Result<Datum> ExecuteImpl(const std::vector<Datum>& args,
611611
const FunctionOptions* options,
612612
ExecContext* ctx) const override {
613613
if (options != nullptr) {
614-
return Status::Invalid("Unexpected options for 'is_in_meta_binary' function");
614+
return Status::Invalid("Unexpected options for 'is_in_binary' function");
615615
}
616616
return IsIn(args[0], args[1], ctx);
617617
}
618618
};
619619

620620
// Enables calling index_in with CallFunction as though it were binary.
621-
class IndexInMetaBinary : public MetaFunction {
621+
class IndexInBinary : public MetaFunction {
622622
public:
623-
IndexInMetaBinary()
624-
: MetaFunction("index_in_meta_binary", Arity::Binary(), index_in_meta_doc) {}
623+
IndexInBinary()
624+
: MetaFunction("index_in_binary", Arity::Binary(), index_in_binary_doc) {}
625625

626626
Result<Datum> ExecuteImpl(const std::vector<Datum>& args,
627627
const FunctionOptions* options,
628628
ExecContext* ctx) const override {
629629
if (options != nullptr) {
630-
return Status::Invalid("Unexpected options for 'index_in_meta_binary' function");
630+
return Status::Invalid("Unexpected options for 'index_in_binary' function");
631631
}
632632
return IndexIn(args[0], args[1], ctx);
633633
}
@@ -659,7 +659,8 @@ void RegisterScalarSetLookup(FunctionRegistry* registry) {
659659
DCHECK_OK(is_in->AddKernel(isin_base));
660660
DCHECK_OK(registry->AddFunction(is_in));
661661

662-
DCHECK_OK(registry->AddFunction(std::make_shared<IsInMetaBinary>()));
662+
DCHECK_OK(registry->AddFunction(std::make_shared<IsInBinary>()));
663+
DCHECK_OK(registry->AddAlias("is_in_meta_binary", "is_in_binary"));
663664
}
664665

665666
// IndexIn writes its int32 output into preallocated memory
@@ -677,7 +678,8 @@ void RegisterScalarSetLookup(FunctionRegistry* registry) {
677678
DCHECK_OK(index_in->AddKernel(index_in_base));
678679
DCHECK_OK(registry->AddFunction(index_in));
679680

680-
DCHECK_OK(registry->AddFunction(std::make_shared<IndexInMetaBinary>()));
681+
DCHECK_OK(registry->AddFunction(std::make_shared<IndexInBinary>()));
682+
DCHECK_OK(registry->AddAlias("index_in_meta_binary", "index_in_binary"));
681683
}
682684
}
683685

‎cpp/src/arrow/compute/kernels/scalar_set_lookup_benchmark.cc‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,71 +76,71 @@ static void SetLookupBenchmarkNumeric(benchmark::State& state,
7676
}
7777

7878
static void IndexInStringSmallSet(benchmark::State& state) {
79-
SetLookupBenchmarkString(state, "index_in_meta_binary", state.range(0));
79+
SetLookupBenchmarkString(state, "index_in_binary", state.range(0));
8080
}
8181

8282
static void IsInStringSmallSet(benchmark::State& state) {
83-
SetLookupBenchmarkString(state, "is_in_meta_binary", state.range(0));
83+
SetLookupBenchmarkString(state, "is_in_binary", state.range(0));
8484
}
8585

8686
static void IndexInStringLargeSet(benchmark::State& state) {
87-
SetLookupBenchmarkString(state, "index_in_meta_binary", 1 << 10);
87+
SetLookupBenchmarkString(state, "index_in_binary", 1 << 10);
8888
}
8989

9090
static void IsInStringLargeSet(benchmark::State& state) {
91-
SetLookupBenchmarkString(state, "is_in_meta_binary", 1 << 10);
91+
SetLookupBenchmarkString(state, "is_in_binary", 1 << 10);
9292
}
9393

9494
static constexpr int64_t kArrayLengthWithSmallSet = 1 << 18;
9595
static constexpr int64_t kArrayLengthWithLargeSet = 1000;
9696

9797
static void IndexInInt8SmallSet(benchmark::State& state) {
98-
SetLookupBenchmarkNumeric<Int8Type>(state, "index_in_meta_binary", state.range(0),
98+
SetLookupBenchmarkNumeric<Int8Type>(state, "index_in_binary", state.range(0),
9999
kArrayLengthWithSmallSet);
100100
}
101101

102102
static void IndexInInt16SmallSet(benchmark::State& state) {
103-
SetLookupBenchmarkNumeric<Int16Type>(state, "index_in_meta_binary", state.range(0),
103+
SetLookupBenchmarkNumeric<Int16Type>(state, "index_in_binary", state.range(0),
104104
kArrayLengthWithSmallSet);
105105
}
106106

107107
static void IndexInInt32SmallSet(benchmark::State& state) {
108-
SetLookupBenchmarkNumeric<Int32Type>(state, "index_in_meta_binary", state.range(0),
108+
SetLookupBenchmarkNumeric<Int32Type>(state, "index_in_binary", state.range(0),
109109
kArrayLengthWithSmallSet);
110110
}
111111

112112
static void IndexInInt64SmallSet(benchmark::State& state) {
113-
SetLookupBenchmarkNumeric<Int64Type>(state, "index_in_meta_binary", state.range(0),
113+
SetLookupBenchmarkNumeric<Int64Type>(state, "index_in_binary", state.range(0),
114114
kArrayLengthWithSmallSet);
115115
}
116116

117117
static void IndexInInt32LargeSet(benchmark::State& state) {
118-
SetLookupBenchmarkNumeric<Int32Type>(state, "index_in_meta_binary", state.range(0),
118+
SetLookupBenchmarkNumeric<Int32Type>(state, "index_in_binary", state.range(0),
119119
kArrayLengthWithLargeSet);
120120
}
121121

122122
static void IsInInt8SmallSet(benchmark::State& state) {
123-
SetLookupBenchmarkNumeric<Int8Type>(state, "is_in_meta_binary", state.range(0),
123+
SetLookupBenchmarkNumeric<Int8Type>(state, "is_in_binary", state.range(0),
124124
kArrayLengthWithSmallSet);
125125
}
126126

127127
static void IsInInt16SmallSet(benchmark::State& state) {
128-
SetLookupBenchmarkNumeric<Int16Type>(state, "is_in_meta_binary", state.range(0),
128+
SetLookupBenchmarkNumeric<Int16Type>(state, "is_in_binary", state.range(0),
129129
kArrayLengthWithSmallSet);
130130
}
131131

132132
static void IsInInt32SmallSet(benchmark::State& state) {
133-
SetLookupBenchmarkNumeric<Int32Type>(state, "is_in_meta_binary", state.range(0),
133+
SetLookupBenchmarkNumeric<Int32Type>(state, "is_in_binary", state.range(0),
134134
kArrayLengthWithSmallSet);
135135
}
136136

137137
static void IsInInt64SmallSet(benchmark::State& state) {
138-
SetLookupBenchmarkNumeric<Int64Type>(state, "is_in_meta_binary", state.range(0),
138+
SetLookupBenchmarkNumeric<Int64Type>(state, "is_in_binary", state.range(0),
139139
kArrayLengthWithSmallSet);
140140
}
141141

142142
static void IsInInt32LargeSet(benchmark::State& state) {
143-
SetLookupBenchmarkNumeric<Int32Type>(state, "is_in_meta_binary", state.range(0),
143+
SetLookupBenchmarkNumeric<Int32Type>(state, "is_in_binary", state.range(0),
144144
kArrayLengthWithLargeSet);
145145
}
146146

‎cpp/src/arrow/compute/kernels/scalar_set_lookup_test.cc‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ TEST_F(TestIsInKernel, CallBinary) {
169169
auto value_set = ArrayFromJSON(int8(), "[2, 3, 5, 7]");
170170
ASSERT_RAISES(Invalid, CallFunction("is_in", {input, value_set}));
171171

172-
ASSERT_OK_AND_ASSIGN(Datum out, CallFunction("is_in_meta_binary", {input, value_set}));
173172
auto expected = ArrayFromJSON(boolean(), ("[false, false, true, true, false,"
174173
"true, false, true, false]"));
175-
AssertArraysEqual(*expected, *out.make_array());
174+
for (const std::string& function_name : {"is_in_binary", "is_in_meta_binary"}) {
175+
SCOPED_TRACE(function_name);
176+
ASSERT_OK_AND_ASSIGN(Datum out, CallFunction(function_name, {input, value_set}));
177+
AssertArraysEqual(*expected, *out.make_array());
178+
}
176179
}
177180

178181
TEST_F(TestIsInKernel, ImplicitlyCastValueSet) {
@@ -1127,11 +1130,13 @@ TEST_F(TestIndexInKernel, CallBinary) {
11271130
auto value_set = ArrayFromJSON(int8(), "[2, 3, 5, 7]");
11281131
ASSERT_RAISES(Invalid, CallFunction("index_in", {input, value_set}));
11291132

1130-
ASSERT_OK_AND_ASSIGN(Datum out,
1131-
CallFunction("index_in_meta_binary", {input, value_set}));
11321133
auto expected = ArrayFromJSON(int32(), ("[null, null, 0, 1, null, 2, null, 3, null,"
11331134
" null, null]"));
1134-
AssertArraysEqual(*expected, *out.make_array());
1135+
for (const std::string& function_name : {"index_in_binary", "index_in_meta_binary"}) {
1136+
SCOPED_TRACE(function_name);
1137+
ASSERT_OK_AND_ASSIGN(Datum out, CallFunction(function_name, {input, value_set}));
1138+
AssertArraysEqual(*expected, *out.make_array());
1139+
}
11351140
}
11361141

11371142
template <typename Type>

‎docs/source/cpp/compute.rst‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,15 @@ Containment tests
12371237
| index_in | Unary | Boolean, Null, Numeric, Temporal, | Int32 | :struct:`SetLookupOptions` | \(4) |
12381238
| | | Binary- and String-like | | | |
12391239
+-----------------------+-------+-----------------------------------+----------------+---------------------------------+-------+
1240+
| index_in_binary | Binary| Boolean, Null, Numeric, Temporal, | Int32 | | \(4) |
1241+
| | | Binary- and String-like | | | |
1242+
+-----------------------+-------+-----------------------------------+----------------+---------------------------------+-------+
12401243
| is_in | Unary | Boolean, Null, Numeric, Temporal, | Boolean | :struct:`SetLookupOptions` | \(5) |
12411244
| | | Binary- and String-like | | | |
12421245
+-----------------------+-------+-----------------------------------+----------------+---------------------------------+-------+
1246+
| is_in_binary | Binary| Boolean, Null, Numeric, Temporal, | Boolean | | \(5) |
1247+
| | | Binary- and String-like | | | |
1248+
+-----------------------+-------+-----------------------------------+----------------+---------------------------------+-------+
12431249
| match_like | Unary | Binary- or String-like | Boolean | :struct:`MatchSubstringOptions` | \(6) |
12441250
+-----------------------+-------+-----------------------------------+----------------+---------------------------------+-------+
12451251
| match_substring | Unary | Binary- or String-like | Boolean | :struct:`MatchSubstringOptions` | \(7) |
@@ -1262,12 +1268,15 @@ Containment tests
12621268
string, otherwise -1. Output type is Int32 for Binary/String, Int64
12631269
for LargeBinary/LargeString.
12641270

1265-
* \(4) Output is the index of the corresponding input element in
1266-
:member:`SetLookupOptions::value_set`, if found there. Otherwise,
1267-
output is null.
1271+
* \(4) Output is the index of the corresponding input element in the
1272+
value set, if found there. The value set is provided as the second input to
1273+
``index_in_binary`` or as :member:`SetLookupOptions::value_set` to
1274+
``index_in``. Otherwise, output is null.
12681275

12691276
* \(5) Output is true iff the corresponding input element is equal to one
1270-
of the elements in :member:`SetLookupOptions::value_set`.
1277+
of the elements in the value set. The value set is provided as the second
1278+
input to ``is_in_binary`` or as :member:`SetLookupOptions::value_set` to
1279+
``is_in``.
12711280

12721281
* \(6) Output is true iff the SQL-style LIKE pattern
12731282
:member:`MatchSubstringOptions::pattern` fully matches the

‎docs/source/python/api/compute.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ Containment Tests
399399
find_substring
400400
find_substring_regex
401401
index_in
402+
index_in_binary
402403
is_in
404+
is_in_binary
403405
match_like
404406
match_substring
405407
match_substring_regex

‎python/pyarrow/tests/test_compute.py‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ def test_pickle_global_functions(pickle_module):
320320

321321
def test_function_attributes():
322322
# Sanity check attributes of registered functions
323+
aliases = {
324+
"index_in_meta_binary": "index_in_binary",
325+
"is_in_meta_binary": "is_in_binary",
326+
}
323327
for name in pc.list_functions():
324328
func = pc.get_function(name)
325329
assert isinstance(func, pc.Function)
326-
assert func.name == name
330+
assert func.name == aliases.get(name, name)
327331
kernels = func.kernels
328332
assert func.num_kernels == len(kernels)
329333
assert all(isinstance(ker, pc.Kernel) for ker in kernels)
@@ -3340,6 +3344,19 @@ def test_is_in():
33403344
assert result.to_pylist() == [True, False, False, True, False, True]
33413345

33423346

3347+
@pytest.mark.parametrize("function_name", [
3348+
"is_in_binary",
3349+
"is_in_meta_binary",
3350+
])
3351+
def test_is_in_binary(function_name):
3352+
values = pa.array([1, 2, None, 3])
3353+
value_set = pa.array([1, 3, None])
3354+
3355+
result = getattr(pc, function_name)(values, value_set)
3356+
3357+
assert result.to_pylist() == [True, False, True, True]
3358+
3359+
33433360
def test_index_in():
33443361
arr = pa.array([1, 2, None, 1, 2, 3])
33453362

@@ -3361,6 +3378,19 @@ def test_index_in():
33613378
assert result.to_pylist() == [0, None, None, 0, None, 1]
33623379

33633380

3381+
@pytest.mark.parametrize("function_name", [
3382+
"index_in_binary",
3383+
"index_in_meta_binary",
3384+
])
3385+
def test_index_in_binary(function_name):
3386+
values = pa.array([1, 2, None, 3])
3387+
value_set = pa.array([1, 3, None])
3388+
3389+
result = getattr(pc, function_name)(values, value_set)
3390+
3391+
assert result.to_pylist() == [0, None, 2, 1]
3392+
3393+
33643394
def test_quantile():
33653395
arr = pa.array([1, 2, 3, 4])
33663396

‎r/R/compute.R‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ match_arrow <- function(x, table, ...) {
268268
if (!inherits(table, c("Array", "ChunkedArray"))) {
269269
table <- Array$create(table)
270270
}
271-
call_function("index_in_meta_binary", x, table)
271+
call_function("index_in_binary", x, table)
272272
}
273273

274274
#' @rdname match_arrow
@@ -281,7 +281,7 @@ is_in <- function(x, table, ...) {
281281
if (!inherits(table, c("Array", "DictionaryArray", "ChunkedArray"))) {
282282
table <- Array$create(table)
283283
}
284-
call_function("is_in_meta_binary", x, table)
284+
call_function("is_in_binary", x, table)
285285
}
286286

287287
#' `table` for Arrow objects

‎r/R/dplyr-funcs-conditional.R‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ parse_value_mapping <- function(x, formulas = list(), from = NULL, to = NULL, ma
180180

181181
register_bindings_conditional <- function() {
182182
register_binding("%in%", function(x, table) {
183-
# We use `is_in` here, unlike with Arrays, which use `is_in_meta_binary`
183+
# We use `is_in` here, unlike with Arrays, which use `is_in_binary`
184184
value_set <- Array$create(table)
185185
# If possible, `table` should be the same type as `x`
186186
# Try downcasting here; otherwise Acero may upcast x to table's type

0 commit comments

Comments
 (0)