Description
Is your feature request related to a problem?
I am trying to use the SQL expression for multiple CTE but the Table.sql
only allows for a single table.
What is the motivation behind your request?
I found https://ibis-project.org/how-to/extending/sql very useful as an intermediate step to migrate existing SQL scripts to ibis. Instead of going from SQL -> ibis immediately, it is sometimes useful to breakdown a complex SQL into multiple ibis expressions (using the .sql
). This requires minimal effort but already make the SQL scripts much more debuggable.
Consider this example
with a as (select * from raw_a),
with b as (select * from raw_b)
select a.*, b.* where a.id=b.id
To break it down with ibis
, I start with copying the CTE as follow
a = con.sql("select * from raw_a").alias("a")
b = con.sql("select ( from raw_b").alias("b")
All follow option will fail as it doesn't understand the table alias
con.sql("select a.*, b.* from a where a.id=b.id") #doesn't know a & b
a.sql("select a.*, b.* from a where a.id=b.id") # doesn't know b
b.sql("select a.*, b.* from a where a.id=b.id") # doesn't know a
This make it possible to debug, or inspect data quickly inside a notebook. Then I want to join them together but I cannot find the correct API. Backend.sql
only recognize tables that are exists already (raw_a, raw_b).
while a.sql()
will only recognize a but not b, and b.sql()
only recognize b but not a. Chaining ibis expression with SQL is powerful but this seems to limited to a single table, which make joins impossible.
I know this is doable if I go for full ibis dataframe code, but this is not what I want here.
Describe the solution you'd like
But some reason the documentation to extend SQL with expression is quite hidden. I have browsed the documentation a couple of times before but didn't know this feature exist.
What version of ibis are you running?
ibis-framework 9.5.0
What backend(s) are you using, if any?
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Type
Projects
Status