Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.3.0 - aggregate functions do not work on embedded documents collection #1373

Closed
dm-ordb opened this issue Feb 27, 2013 · 6 comments
Closed
Assignees
Labels
Milestone

Comments

@dm-ordb
Copy link

dm-ordb commented Feb 27, 2013

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) .

@ghost ghost assigned lvca Feb 27, 2013
@lvca
Copy link
Member

lvca commented Feb 27, 2013

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 lvca closed this as completed Feb 27, 2013
@dm-ordb
Copy link
Author

dm-ordb commented Feb 27, 2013

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.

@lvca lvca reopened this Feb 27, 2013
@lvca
Copy link
Member

lvca commented Feb 27, 2013

So the data is not present in database?

@dm-ordb
Copy link
Author

dm-ordb commented Feb 27, 2013

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

@lvca lvca modified the milestones: 2.0rc1, 2.1 Aug 28, 2014
@lvca lvca assigned luigidellaquila and unassigned lvca Aug 28, 2014
@lvca lvca modified the milestones: 2.1-rc1, 2.1-rc2 Apr 1, 2015
@lvca lvca modified the milestones: 2.1-rc2, 2.1 GA May 5, 2015
luigidellaquila added a commit that referenced this issue Jul 7, 2015
…embedded documents collection (already fixed)
@luigidellaquila
Copy link
Member

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

@lvca lvca modified the milestones: 2.1 GA, 2.1-rc6 Jul 28, 2015
@red-0ne
Copy link

red-0ne commented Feb 23, 2016

Is this merged to 2.2 branch ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants