Skip to content

Instantly share code, notes, and snippets.

@gforsyth
Created March 15, 2023 16:02
Show Gist options
  • Save gforsyth/189df412b1b546ee9523254019503fb3 to your computer and use it in GitHub Desktop.
Save gforsyth/189df412b1b546ee9523254019503fb3 to your computer and use it in GitHub Desktop.
import ibis
# Need to define a schema for each table in the SQL
catalog = {
"employee": {"first_name": "string", "last_name": "string", "id": "int64"},
}
# SQL to translate
sql = "SELECT *, first_name as first FROM employee WHERE id < 5 ORDER BY id DESC"
# Parse SQL into in-memory Ibis expression
expr = ibis.parse_sql(sql, catalog)
# Decompile Ibis expression into Python code that will create that expression
code = ibis.decompile(expr, format=True)
print(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment