Skip to content

Commit 8d16a3c

Browse files
committed
Update count and count_star to use macro for exposing
1 parent 9543626 commit 8d16a3c

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
@@ -367,7 +367,7 @@ def col(name: str) -> Expr:
367367

368368
def count_star() -> Expr:
369369
"""Create a COUNT(1) aggregate expression."""
370-
return Expr(f.count_star())
370+
return Expr(f.count(Expr.literal(1)))
371371

372372

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

src/functions.rs

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

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

835817
fn add_builder_fns_to_window(
836818
window_fn: Expr,
@@ -979,7 +961,6 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
979961
m.add_wrapped(wrap_pyfunction!(cosh))?;
980962
m.add_wrapped(wrap_pyfunction!(cot))?;
981963
m.add_wrapped(wrap_pyfunction!(count))?;
982-
m.add_wrapped(wrap_pyfunction!(count_star))?;
983964
m.add_wrapped(wrap_pyfunction!(covar_pop))?;
984965
m.add_wrapped(wrap_pyfunction!(covar_samp))?;
985966
m.add_wrapped(wrap_pyfunction!(current_date))?;

0 commit comments

Comments
 (0)