I have the following documents for use in Android:
Users:
{“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
Interests:
{“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 = QueryBuilder.select(
SelectResult.expression(Function.Sum(Expression.property("InitialCommitment"))),
SelectResult.property("BlockId"),
.from(DataSource.database(database))
.groupBy(
Expression.property("BlockId"))
val queryTotalInterests: Query = QueryBuilder.select(
SelectResult.expression(Function.Sum(Expression.property("Value"))),
SelectResult.property("BlockId"),
.from(DataSource.database(database))
.groupBy(
Expression.property("BlockId"))
the error now is Sum does not exist. Am I suppposed to write it? I have already imported Function from couchbaste.lite