Tested on Aqua Data Studio 14.0-alpha-23 Build #: 32551 on Ubuntu 12.04( Mongo DB 2.4.3) and Windows XP ( Mongo DB 2.0.9).
When using operations in the WHAT clause in SELECT statement with GROUP BY "Don't know how to aggregate" error appears e.g.:
The equiv MongoShell commands are wrong, because on the MongoSQL the GROUP BY clause is present, while in the MongoShell the $group operator is missing.
e.g.
select (valuation * valuation) as mul from baseball group by valuation
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$multiply:["$valuation","$valuation"]}}})
which returns null for the "mul" field because there is no such "valuation" field after aggregating the collection based on the "valuation" field as grouping key (i.e. the result of the $group pipeline operator).
Also, $and and $or are wrongly used in the last two examples: these are boolean aggregation operators, not bitwise ones.
The MongoSQL equiv for your MongoShell example
db.baseball.aggregate({$project:{"valuation":1,"mul":{$multiply:["$valuation","$valuation"]}}})
would be:
select valuation, (valuation * valuation) as mul from baseball
Emil, you are right - my mistake. Because e.g. valuation+valuation is not in GROUP BY. But these statements can be corrected if I put expressions inside aggregate function e.g. MAX(). For example:
SELECT city,max(valuation+valuation) FROM baseball GROUP BY city. Anyway ADS gives error:
db.baseball.aggregate({$project:{"sm":{$add:["$valuation","$valuation"]},city:1}},{$group:{_id:"$city","mn":{$max:"$sm"}}})
The same is for other operations:*,/,-,%
Emil, you are right - my mistake. Because e.g. valuation+valuation is not in GROUP BY. But these statements can be corrected if I put expressions inside aggregate function e.g. MAX(). For example:
SELECT city,max(valuation+valuation) FROM baseball GROUP BY city. Anyway ADS gives error:
db.baseball.aggregate({$project:{"sm":{$add:["$valuation","$valuation"]},city:1}},{$group:{_id:"$city","mn":{$max:"$sm"}}})
The same is for other operations:*,/,-,%
Verified in Aqua Data Studio 14.0.0-beta-55 Build #: 33118
Verified in Aqua Data Studio 14.0.0-beta-55 Build #: 33118
Tested Aqua Data Studio Aqua Data Studio 14.0.0-beta-74 Build #: 33340 on Ubuntu 12.04( Mongo DB 2.4.3) and Windows XP ( Mongo DB 2.0.9).
As ticket states next statements give error :
select (valuation * valuation) as mul from baseball group by valuation
go
-- Don't know how to aggregate
select (valuation % valuation) as mul from baseball group by valuation
select (valuation / valuation) as mul from baseball group by valuation
Emil wrote above:
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$multiply:["$valuation","$valuation"]}}})
which returns null for the "mul" field because there is no such "valuation" field after aggregating the collection based on the "valuation" field as grouping key (i.e. the result of the $group pipeline operator).
It is just necessary to use "$_id" column in ending $project to have correct results:
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$multiply:["$_id","$_id"]}}})
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$mod:["$_id","$_id"]}}})
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$divide:["$_id","$_id"]}}})
Tested Aqua Data Studio Aqua Data Studio 14.0.0-beta-74 Build #: 33340 on Ubuntu 12.04( Mongo DB 2.4.3) and Windows XP ( Mongo DB 2.0.9).
As ticket states next statements give error :
select (valuation * valuation) as mul from baseball group by valuation
go
-- Don't know how to aggregate
select (valuation % valuation) as mul from baseball group by valuation
select (valuation / valuation) as mul from baseball group by valuation
Emil wrote above:
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$multiply:["$valuation","$valuation"]}}})
which returns null for the "mul" field because there is no such "valuation" field after aggregating the collection based on the "valuation" field as grouping key (i.e. the result of the $group pipeline operator).
It is just necessary to use "$_id" column in ending $project to have correct results:
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$multiply:["$_id","$_id"]}}})
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$mod:["$_id","$_id"]}}})
db.baseball.aggregate({$group: {_id:"$valuation"}}, {$project:{"mul":{$divide:["$_id","$_id"]}}})
Arithmetic expressions are now supported inside the WHAT clause, when GROUP BY is present.
Arithmetic expressions are now supported inside the WHAT clause, when GROUP BY is present.
Verified in Aqua Data Studio Aqua Data Studio 14.0.0-beta-82 Build #: 33525 on Ubuntu 12.04( Mongo DB 2.4.3)
Verified in Aqua Data Studio Aqua Data Studio 14.0.0-beta-82 Build #: 33525 on Ubuntu 12.04( Mongo DB 2.4.3)
Issue #9172 |
Closed |
Fixed |
Resolved |
Completion |
No due date |
Fixed Build ADS 14.0.0-beta-82 (mongo-jdbc 1.2.7) |
No time estimate |
The equiv MongoShell commands are wrong, because on the MongoSQL the GROUP BY clause is present, while in the MongoShell the $group operator is missing.
e.g.
which returns null for the "mul" field because there is no such "valuation" field after aggregating the collection based on the "valuation" field as grouping key (i.e. the result of the $group pipeline operator).
Also, $and and $or are wrongly used in the last two examples: these are boolean aggregation operators, not bitwise ones.
The MongoSQL equiv for your MongoShell example
would be: