orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

1.3.0 - aggregate functions do not work on embedded documents collection

Open dm-ordb opened this issue 13 years ago • 6 comments

Versions: -1.3.0 release -OrientDB 1.4.0-SNAPSHOT 20130227-0214

Hi, could you try the following sequence:

create class collection

insert into collection set data = [{"size": 0}, {"size": 0}, {"size": 30}]

select data.size, data.size(), min(data.size), max(data.size), sum(data.size), avg(data.size)
from collection

returned: { "result": [{ "@type": "d", "@rid": "#-2:0", "@version": 0, "data": [0, 30], "data2": 3, "sum": 30, "avg": 15 } ] }

expected: { "result": [{ "@type": "d", "@rid": "#-2:0", "@version": 0, "data": [0, 0, 30], "data2": 3, "min": 0, "max": 30 "sum": 30, "avg": 10 } ] }

It seems the aggregation is made on the set of values (not the list) .

dm-ordb avatar Feb 27 '13 13:02 dm-ordb

I don't know if it's right the current behavior or not, but try this:

select list(data.size), data.size(), min(data.size), max(data.size), sum(data.size), avg(data.size)

from collection

lvca avatar Feb 27 '13 13:02 lvca

Luca,

running the following query (added list function as you suggested) does not change anything:

select list(data.size), data.size(), min( list(data.size)), max( list(data.size)), sum( list(data.size)), avg(list(data.size)) from collection

The result is the same and it is actually inconsistent.

On the input we have collection of documents: [{"size": 0}, {"size": 0}, {"size": 30}] So the query's task is to aggregate the following collection of numbers [0, 0, 30]

And the result says: "data": [0, 30], -> 1 element form the collection missed "data2": 3, -> size of the collection =3 (OK) "sum": 30, -> OK "avg": 15 -> incorrect; should be =10 (30/3) min, max are not calculated at all -> incorrect

It is a bug from my point of view.

Regards Dan.

dm-ordb avatar Feb 27 '13 14:02 dm-ordb

So the data is not present in database?

lvca avatar Feb 27 '13 14:02 lvca

Luca,

I am sorry for inconvenience. I try to explain it more clearly.

If you prepare data: 1. create class collection insert into collection set data = [{"size": 0}, {"size": 0}, {"size": 30}, {"size": 50}, {"size": 50}]

and run this query: 2. select from collection

you get the the correct content in DB:

{"result":[{"@type":"d","@rid":"#11:0","@version":0,"@class":"collection", "data":[{"size":0},{"size":0},{"size":30},{"size":50},{"size":50}] }]}

  1. But if you try to calculate aggregates on "size" attribute from that collection [[{"size":0},{"size":0},{"size":30},{"size":50},{"size":50}] you get incorrect result.

select data.size as collection_content, data.size() as collection_size, min(data.size) as collection_min, max(data.size) as collection_max, sum(data.size) as collection_sum, avg(data.size) as collection_avg from collection

{"result":[{"@type":"d","@rid":"#-2:0","@version":0, "collection_content":[0,50,30]-> incorrect: should be [0,0, 30, 50, 50] as in the source data "collection_size":5,-> OK "collection_sum":80, -> incorrect: should be =130 "collection_avg":26} -> OK ]}

-if you try with [0, 0, 30, 50] {"result":[{"@type":"d","@rid":"#-2:0","@version":0, "collection_content":[0,50,30], -> incorrect: should be [0, 0, 30, 50] as in the source data "collection_size":4,-> OK: "collection_sum":80,-> OK: "collection_avg":26}-> incorrect; should be =20 (80/4) ]}

-if you try with [0,0,30] {"result":[{"@type":"d","@rid":"#-2:0","@version":0, "collection_content":[0,30], -> incorrect: should be [0,0, 30] as in the source data "collection_size":3, -> OK: "collection_sum":30, -> OK "collection_avg":15 -> incorrect; should be =10 (30/3) } ] }

You can note the following:

  • min max aggregates have not been calculated.
  • avg, sum result depends on input and sometimes is calculated incorrectly

Regards Dan

dm-ordb avatar Feb 27 '13 15:02 dm-ordb

this is fixed in develop branch. I just added a test case.

luigidellaquila avatar Jul 07 '15 13:07 luigidellaquila

Is this merged to 2.2 branch ?

red-0ne avatar Feb 23 '16 12:02 red-0ne