Skip to content

Commit

Permalink
Update count and count_star to use macro for exposing
Browse files Browse the repository at this point in the history
  • Loading branch information
timsaucer committed Sep 7, 2024
1 parent db854db commit eb53593
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
2 changes: 1 addition & 1 deletion python/datafusion/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ def col(name: str) -> Expr:

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


def case(expr: Expr) -> CaseBuilder:
Expand Down
21 changes: 1 addition & 20 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,25 +432,6 @@ fn col(name: &str) -> PyResult<PyExpr> {
})
}

// TODO: should we just expose this in python?
/// Create a COUNT(1) aggregate expression
#[pyfunction]
fn count_star() -> PyExpr {
functions_aggregate::expr_fn::count(lit(1)).into()
}

/// Wrapper for [`functions_aggregate::expr_fn::count`]
/// Count the number of non-null values in the column
#[pyfunction]
fn count(expr: PyExpr, distinct: bool) -> PyResult<PyExpr> {
let expr = functions_aggregate::expr_fn::count(expr.expr);
if distinct {
Ok(expr.distinct().build()?.into())
} else {
Ok(expr.into())
}
}

/// Create a CASE WHEN statement with literal WHEN expressions for comparison to the base expression.
#[pyfunction]
fn case(expr: PyExpr) -> PyResult<PyCaseBuilder> {
Expand Down Expand Up @@ -830,6 +811,7 @@ aggregate_function!(bit_xor);
aggregate_function!(bool_and);
aggregate_function!(bool_or);
aggregate_function!(corr, y x);
aggregate_function!(count);

fn add_builder_fns_to_window(
window_fn: Expr,
Expand Down Expand Up @@ -978,7 +960,6 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(cosh))?;
m.add_wrapped(wrap_pyfunction!(cot))?;
m.add_wrapped(wrap_pyfunction!(count))?;
m.add_wrapped(wrap_pyfunction!(count_star))?;
m.add_wrapped(wrap_pyfunction!(covar_pop))?;
m.add_wrapped(wrap_pyfunction!(covar_samp))?;
m.add_wrapped(wrap_pyfunction!(current_date))?;
Expand Down

0 comments on commit eb53593

Please sign in to comment.