Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grouping and couting data #48

Open
gstraymond opened this issue Jan 22, 2016 · 1 comment
Open

Grouping and couting data #48

gstraymond opened this issue Jan 22, 2016 · 1 comment

Comments

@gstraymond
Copy link

Hi,

I try using group() and count() on a table like : https://www.rethinkdb.com/api/java/group/

r.table("matches").group(
    match -> r.array(match.g("date").year(), match.g("date").month())
).count().run(conn);
[
    {
        "group": [2014, 2],
        "values": 2
    },
    {
        "group": [2014, 3],
        "values": 2
    },
    ...
]

The goal is to simply group data by a field and count grouped occurences.
In my code, this looks like :

def getLeaderboard: Future[Double] = {
    r.table("stats").group("userId").count().run
}

First problem, to make code compile to function must return a Future[Double], I would expect something like Future[Map[String, Double]] or Future[Seq[(String, Double)]].
Then, when I try to run the code and get this in return (this is logic since the return type is not correct) :

RethinkRuntimeError: Can not deserialize instance of java.lang.Double out of START_OBJECT token at 
[Source: {"t":1,"r":[{"$reql_type$":"GROUPED_DATA","data":[["foo",143]]}]}; line: 1, column: 13] 
(through reference chain: com.rethinkscala.net.JsonResponse["r"]->com.fasterxml.jackson.module.scala.deser.BuilderWrapper[0])]

I think the request is good, since in the error I can see the data grouped and counted.

BTW, I'm using : "com.rethinkscala" %% "core" % "0.4.8-SNAPSHOT"

Any help appreciated !

@kclay
Copy link
Owner

kclay commented Jan 25, 2016

Group and ungroup have always been a problem to support due to the ability to group by different data types. I'll take another look into this to see if I can at least provide some casting methods so the user can instruct the driver of the correct type when it fails to pick the correct type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants