MechanicalRabbit / FunSQL.jl

Julia library for compositional construction of SQL queries
https://mechanicalrabbit.github.io/FunSQL.jl
Other
150 stars 6 forks source link

Reverse render: constructing query nodes from existing SQL string #35

Closed rofinn closed 7 months ago

rofinn commented 2 years ago

One point of friction using FunSQL.jl is that I still often need to switch between two different syntax. I still need to write SQL in a query editor while debugging and performance testing, but I eventually need to translate to modular FunSQL.jl syntax in a package. I'm not sure how hard it would be at this stage to reverse the render function to generate the Julia object I want to use in my code... perhaps that kind of functionality is out of scope? I do think it would be really slick and it'd be really cool if this function could identify parts of a dialect that aren't currently supported.

xitology commented 2 years ago

Translation of SQL into the corresponding FunSQL expression would be a valuable feature, but I'm not sure if it is in scope of the FunSQL package itself. Perhaps, it belongs to a separate package.

Such translation is a challenging problem. The biggest challenge is not the translation per se, but parsing the input SQL into an abstract syntax tree. SQL syntax is irregular and difficult to parse, and, moreover, different SQL dialects are mutually incompatible, so each dialect would require a specialized parser. Perhaps, SQL parsing could be delegated to some 3rd-party library. Such additional dependency would be another argument for moving this feature into another package.

We could also consider a radically different idea: implement a database IDE that directly supports FunSQL. Such IDE would have an advantage over traditional database IDEs because it could allow the user to build queries incrementally, as well as encapsulate and reuse query components.

rofinn commented 1 year ago

I don't think creating a custom IDE is the right solution here as that would be a much larger project to maintain. I also don't see a lot of benefit to using FunSQL for adhoc querires in an editor. AFAICT, some DBMS systems already provide libraries for converting SQL to syntax trees, usually with some JSON representation being available.

https://github.com/pganalyze/libpg_query

That being said, I can see FunSQL not wanting to be coupled to any specific DBMS systems, so I'd be fine if some wrapper package just used Requires.jl to include that glue code if FunSQL is loaded.

clarkevans commented 7 months ago

I think this ticket is out of scope for FunSQL, so we'll close it. It's a great idea though.