-
Hi! I posted this question in stackoverflow as well but not sure what you prefer:) My question is whether it is possible to define "abstract" queries in Ibis against a pre-defined schema and, given a datasource with the matching schema, execute this query? Ideally, I want to define schemas and abstract queries for them. Then, at a later stage, choose the backend, and finally, execute the queries. Here's a concrete example: import ibis
import pandas as pd
customers_schema = ibis.table(
[("CustomerId", int),
("Name", int),
("Age", int)]
, name="customers")
abstract_query = customers_schema.filter(customers_schema.Age >= 25)
print(abstract_query) # No problem here
# given actual data
customers_df = pd.DataFrame(
{"CustomerId": [1, 2, 3],
"Name": ["john", "jane", "maya"],
"Age": [28, 35, 22]
}
)
customers = ibis.memtable(customers_df, name="customers")
# possible to execute abstract_query against this data? I guess I could use Substrait, but it means currently I can only execute via DuckDB or Acero. Ideally I'd want to use any of the Ibis implemented backends. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
You should be able to create a connection and then pass an unbound expression to that connection's con = ibis.${whatever}.connect(...)
expr = build_query(table1, table2)
con.execute(expr) Did I understand your question correctly? |
Beta Was this translation helpful? Give feedback.
I think
memtable
s may be confusing understanding here. Let's stick with named tables inside a database, just for the sake of simplicity.Here's an example using DuckDB and abstract expressions: