Skip to content

Commit b3d2ff7

Browse files
committed
add bit_and,bit_or,bit_xor,bool_add,bool_or
1 parent b4d383b commit b3d2ff7

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

datafusion/tests/test_aggregation.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ def df():
3333
pa.array([1, 2, 3]),
3434
pa.array([4, 4, 6]),
3535
pa.array([9, 8, 5]),
36+
pa.array([True, True, False]),
3637
],
37-
names=["a", "b", "c"],
38+
names=["a", "b", "c", "d"],
3839
)
3940
return ctx.create_dataframe([[batch]])
4041

@@ -125,3 +126,36 @@ def test_built_in_aggregation(df):
125126
np.testing.assert_array_almost_equal(
126127
result.column(21), np.var(values_c, ddof=1)
127128
)
129+
130+
131+
def test_bit_add_or_xor(df):
132+
133+
df = df.aggregate(
134+
[],
135+
[
136+
f.bit_and(column("a")),
137+
f.bit_or(column("b")),
138+
f.bit_xor(column("c")),
139+
],
140+
)
141+
142+
result = df.collect()
143+
result = result[0]
144+
assert result.column(0) == pa.array([0])
145+
assert result.column(1) == pa.array([6])
146+
assert result.column(2) == pa.array([4])
147+
148+
149+
def test_bool_and_or(df):
150+
151+
df = df.aggregate(
152+
[],
153+
[
154+
f.bool_and(column("d")),
155+
f.bool_or(column("d")),
156+
],
157+
)
158+
result = df.collect()
159+
result = result[0]
160+
assert result.column(0) == pa.array([False])
161+
assert result.column(1) == pa.array([True])

src/functions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ aggregate_function!(stddev_samp, Stddev);
357357
aggregate_function!(var, Variance);
358358
aggregate_function!(var_pop, VariancePop);
359359
aggregate_function!(var_samp, Variance);
360+
aggregate_function!(bit_and, BitAnd);
361+
aggregate_function!(bit_or, BitOr);
362+
aggregate_function!(bit_xor, BitXor);
363+
aggregate_function!(bool_and, BoolAnd);
364+
aggregate_function!(bool_or, BoolOr);
360365

361366
pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
362367
m.add_wrapped(wrap_pyfunction!(abs))?;
@@ -482,5 +487,10 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
482487
m.add_wrapped(wrap_pyfunction!(var_pop))?;
483488
m.add_wrapped(wrap_pyfunction!(var_samp))?;
484489
m.add_wrapped(wrap_pyfunction!(window))?;
490+
m.add_wrapped(wrap_pyfunction!(bit_and))?;
491+
m.add_wrapped(wrap_pyfunction!(bit_or))?;
492+
m.add_wrapped(wrap_pyfunction!(bit_xor))?;
493+
m.add_wrapped(wrap_pyfunction!(bool_and))?;
494+
m.add_wrapped(wrap_pyfunction!(bool_or))?;
485495
Ok(())
486496
}

0 commit comments

Comments
 (0)