Restream / reindexer

Embeddable, in-memory, document-oriented database with a high-level Query builder interface.
https://reindexer.io
Apache License 2.0
763 stars 64 forks source link

Aggregation on the right table is calculated, but the application is not given #13

Closed liderman closed 5 years ago

liderman commented 6 years ago

Hi, This issue - the result of the dialogue in Telegram chat: https://t.me/reindexer/43

Query example:

leftQ := db.Query ("features").Where (... this where select features)
rightQ := db.Query ("goods").Where (.... this where select goods).Aggrgate("id", AggSum)
leftQ.Join (rightQ).On ("id", reindexer.EQ, feature_ids)

Result example:

[{
   "id": 1,
   "CPU Intel Core i7",
   "_joined_goods": {
     " agg" : 10
   },
   "id": 5,
   "RAM 8Gb",
   "_joined_goods": {
     " agg" : 55
   },
}

Problem: Aggregation on the right table is calculated, but the application is not given

liderman commented 5 years ago

Tested on version v1.10.0. Problem solved. Thank.

usage by one field:

iterator := db.Query("items").Aggregate("name", reindexer.AggMax).Exec()
aggRes := iterator.AggResults()[0]
fmt.Printf("fieldName: `%s` -> value: `%f`", aggRes.Name, aggRes.Value)

usage by two field:

iterator := db.Query("items").Aggregate("field1", reindexer.AggMax).Aggregate("field2", reindexer.AggMin).Exec()
for _, aggRes := range iterator.AggResults() {
    fmt.Printf("fieldName: `%s` -> value: `%f`", aggRes.Name, aggRes.Value)
}