Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: combine scalar from one table with column from other table #6800

Closed
1 task done
NickCrews opened this issue Aug 7, 2023 · 5 comments
Closed
1 task done

feat: combine scalar from one table with column from other table #6800

NickCrews opened this issue Aug 7, 2023 · 5 comments
Labels
feature Features or general enhancements

Comments

@NickCrews
Copy link
Contributor

Is your feature request related to a problem?

I'm not sure if this is even possible with SQL, I was playing around with duckdb and I couldn't get it to work, but it seems like it should be possible (ie "well-defined") to me, so I was guessing I just didn't find the right SQL. If this isn't possible in SQL then feel free to close this.

import ibis

t1 = ibis.examples.penguins.fetch()
t2 = ibis.examples.penguins.fetch()
t1.body_mass_g + t2.body_mass_g.max()
# gives `RelationError: Cannot convert  expression involving multiple base table references to a projection`

Describe the solution you'd like

The above should work.

What version of ibis are you running?

6.0.0

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

duckdb

Code of Conduct

  • I agree to follow this project's Code of Conduct
@NickCrews NickCrews added the feature Features or general enhancements label Aug 7, 2023
@cpcloud
Copy link
Member

cpcloud commented Aug 7, 2023

It's possible, using CROSS JOIN:

with bm_max as (select max(body_mass_g) as bmx from other_penguins)
select t.body_mass_g + bmx from penguins t cross join bm_max

@NickCrews
Copy link
Contributor Author

Ah, I see, the problem was that I needed to do the max() inside the CTE, thank you!

So, can we make Ibis clever enough to do this for us?

@cpcloud
Copy link
Member

cpcloud commented Aug 7, 2023

I realized there's another way that doesn't involve an explicit cross join:

select body_mass_g + (select max(body_mass_g) from other_penguins)
from penguins

☝🏻 might be easier to give sane behavior to than cross join rewrites.

@lostmygithubaccount
Copy link
Member

going to close as complete based on the discussion, feel free to re-open

@NickCrews
Copy link
Contributor Author

related to #7655.

Yes this is good to close, the code snippet I posted now works on master! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements
Projects
Archived in project
Development

No branches or pull requests

3 participants