Something that I'm working on is a pure python SQL engine https://github.com/tobymao/sqlglot/blob/main/sqlglot/executo.... It does the whole shebang, parsing, optimizations, logical planning, physical execution.
Something that I'm working on is a pure python SQL engine https://github.com/tobymao/sqlglot/blob/main/sqlglot/executo.... It does the whole shebang, parsing, optimizations, logical planning, physical execution.
I have a personal question if you don't mind -- I do some SQL query generation and transpilation for both work and hobby. One headache I've run into recently is generating nested EXISTS() subqueries.
Imagine you have something like this:
// WHERE Name = 'Audioslave'
{
type: "binary_op",
operator: "equal",
column: { path: [], name: "Name" },
value: { type: "scalar", value: "Audioslave" },
}
This is all fine, but what if you want to say "A binary operation on related entities": {
type: "binary_op",
operator: "equal",
column: { path: ["Albums", "Tracks"], name: "AlbumId" },
value: { type: "scalar", value: 40 },
},
Which you want to generate something like: WHERE EXISTS(SELECT 1 FROM Albums WHERE Albums.ForeignKey = t.PrimaryKey
AND EXISTS(SELECT 1 FROM Tracks WHERE Tracks.ForeignKey = Albums.PrimaryKey AND AlbumId = 40))
How to do this is giving me a headache for a lot of reasons and I can't seem to come up with a good way.
Any tips, references, or search terms to google?Thank you, look forward to digging in more + gave your repo a star!
i'm not exactly sure what you're asking though, in terms of sql generation, it's not difficult for me because i just take in sql and output sql from the ast
How permissive is the parser? Do you need to know the exact dialect up front or can it make some intelligent guesses for unknown UDFs etc?