Yes, SQL lacks tooling. There's a ton of stuff to build a SQL client, obviously. However, on the other side:
- I have no sane way to parse SQL
- I have no sane way to comprehend SQL
Writing a SQL query system would be many months of work. Tossing together a good-enough query language with standards like JSON or YAML means I can json.loads(query) in Python and JSON.parse in JavaScript.
SQL would be an ideal fit if there was good tooling, and it fits in more places than most people realize. Web API query a whole bunch of stuff stored in all sorts of complex ways. SQL is better on paper than RESTful / AJAXy / GraphQL / etc. APIs.
It's not better if it means that the query language takes more time to build out than the entire rest of the system.
TL;DR: If you want to build a high-visibility open-source project and guarantee employment for the rest of your life, an elegant SQL parser, especially for building web APIs, would be a great thing to do.
This comment is full of hyperbole. Writing a precedence-climbing SQL parser should take a few days. I know because I've done it. I don't know where you're getting "months of work" - mine ended up being like 600 lines of Python.
And I don't know what you mean by "no sane way to comprehend SQL" - I guess the millions of data people in the industry are just insane?
Cobbling it together with YAML or JSON is a reasonable trade off if you're in a hurry, but I don't understand how we got to the point where we're throwing out estimates like "writing a parser is months of work" and "it's a PhD project to render some glyphs [1]"
I was kind of assuming you had those things for a YAML based frontend, and just wanted to implement SQL support.
I can see that if your YAML solution doesn’t have a way to express GROUP BY, so the backend doesn’t support it, then of course that’ll be extra work, but then that’s IMO a different feature.
My current JSON-based system doesn't implement full SQL semantics. We definitely don't have (or actually need) GROUP BY. Doing full SQL would require ASTs, a query optimizer, and similar. Right now, it's SQL-like, but the implementation is really quite dumb.
What I actually want is the whole dotty / efilter system, only with things like documentation.
We really do care about performance, though. From your code, this would not work:
api.apply("SELECT name FROM users WHERE age > 10",
vars={"users": ({"age": 10, "name": "Bob"},
{"age": 20, "name": "Alice"},
{"age": 30, "name": "Eve"}))
It would really need to be:
query = api.compile("SELECT name FROM users WHERE age > 10")
Could you tell me what you want to accomplish by reimplementing query system? I really curious, because generally query systems used to query data from DB..
I'm working on a platform where data changes in real-time, often every few milliseconds. It's not stored in a DB, and a lot of it is computed on-the-fly.
What I want to query is a perfect fit for SQL. However, it's very much not in a database.
I also don't need a subset of SQL. I would need things like stored procedures and ideally things like virtual tables. There's a lot of computation going on in the queries. The postgres can represent 100% of what I want, but it's a big complex syntax.
In an ideal case, I could pick up pieces and run with them. I think I could reuse parts of things like a query optimizer too.
Why not SQL?
Lack of tooling for SQL.
Yes, SQL lacks tooling. There's a ton of stuff to build a SQL client, obviously. However, on the other side:
- I have no sane way to parse SQL
- I have no sane way to comprehend SQL
Writing a SQL query system would be many months of work. Tossing together a good-enough query language with standards like JSON or YAML means I can json.loads(query) in Python and JSON.parse in JavaScript.
SQL would be an ideal fit if there was good tooling, and it fits in more places than most people realize. Web API query a whole bunch of stuff stored in all sorts of complex ways. SQL is better on paper than RESTful / AJAXy / GraphQL / etc. APIs.
It's not better if it means that the query language takes more time to build out than the entire rest of the system.
TL;DR: If you want to build a high-visibility open-source project and guarantee employment for the rest of your life, an elegant SQL parser, especially for building web APIs, would be a great thing to do.