Borderless Queries #1238
Replies: 3 comments 1 reply
-
Step Two, kill the
|
Beta Was this translation helpful? Give feedback.
-
One thing I don't love about this is that when you have a nested query with two stages, it's a really unintuitive transformation to add a second nest after it: Before:
After:
It almost makes me want to have a different "end of statement" gesture like
Or maybe you just enclose it differently:
|
Beta Was this translation helpful? Give feedback.
-
After experimenting with this feature, the difficulty of reading and writing nested queries was the eventual downfall of this idea. |
Beta Was this translation helpful? Give feedback.
-
Queries Should Not Look Like Sources
A “source” is a set of definitions. It is never intended to be run, and so the syntax for a source looks like a bag of properties. This makes sense.
We currently use the same syntax that we developed for writing sources, to write queries. Mapping everything that happens in a query into something which looks like a source declaration. It might be more natural for queries to be written as sentences, not as bags of properties.
Step One, No {}
We change nothing about the language except that query “statements” are not contained in {} but simply strung out like SELECT, JOIN, FROM, GROUP BY are in SQL. Set the query free, let it out of bracket jail!
Notice how this short SQL query reads as “Select these two things from this data set with this grouping”, the scan across the sentence is uninterrupted and smooth.
One Liner Example
Now let’s write that sentence in Malloy. Notice how your ability to simply read left to right and collect information about the sentence is interrupted, you read this as flights … pause … piped into something which as you parse it … groups and counts … oh yeah groups and counts flights
Now in this new hybrid syntax it again scans smoothly “flights grouped by carrier and aggregated”
Other Examples
Let’s look at some small, but more normal queries where you are not reading the whole query, by scanning it for parts “what data is used, what is filtered, what is the grouping, what is computed, how is it sorted” In SQL you need to read carefully to answer those questions.
Malloy does this so much better, though the
}
means it takes one more line to do soAnd this query in the
{}
-free version, it is just slightly better, it has the barely perceptible speed bump of the { edited out of the experience. We carry “flights” with us into the query because we weren’t told by the { that this is new context. And just for laughs, this is the same number of LOC as the SQL query.Here’s some sample code which is sometimes used to evaluate syntax in a more complex setting. Note that {} can still bracket a query for clarity, or here, when it is required to get the nested queries in genre_matrix, but you are only incurring the extra burden of parsing the containment when the query is complicated enough to need it.
This feature depends on the extend and refine keywords being required, so it needs to wait for that to have shipped. This feature could then be rolled out, or if we are uncertain of its value, beta-tested, and enabled by users who want to experiment with it. (There is a lurking proposal to use part of the document tag-space for language directives)
Beta Was this translation helpful? Give feedback.
All reactions