FunSQL.jl icon indicating copy to clipboard operation
FunSQL.jl copied to clipboard

Reverse render: constructing query nodes from existing SQL string

Open rofinn opened this issue 2 years ago • 2 comments

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.

rofinn avatar Sep 06 '22 17:09 rofinn

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.

xitology avatar Sep 08 '22 17:09 xitology

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.

rofinn avatar Oct 12 '22 17:10 rofinn

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

clarkevans avatar Feb 26 '24 15:02 clarkevans