groupby and join in couchbase lite for android

I have the following documents for use in Android:


{“Type” : “User”, “UserId” : 920, “InitialCommitment”: 2000, “BlockId”: 1, “_id” : “User_1_920”},
{“Type” : “User”, “UserId” : 921, “InitialCommitment”: 1800, “BlockId”: 1, “_id” : “User_1_921”}

where Id is formed in Type_BlockId_UserId


{“Type” : “Intr”, “UserId” : 920, “IntrId”:1, “Value”: 11, “BlockId”: 1, “_id” : “Intr_1_920_1”},
{“Type” : “Intr”, “UserId” : 920, “IntrId”:2, “Value”: 5, “BlockId”: 1, “_id” : “Intr_1_920_2”}

where id is Intr_BlockId_UserId_IntrId

Basically, I want to get an aggregated data by BlocKId something like this:

BlocKId: 1, totalCommitments:3800, totalInterests: 16

I have indexes on Type, UserId, IntrId and BlockId fields. My issue now is my app don’t compile because the Sum function does not exist. Secondly, I am doing two queries one to get aggregates for interests and another for commitments. Is there away to join the queries in one go?

val queryTotalCommitment: Query =

val queryTotalInterests: Query =

the error now is Sum does not exist. Am I suppposed to write it? I have already imported Function from couchbaste.lite

I think you mean sum (with a lower case l, not upper case).

thanks Borrrden. Even with lower case sum, I still can’t compile as it complains sum not imported.

My apologies. We are behind in making our code Kotlin friendly.

In Java, public members of non-public super classes are visible from the subclass. This is not the case in Kotlin. The “sum” method is declared in a package protected superclass of Function (AbstractFunction). That means that Kotlin can’t see it.

I am afraid that this will not change in the next release; perhaps not even in the one after that. You will have to write your query creation code in Java.

Again, my apologies. I am trying to get this fixed.

oh thatnks Blake! That is totally fine.