by cldellow · 9y ago · 0 comments
An example: our company uses redash for sharing ad hoc data sets internally. It'd be easy to generate a SQL expression with array_agg that could be wrapped in a span w/this font. I currently cruft up a call to a google charts replacement to do just that, which sucks because it adds a bunch of image requests.
I _could_ do it with SVG, too, but the expression to create it would be a lot more complex.
I can imagine submitting a PR to redash to autoformat any SQL column named "sparkline" with this font, actually.
(Valid criticism: maybe I should use a richer tool than redash for this...but I love it when a general tool can do a lot just because of composable primitives, AtF Spark fits the bill perfectly here.)
> it would be a lot more complex
I don't use redash, but isn't the 'complexity' just the boiler plate literal text? The query is rather simple.
'<svg ...etc... d="L' +
SELECT ROW_NUMBER() OVER (ORDER BY Date DESC), Value FROM Data GROUP BY Date +
'" ...etc... /></svg>'
No more complex than the google chart call, surely?To fit in the redash model, you need a single expression that returns a string of HTML. So the example you cite isn't quite there, as I don't think it's valid SQL (or is it? I'm mainly familiar with Postgres--perhaps that example is valid in some other DB?)
So you need something like:
SELECT 'preamble' || (SELECT string_agg(ROW_NUMBER() OVER (ORDER BY Date Desc), ...) || 'postamble'
Except aggregate functions can't contain window functions, so something like:
WITH windowed as (SELECT ROW_NUMBER(), ...) SELECT 'preamble' || (SELECT string_agg(row_number || ',' value, ',') FROM windowed) || 'postamble'
is needed. Which isn't a big deal, but since you don't really care about the row number, it's nice to be able to skip the CTE and just directly smash the values into a string_agg.
It's a minor thing, but I'm lazy.
Mind sharing what you're doing today with me (the Google Charts approach)? My email is arik at redash.io.
Thanks!