8000 add first_value last_value (#498) · llama90/arrow-datafusion-python@a91188c · GitHub
[go: up one dir, main page]

Skip to content

Commit a91188c

Browse files
jiangzhxandygrove
andauthored
add first_value last_value (apache#498)
Co-authored-by: Andy Grove <andygrove73@gmail.com>
1 parent 804d0eb commit a91188c

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

datafusion/tests/test_functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,29 @@ def test_case(df):
479479
assert result.column(2) == pa.array(["Hola", "Mundo", None])
480480

481481

482+
def test_first_last_value(df):
483+
df = df.aggregate(
484+
[],
485+
[
486+
f.first_value(column("a")),
487+
f.first_value(column("b")),
488+
f.first_value(column("d")),
489+
f.last_value(column("a")),
490+
f.last_value(column("b")),
491+
f.last_value(column("d")),
492+
],
493+
)
494+
495+
result = df.collect()
496+
result = result[0]
497+
assert result.column(0) == pa.array(["Hello"])
498+
assert result.column(1) == pa.array([4])
499+
assert result.column(2) == pa.array([datetime(2022, 12, 31)])
500+
assert result.column(3) == pa.array(["!"])
501+
assert result.column(4) == pa.array([6])
502+
assert result.column(5) == pa.array([datetime(2020, 7, 2)])
503+
504+
482505
def test_binary_string_functions(df):
483506
df = df.select(
484507
f.encode(column("a"), literal("base64")),

src/functions.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ aggregate_function!(stddev_samp, Stddev);
362362
aggregate_function!(var, Variance);
363363
aggregate_function!(var_pop, VariancePop);
364364
aggregate_function!(var_samp, Variance);
365+
aggregate_function!(first_value, FirstValue);
366+
aggregate_function!(last_value, LastValue);
365367
aggregate_function!(bit_and, BitAnd);
366368
aggregate_function!(bit_or, BitOr);
367369
aggregate_function!(bit_xor, BitXor);
@@ -494,6 +496,8 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
494496
m.add_wrapped(wrap_pyfunction!(var_pop))?;
495497
m.add_wrapped(wrap_pyfunction!(var_samp))?;
496498
m.add_wrapped(wrap_pyfunction!(window))?;
499+
m.add_wrapped(wrap_pyfunction!(first_value))?;
500+
m.add_wrapped(wrap_pyfunction!(last_value))?;
497501
m.add_wrapped(wrap_pyfunction!(bit_and))?;
498502
m.add_wrapped(wrap_pyfunction!(bit_or))?;
499503
m.add_wrapped(wrap_pyfunction!(bit_xor))?;

0 commit comments

Comments
 (0)
0