Skip to content

row-wise min and max #16366

Closed
Closed
@drtconway

Description

@drtconway

Is your feature request related to a problem or challenge?

Thanks for an awesome platform! I'm really loving it!

In R pmin and pmax do row-wise min and max respectively. They're reasonably verbose to replicate, and probably much less efficient than a direct implementation. At the moment, I use the following code to achieve the same effect:

pub fn ifelse(cond: Expr, then: Expr, otherwise: Expr) -> datafusion::common::Result<Expr> {
    case(cond)
        .when(lit(true), then)
        .when(lit(false), otherwise)
        .end()
}

pub fn pmin(lhs: Expr, rhs: Expr) -> datafusion::common::Result<Expr> {
    ifelse(lhs.clone().lt_eq(rhs.clone()), lhs, rhs)
}

pub fn pmax(lhs: Expr, rhs: Expr) -> datafusion::common::Result<Expr> {
    ifelse(lhs.clone().gt_eq(rhs.clone()), lhs, rhs)
}

Describe the solution you'd like

A direct, builtin implementation would be faster, and more concise, since it could support a signature:
fn pmin(lhs: Expr, rhs: Expr) -> Expr.

The ifelse function would be nice too (I like the R equivalent too!), but is a lower priority.

Describe alternatives you've considered

The above code works, and isn't too awful, but a direct implementation would be nicer.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions