Hacker News new | comments | show | ask | jobs | submit login
Translating SQL Queries using map, reduce, and filter in JavaScript (zsoltnagy.eu)
22 points by zsolt777 35 days ago | hide | past | web | favorite | 6 comments



My Answer: To replace a SQL select with javascript map/reduce is senseless. The whole idea of a database is to provide high performance access to data using index lookups. This particular case can be performed by a full table scan and a merge/sort operation, and so the performance might be acceptable, that is not a general solution though.

As an aside: You could optimise this in sql by providing indices on some of the fields and the DB would then perform a full index scan rather than a table scan.


Note: My sideproject/hobby is how build a relational language.

The problem is not about using map/reduce, is that you need to return them as AST, so you can do the whole compiler dance to optimize them, instead of interpret right away that is the default.

Also, know this is usefull when you want to post-process the data after the SQL have run, and you need to do some extra pass in the client... Instead of the ad-hoc most do.


Additionally, SQL is a domain specific language that is standard and cross platform. Why write a query dozens of different times for dozens of different host languages when you could just write it once?


In C# where you have something similar with Linq it makes sense. The runtime translates Linq to expression trees and the Linq provider translates the expression tree at runtime to a native query. That native query can be anything - sql, mongoquery, or can be an in memory collection, etc.

You can use the same strongly typed Linq expression with anything.


I guess that’s true! Embedded domain specific languages could be useful to swap out your data layer or provide a unified interface for different data layers.


I don't think that it is for situations were you have a database and are deciding to get rid of it but it could be useful if you starting something but for whatever reason a DB isn't possible and you might be new to Javascript. A version of the panadas Comparison with SQL doc for pure Javascript? Also pretty simple association of map-reduce to SQL I haven't seen before in Hadoop explanations.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: