Created
March 15, 2023 16:02
-
-
Save gforsyth/189df412b1b546ee9523254019503fb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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