1

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

Matthew Groves
  • 25,181
  • 9
  • 71
  • 121
Nie Selam
  • 1,343
  • 2
  • 24
  • 56

2 Answers2

0

It is because of Kotlin. It worked well in Java because public members of non-public super classes are visible from the subclass, which is not the case in Kotlin. HERE IS MORE

Nie Selam
  • 1,343
  • 2
  • 24
  • 56
0

As @Nie points out in his link we are still working on making our API Kotlin friendly.

The specific reason that you the Sum function worked in Java but not Kotlin is that 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 expect to fix this problem in a release sometime around the end of this year.

Until then the best solution is a QueryBuilder helper class, written in Java.

G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40