News for hackers. Stuff that matters.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by taf2 on Wednesday March 26, 2014 @01:14PM (#7474799)
I don't understand why databases like RethinkDB and MongoDB don't just provide a SQL interface. I get it - they are marketing themselves as NoSQL but they are infact providing almost exactly the same set of features that say MySQL provided back in the day a simple "fast" sub-set of SQL. Instead they use the lack of an interface as a marketing gimmick... when in reality we have to learn a new query language... :(
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @01:39PM (#7474966)
> I don't understand why databases like RethinkDB and MongoDB don't just provide a SQL interface.

Actually, it's a really good question. I'm one of the ReQL designers at Rethink, and I was the one pushing for no SQL compatibility. Here is some of my reasoning (we could talk about this for days, though):

  * Even SQL designers would tell you SQL isn't a very good
    programming language. It even looks like Cobol! Imagine if
    every language after Cobol decided to be backwards compatible
    -- what sort of world would we live in?
  
  * SQL is really bad for querying hierarchical data with lots of
    empty columns. The quality of experience you get from learning
    a new language designed for JSON, far outweighs the downsides
    of learning it. We're assuming people will be using ReQL
    fifteen years from now.
  
  * Designing a language that embeds into your programming language
    wasn't possible before -- but it is now. That means no more SQL
    injection, no more string manipulation, no more heavy
    ORMs. Well worth it in my opinion.
  
  * The chaining paradigm (largely pinoneered and proven by jQuery)
    is magical for getting people to intuitively understand how to
    write complex queries. No more StackOverflow questions of "How
    do I do X in SQL?" because there is now an intuitive
    consistency to the language.
  
  * SQL compatibility is very, very difficult. The standard is hard
    to implement, and has lots of grey area around the edges. You
    can go for full bug-by-bug compatibility, which would take
    decades. Or you can go for basic compatibility, which confuses
    people. They try to port their application, it works for a
    while, and then breaks in some grey area in production, which
    results in a terrible user experience.
As an example, I'd ponder on why SQL has both the `where` keyword, and the `having` keyword. This alone wouldn't be enough of a reason to design a new language, of course, but this sort of thing permeates SQL. It's 2014. We can do better.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by AaronFriel on Wednesday March 26, 2014 @02:49PM (#7475508)
I can tell at a glance what `where` and `having` mean - the former is a filter over a result set, and the latter is a filter over a grouping.

You're probably right that SQL should have earlier defined this sort of recursion, so that you could sequence groupings and filters more easily, but don't fret: that future is here with common table expressions. Recursion is even supported!

I'm reminded of this abomination of a query I wrote in 2010 that produced a numbers table:

http://blogs.msdn.com/b/sqlazure/archive/2010/09/16/10063301...

Code:

    DECLARE @N int = 1000000;

      WITH RecursiveRowGenerator (Row#, Iteration) AS (
           SELECT 1, 1
            UNION ALL
           SELECT Row# + Iteration, Iteration * 2
             FROM RecursiveRowGenerator
            WHERE Iteration * 2 < CEILING(SQRT(@N))
            UNION ALL
           SELECT Row# + (Iteration * 2), Iteration * 2
             FROM RecursiveRowGenerator
            WHERE Iteration * 2 < CEILING(SQRT(@N))
         )
         , SqrtNRows AS (
           SELECT *
             FROM RecursiveRowGenerator
            UNION ALL
           SELECT 0, 0
         )
    SELECT TOP(@N) 1 + A.Row# * POWER(2,CEILING(LOG(SQRT(@N))/LOG(2))) + B.Row# Row#
      FROM SqrtNRows A, SqrtNRows B
     ORDER BY A.Row#, B.Row#;
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by jjudge on Wednesday March 26, 2014 @07:57PM (#7477592)
Wow, that must have felt good to wrap up.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by josephlord on Wednesday March 26, 2014 @02:33PM (#7475355)
Do you consider Rethink relational (in the Codd sense)? From a quick look at the API I would guess that it qualifies.

What I couldn't see at a quick glance was a way to constrain the data in a table or enforce foreign key constraints. I guess those are the trade offs against something like Postgres for schema flexibility and easy distribution. Is that a correct way to view it?

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @02:43PM (#7475447)
> Do you consider Rethink relational (in the Codd sense)?

Under the hood, yes. How much of that is exposed to the user is debatable.

> What I couldn't see at a quick glance was a way to constrain the data in a table or enforce foreign key constraints. I guess those are the trade offs against something like Postgres for schema flexibility and easy distribution. Is that a correct way to view it?

That's about right. Some of this is by design (lack of schema enforcement), and we might add features to do that later. There are no architectural constraints preventing us from doing that.

Foreign key constraints will probably never be added to Rethink (or at least not for a long, long time) because doing those efficiently in distributed systems is anywhere from hard to impossible.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by derefr on Wednesday March 26, 2014 @03:42PM (#7475972)
Good arguments, though only the last one seems like a true objection.

I think, If I were implementing a database from the ground up, I'd indeed make my own query language--SQL does suck--but I would probably strive to accept SQL as an option, with the proviso that it's "just SQL syntax with ThisDB's semantics."

This would let people point their old applications, written under "the database is just an SQL-speaking dumb store for simple CRUD operations" assumptions (e.g. any ActiveRecord app), at the new DB and get somewhat-sensible results out, while still letting them write new applications against the new API.

The alternative is forcing any user with existing services to hack up some sort of application-level back-and-forth replication between their old DB and your new DB during the long-and-possibly-indefinite migration period, rather than just migrating in one fell swoop.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by dataminded on Wednesday March 26, 2014 @09:33PM (#7477986)
Background: I've done a fair bit of hiring for analysts and have worked in most facets of analytics/DW including vendor evaluation/selection and implementation.

I think that the lack of a SQL interface is a big negative. It's really hard to find analyst (not programmers) with good technical skills or train them to proficiency in new technologies. I would have a very hard time selling a platform that existing analysts wouldn't be able to use right away and that few people on the market could work with.

Also, designing a new language makes integration with other applications that much harder.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @10:44PM (#7478259)
That's a great point. Our hypothesis is that great querying capabilities for analysts and great querying capabilities for programmers should look completely different, and be two totally different technologies. We'll eventually ship a solution for analysts, but I don't think a great database product should shoot for a lowest common denominator.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by nXqd on Wednesday March 26, 2014 @10:17PM (#7478156)
You can find the answer to this in coffeemug' post :

"We're assuming people will be using ReQL fifteen years from now."

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by ashwinp92 on Wednesday March 26, 2014 @02:46PM (#7475470)
Although initially it seemed otherwise, your point on having a different interface to confusion between complete SQL compatibility v/s the subset being offered makes a lot of sense. Also personally I would rather prefer an imperative language for tasks where efficiency is the primary concern compared to declarative SQL
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by shin_lao on Thursday March 27, 2014 @04:09AM (#7479148)
It's great to see someone with a lot of enthusiasm, but I submit you think too much like a programmer and not enough like a database administrator.

What problem does your product solve that, for example, PostgreSQL doesn't?

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by shawn-butler on Wednesday March 26, 2014 @02:17PM (#7475230)
HAVING specifies a search condition for a group or an aggregate function.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @02:23PM (#7475270)
Sure, but consider how this works in ReQL:

  r.table('foo').filter(...)
  r.table('foo').group('category').filter(...)
A properly designed language shouldn't have two different keywords for something that does ostensibly the same thing in different contexts. That's a mark of bad language design.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by haberman on Wednesday March 26, 2014 @02:36PM (#7475393)
I don't think this is a "good language" / "bad language" dichotomy. SQL just sits at a different level of abstraction.

From the examples you have posted, it appears that ReQL is a lower-level abstraction that SQL. In SQL you specify what you want logically and the DB turns this into a query plan. It appears that ReQL is more like a query plan itself, where you explicitly specify the data flow from stage to stage of query evaluation.

As a more specific example of this, it appears that in many cases in ReQL the user specifies what index should be used in the query itself. SQL is more abstract than this; the idea is for the query planner to figure out what index(ex) should be used.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by meritt on Wednesday March 26, 2014 @02:38PM (#7475411)
Are you sure about that? Looking at even your example page [ http://www.rethinkdb.com/docs/sql-to-reql/ ] this appears to be wrong or at least confusing?

It's suggesting:

    SELECT category,
       SUM(num_comments)
    FROM posts
    GROUP BY category
    HAVING num_comments > 7
and:

    r.table("posts")
     .filter(r.row['num_comments']>7)
     .group('category')
    .sum('num_comments')
are identical.

I don't think they are? Your ReQL to me looks like it's applying WHERE num_comments > 7 and then aggregating that.

I mean regardless, your example SQL should be doing the >7 against an aggregate (e..g sum(num_comments)) not a field, that SQL does not work as written.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @02:47PM (#7475483)
Whoops, that's a great catch -- it's a bug in the docs. Will fix momentarily. Thanks!! (that is indeed embarrassing)

In ReQL any command you call after `group` runs on each group. So once you've called `group`, you can run anything you could run on a table on each group and that just works.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by meritt on Wednesday March 26, 2014 @02:49PM (#7475506)
So, to be clear here, you have created two fundamental things (both called "filter") -- A pre-group and a post-group filter. Users must still understand the difference and when to utilize them.

SQL just happens to call those WHERE and HAVING instead of "filter" both times.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @03:05PM (#7475653)
You're right, but it's not just `filter`. Any command that can run on a group can run on a full table and vice versa. For example:

  # get a sample of 3 elements from a table
  r.table('foo').sample(3)
  
  # get a sample of 3 elements from each group
  r.table('foo').group('category').sample(3)
You could say that we created two versions of `filter`, and `sample`, and every other command. But another way to say it is that we use polymorphism, which is widely considered an advantage in modern programming languages.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by meritt on Wednesday March 26, 2014 @03:40PM (#7475947)
Yeah, it's definitely more expressive and terse I just don't think your argument against WHERE/HAVING is incredibly strong. Someone could also just do subqueries and only use WHERE and achieve the exact same behavior that you offer (albeit with a ton more typing).

HAVING exists because it was created prior to subqueries/dynamic tables, otherwise we'd have been likely to just use:

    select * from (select category, sum(num_comments) as comments from posts group by category) as temp where comments > 7
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by br1 on Wednesday March 26, 2014 @08:13PM (#7477658)
As a LINQ user, I expected group('category').sample(3) to sample 3 categories, not to sample inside each category.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coffeemug on Wednesday March 26, 2014 @08:23PM (#7477694)
In ReQL you can do it with group('category').ungroup().sample(3). It's really powerful once you get the hang of it.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by boomzilla on Wednesday March 26, 2014 @02:35PM (#7475373)
In theory, yes. In practice, the best language is one that maps developer thought process into working code in the most natural ways. I don't know the community that ReQL is targeting, but for the current crop of data scientists, SQL is a more natural language in my opinion. (There is a reason why Hive is so popular among big companies, where you'd expect to find big data sets.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by fidotron on Wednesday March 26, 2014 @02:59PM (#7475602)
I'm totally the opposite, and blame you entirely for provoking what follows! SQL at this point is passed expiry.

The simple reason is we now have plenty of decent scripting languages to run as interactive prompts, all of which are far better at interfacing with the rest of the system than SQL is. Exposing a sane, direct, API in those languages gets you much more than SQL, along with having removed multiple layers of confusion, including string generation, escaping, reparsing, then is it doing what you want, etc.

I've been using LevelDB (via plyvel) a lot lately for data storage, and every time I end up having to use SQL (even indirectly via ORM) is painful by comparison because you can just feel the control being taken away from you, and somewhere you end up having to fire up the DB prompt for no good reason such as adding strange DB specific indexing flags to columns or even setting up authorization and DB creation, making it yet another thing to go wrong during deployment.

Protocol buffers stored in LevelDB prove so easy to use by comparison with something like SQLite or PgSQL just at an API level. The resulting code is simpler, cleaner, and much easier to reason about. If I need to move it to another format the code, again, is amazingly small.

As someone that cares deeply about my app's data structure seeing the acceptance of a world beyond SQL is one of the best developments in my career, and experience means I simply don't trust any SQL based abstraction to give you the controls to get it right.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coldtea on Thursday March 27, 2014 @07:14AM (#7479623)
>I'm totally the opposite, and blame you entirely for provoking what follows! SQL at this point is passed expiry.

Actually it's the very opposite.

SQL is a higher level abstraction for all this ad-hoc junk, based on actual mathematical principles (relational algebra), and it's also declarative, instead of imperative.

Furthermore, all this NoSQL query systems now emerging are nothing new. They were tried in the 70s and early 80s, and people found out that they sucked. Before SQL what we had was, well, NoSQL.

Wanting a flexible schema-less db or one that's denormalised for certain needs (like Google's or Facebook's) makes sense.

Replacing SQL and RBDMS for the common tasks they are used (company logistics and accounting, etc) with NoSQL is a regression to the primitive past. I guess people not knowning (computing) history are doomed to repeat it.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by teraflop on Wednesday March 26, 2014 @01:31PM (#7474917)
One reason is that SQL only lets you work with flat relational tables. MongoDB and RethinkDB let you store complex JSON-like objects as values, and extending SQL to query and manipulate those kinds of structures is hard. The closest attempt I've seen is Google's BigQuery.

Another reason is that SQL does its best to decouple the query (what you're asking for) from the execution plan (how it actually gets evaluated). But for operations like joins, the precise way the query is evaluated can have a huge effect on performance. So it makes sense to design your query language to explicitly expose those knobs to the programmer.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by spamizbad on Wednesday March 26, 2014 @03:39PM (#7475944)
I have no experience with RethinkDB, so maybe they did it right, but I have quite a bit with Mongo.

MongoDB's querying is nowhere near as powerful as SQL. And understanding its limitations and pain points are essential when structuring your data. Otherwise you'll never really scale unless you've got data that's embarrassingly easy to query (eg: filtering on 1 or 2 indexed fields).

Being able to write JS map-reduce queries is fine when you need to do stuff ad-hoc, but none of it can be used in production at scale. Then there's the aggregate framework which helps quite a bit but still doesn't offer the same level of performance I'd expect from Postgres, MSSQL, or Oracle. Things get really yucky when you have to start unpacking arrays - especially since there's a memory limit on $sort and $group. There are further issues related to skipping being slow on large collections because it must step through.

And to cope with these limitations you need to invest a ton of time into coding around them. The freedom of the database being schemaless? Gone. You must carefully structure data and decide up-front how it needs to be queried - or cope with poor performance.

And those complex queries, when written in ugly JSON, aren't the most human-readable things in the world. Certainly not any better than SQL.

I'd rather just invest the time in learning SQL than partake in the mental gymnastics necessary squeeze high-performance non-trivial queries out of MongoDB.

I understand MongoDB is a big hit with people who use it for low volume internal tools or people building MVPs. I can totally understand how its an awesome tool for those. But rusty old SQL starts looking better when your app scales and the business demands change.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by orthecreedence on Wednesday March 26, 2014 @04:13PM (#7476252)
You're right, you haven't tried REQL =]. As a developer of a RethinkDB driver and a fairly active user of the database, and also a previous fan of Mongo, I can tell you that REQL kicks the shit out of MongoDB's querying.

SQL really is well-geared towards relational, flat database systems. Mongo's querying is an obtuse command-based language that always felt like it was adding hacks on hacks to get the data you wanted.

REQL is almost like having your data in-memory, and you're running programmatic expressions on it that seamlessly melt into your native language. The lack of a query optimizer almost makes it better because you have to think about your query plans and indexes instead of just firing it off at the server and crossing your fingers. You're not running commands, you're processing data.

I don't have a lot of experience scaling Rethink, but I do know from reading the docs and architecture that it scales out better than most SQL servers will and certainly scale up better than Mongo. I've tried to scale both MySQL and Mongo. Both are difficult and painful.

You can't conclude that because of Mongo's failures, SQL beats Rethink. Rethink is light years ahead of Mongo.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by zapov on Wednesday March 26, 2014 @05:13PM (#7476712)
This is not true. Both Oracle and Postgres are ORDBMS and you can work with objects/nested collections and all kind of non-relational constructs.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by chipotle_coyote on Wednesday March 26, 2014 @10:31PM (#7478218)
I'm not really sure how you could wedge SQL into a system that doesn't really have the concept of columns without it being, at the least, a distinctly different dialect.

And, really, if you've worked with some of the "higher level" interfaces to SQL like SQLAlchemy or Laravel's QueryBuilder, ReQL doesn't seem that alien; they all tend to work by method chaining as well. (But they usually don't support everything SQL does, unlike ReQL's interfaces.)

Also: unlike my (admittedly limited) exposure to other NoSQL systems, RethinkDB supports relations and joins -- it's actually a lot easier for an SQL fiend to move to Rethink than any of its competitors.

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by neumino on Wednesday March 26, 2014 @01:27PM (#7474898)
ReQL is a new query language, and indeed requires the user to learn it but

- It's actually easy to learn -- especially with the data explorer

- It's nicer to use than SQL -- You can chain commands in the language you are using

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by willvarfar on Wednesday March 26, 2014 @02:32PM (#7475347)
I completely agree. Postgres, for example, has nice new JSON support, demonstrating that SQL can be grown in new modern ways.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by baruch on Wednesday March 26, 2014 @03:08PM (#7475674)
I much prefer ReQL over SQL. It is much nicer, flows naturally in my opinion and is combine-able. I'm using this combination method in my rethink-miner tool to help me work with data to try and figure it out and I can make generic queries that I can use on top of every other sub-query which is very very nice.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by coolsunglasses on Wednesday March 26, 2014 @02:39PM (#7475414)
For an idea of what's possible when you put aside SQL:

https://github.com/bitemyapp/Revise/

Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by j_s on Wednesday March 26, 2014 @05:04PM (#7476648)
For now it probably keeps a number of users away that they don't want to support, but it makes sense to at least have an automatic translation layer in the long run.
Re:RethinkDB 1.12: simplified map/reduce, ARM port, new cach... by biokoda on Wednesday March 26, 2014 @02:19PM (#7475240)
there are some that do. The so called newSql databases like actordb