Skip to content

Commit eb53593

Browse files
committed
Update count and count_star to use macro for exposing
1 parent db854db commit eb53593

File tree

2 files changed

+2
-21
lines changed

2 files changed

+2
-21
lines changed

python/datafusion/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def col(name: str) -> Expr:
372372

373373
def count_star() -> Expr:
374374
"""Create a COUNT(1) aggregate expression."""
375-
return Expr(f.count_star())
375+
return Expr(f.count(Expr.literal(1)))
376376

377377

378378
def case(expr: Expr) -> CaseBuilder:

src/functions.rs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -432,25 +432,6 @@ fn col(name: &str) -> PyResult<PyExpr> {
432432
})
433433
}
434434

435-
// TODO: should we just expose this in python?
436-
/// Create a COUNT(1) aggregate expression
437-
#[pyfunction]
438-
fn count_star() -> PyExpr {
439-
functions_aggregate::expr_fn::count(lit(1)).into()
440-
}
441-
442-
/// Wrapper for [`functions_aggregate::expr_fn::count`]
443-
/// Count the number of non-null values in the column
444-
#[pyfunction]
445-
fn count(expr: PyExpr, distinct: bool) -> PyResult<PyExpr> {
446-
let expr = functions_aggregate::expr_fn::count(expr.expr);
447-
if distinct {
448-
Ok(expr.distinct().build()?.into())
449-
} else {
450-
Ok(expr.into())
451-
}
452-
}
453-
454435
/// Create a CASE WHEN statement with literal WHEN expressions for comparison to the base expression.
455436
#[pyfunction]
456437
fn case(expr: PyExpr) -> PyResult<PyCaseBuilder> {
@@ -830,6 +811,7 @@ aggregate_function!(bit_xor);
830811
aggregate_function!(bool_and);
831812
aggregate_function!(bool_or);
832813
aggregate_function!(corr, y x);
814+
aggregate_function!(count);
833815

834816
fn add_builder_fns_to_window(
835817
window_fn: Expr,
@@ -978,7 +960,6 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
978960
m.add_wrapped(wrap_pyfunction!(cosh))?;
979961
m.add_wrapped(wrap_pyfunction!(cot))?;
980962
m.add_wrapped(wrap_pyfunction!(count))?;
981-
m.add_wrapped(wrap_pyfunction!(count_star))?;
982963
m.add_wrapped(wrap_pyfunction!(covar_pop))?;
983964
m.add_wrapped(wrap_pyfunction!(covar_samp))?;
984965
m.add_wrapped(wrap_pyfunction!(current_date))?;

0 commit comments

Comments
 (0)