ibis-project / ibis

the portable Python dataframe library
https://ibis-project.org
Apache License 2.0
5.07k stars 586 forks source link

feat: Windowing/aggregating over literals #9773

Open TrevorBergeron opened 1 month ago

TrevorBergeron commented 1 month ago

Is your feature request related to a problem?

No response

What is the motivation behind your request?

I'm a developer of BigQuery Dataframes . I would like to programatically build SQL queries using ibis. It is challenging to build compact sql involving windows over constant expressions, as the ibis literal API does not allow building of windowed expressions over literals, despite this being legal in GoogleSql.

Right now, I'm forced to select the literal, and then apply the window afterwards, generating a new CTE, and therefore producing more verbose SQL.

Describe the solution you'd like

I'd like to apply aggregate functions to literal expressions in the context of select. For example table.select(ibis.literal(3).sum().over(some_window)).

What version of ibis are you running?

8.0.0

What backend(s) are you using, if any?

BigQuery

Code of Conduct

cpcloud commented 1 month ago

Yep, the ability to do things that are only allowed on columns currently, but on scalars, comes up sometimes.

This seems like a reasonable request to me.

Implementation wise, it'll probably involve moving a handful of methods into the base Value class.

cpcloud commented 1 month ago

@TrevorBergeron Do you have an example that demonstrates the difference in output SQL? It'd be good to know just how much worse it is before we go down this path.