Re:Things I wished more developers knew about databases
by pbowyer on Wednesday April 22, 2020 @11:46AM
(#22946799)
I find thinking about analytic queries like these as map/filter/reduce easier than thinking in terms of the SQL!
Re:Things I wished more developers knew about databases
by taffer on Wednesday April 22, 2020 @12:31PM
(#22947358)
SQL and functional programming constructs are actually quite similar:
SELECT -> map
FROM -> stream
JOIN -> flatMap
WHERE -> filter
GROUP BY -> collect
ORDER BY -> sorted
https://blog.jooq.org/2015/08/13/common-sql-clauses-and-thei...
Re:Things I wished more developers knew about databases
by karmakaze on Wednesday April 22, 2020 @09:21PM
(#22951905)
I don't see how JOIN is like flatMap. It's a subset of a cross-product. It's more like do-notation:
x <- ..
y <- ..
return (x, y)
Re:Things I wished more developers knew about databases
by taffer on Thursday April 23, 2020 @04:15AM
(#22953825)
> I don't see how JOIN is like flatMap
This is explained in the blog post I linked, including an example.
Re:Things I wished more developers knew about databases
by karmakaze on Thursday April 23, 2020 @03:38PM
(#22960229)
It's really flatMap/map from the link:
List<Integer> s1 = Stream.of(1, 2);
Supplier<Stream<String>> s2 = ()->Stream.of("A", "B");
s1.flatMap(v1 -> s2.get()
.map(v2 -> tuple(v1, v2)))
.forEach(System.out::println);
That's just a nested loop.
Aggregate functions in SQL are IMHO quite awesome once you develop a comfort level to stop worrying about them per se. I wouldn't like to try to get Excel to tell me--or write the code to do manually--something like "show me the standard deviation in units sold by day of week over the last ten summers."