Tested Aqua Data Studio Aqua Data Studio 14.0.0-beta-68 Build #: 33238 on Ubuntu 12.04( Mongo DB 2.4.3) and Windows XP ( Mongo DB 2.0.9).
Currently program automatically adds FIELD_EXISTS( ) for the all aggregation functions and this causes unpredictable results. This is not needed at all as MongoDB always applies aggregation functions only to the records with existing fields. E.g. description of $min command from the documentation:
non-missing values for the field."
See next scriptset:
insert into nullcoll(a,b) values (1,1)
go
insert into nullcoll(a,b) values (null,2)
go
select sum(a) from nullcoll
go
--> returns 1 (correct)
select sum(b) from nullcoll
go
--> returns 6 (correct)
select sum(a), sum(b) from nullcoll
go
--> return 1, 3 (incorrect)
Currently program automatically adds FIELD_EXISTS( ) for the all aggregation functions and this causes unpredictable results. This is not needed at all as MongoDB always applies aggregation functions only to the records with existing fields. E.g. description of $min command from the documentation:
The $exists operator is not required for the $min command, but is required for the $sum one. Please try the MongoShell equiv for COUNT(b) and you'll get different results when $exists is present vs when it is not.
I'll look for a fix on this issue.
Currently program automatically adds FIELD_EXISTS( ) for the all aggregation functions and this causes unpredictable results. This is not needed at all as MongoDB always applies aggregation functions only to the records with existing fields. E.g. description of $min command from the documentation:
The $exists operator is not required for the $min command, but is required for the $sum one. Please try the MongoShell equiv for COUNT(b) and you'll get different results when $exists is present vs when it is not.
I'll look for a fix on this issue.
The $exists operator is now used only when the COUNT() aggregate function occurs alone (thus the faster count command is used), but no more when Aggregation Framework is involved. Thus, the two failing scenarios reported above are now fixed.
I've also fixed another scenario:
select count(a), sum(a) from nullcoll
which was incorrectly returning
count(a) | sum(a) |
1 | 1 |
i.e. null values for the "a" field were not counted when Aggregation Framework was involved (because the count() function does not occur alone), but
select count(a) from nullcoll
was already working fine and returning the expected value: 2 .
The $exists operator is now used only when the COUNT() aggregate function occurs alone (thus the faster count command is used), but no more when Aggregation Framework is involved. Thus, the two failing scenarios reported above are now fixed.
I've also fixed another scenario:
select count(a), sum(a) from nullcoll
which was incorrectly returning
count(a) | sum(a) |
1 | 1 |
i.e. null values for the "a" field were not counted when Aggregation Framework was involved (because the count() function does not occur alone), but
select count(a) from nullcoll
was already working fine and returning the expected value: 2 .
Emil, please , look in ticket 9658. Regular count() should not count NULL values in same wat as count() in GROUP BY.
Emil, please , look in ticket 9658. Regular count() should not count NULL values in same wat as count() in GROUP BY.
You're right. OK, I'll change the COUNT() aggregate function behaviour to count only existing, non-null values.
You're right. OK, I'll change the COUNT() aggregate function behaviour to count only existing, non-null values.
Note: Not counting null values makes MongoSQL consistent with other RDBMS' behaviour, but there will be an in-house inconsistency in MongoSQL:
The other approach would be to count null values both if regular count (i.e the faster MongoDB count command is used when count() appears alone and GROUP BY is not used) or if Aggregation Framework is involved. This approach makes count() and push() behaviour consistent, but is not consistent with the other RDBMS.
Note: Not counting null values makes MongoSQL consistent with other RDBMS' behaviour, but there will be an in-house inconsistency in MongoSQL:
The other approach would be to count null values both if regular count (i.e the faster MongoDB count command is used when count() appears alone and GROUP BY is not used) or if Aggregation Framework is involved. This approach makes count() and push() behaviour consistent, but is not consistent with the other RDBMS.
Sachin and I discussed this. We think it is correct that push takes into account the null value.
The problem reported in this issue with push is the following:
select push(a),push(b) from nullcollgo--push(a) push(b)----------- -----------[1,null] [1,2]You can see that element [3] in the push(b) is absent
Sachin and I discussed this. We think it is correct that push takes into account the null value.
The problem reported in this issue with push is the following:
select push(a),push(b) from nullcollgo--push(a) push(b)----------- -----------[1,null] [1,2]You can see that element [3] in the push(b) is absent
Sachin and I discussed this. We think it is correct that push takes into account the null value.
OK, then we keep this behaviour.
The problem reported in this issue with push is the following:
select push(a),push(b) from nullcollgo--push(a) push(b)----------- -----------[1,null] [1,2]You can see that element [3] in the push(b) is absentIt expects push(b) to have a value of [1,2,3].
Yes, this has already been fixed for the 1.2.6 drop by getting rid of the $exists operator from Aggregation Framework, as Slava suggested. The $exists operator is now automatically appended only for the regular count operation (i.e. when Aggregation Framework is not involved).
Sachin and I discussed this. We think it is correct that push takes into account the null value.
OK, then we keep this behaviour.
The problem reported in this issue with push is the following:
select push(a),push(b) from nullcollgo--push(a) push(b)----------- -----------[1,null] [1,2]You can see that element [3] in the push(b) is absentIt expects push(b) to have a value of [1,2,3].
Yes, this has already been fixed for the 1.2.6 drop by getting rid of the $exists operator from Aggregation Framework, as Slava suggested. The $exists operator is now automatically appended only for the regular count operation (i.e. when Aggregation Framework is not involved).
Issue #9652 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
Fixed Build ADS 14.0.0-beta-76 (mongo-jdbc 1.2.6) |
No time estimate |
select sum(a) from nullcoll
go
--> returns 1 (correct)
select sum(b) from nullcoll
go
--> returns 6 (correct)
select sum(a), sum(b) from nullcoll
go
--> return 1, 3 (incorrect)