× Heads up!

Aqua Data Studio / nhilam

Follow
IDE for Relational Databases
×
slavakiev reported 2013-09-05T13:11:09Z  · tariqrahiman last modified 2015-07-07T20:11:23Z

COUNT() and IS NULL/IS NOT NULL do not work for arrays


Priority Low
Complexity Unknown
Component MongoSQL
Version 17.0
Tested Aqua Data Studio Aqua Data Studio 14.0.0-rc-8 Build #: 33812 on Ubuntu 12.04( Mongo DB 2.4.3)
Realisation of COUNT( ) and  IS NULL/NULL for arrays is wrong:
 
drop collection arrnull
go
insert into arrnull(a,b) values([1,null],1)
go
insert into arrnull(a,b) values([null,3],2)
go
insert into arrnull(a,b) values([null,null],3)
go
insert into arrnull(a,b) values([],4)
go
insert into arrnull(a,b) values(null,5)
go
insert into arrnull(b) values(6)
go
 
1)  select count(a) as cnt from arrnull
--wrong from SQL point of view
--cnt
--1
go
 
2) select count(a) as cnt,a from arrnull group by a
--correct from SQL point of view
--cnt a
--0       (null)
--1       [  ]
--1       [  null ,  null  ]
--1       [  null , 3 ]
--1       [ 1,  null  ]
--[ { "$group" : { "_id" : '$a', "cnt" : { "$sum" : { "$cond" : [ { "$or" : [ '$a', { "$eq" : [ '$a', 0 ] } ] }, 1, 0 ] } } } }, { "$project" : { "_id" : 0, "a" : '$_id', "cnt" : 1 } } ]
go
 
3) select a,b from arrnull where a is null group by a,b
--wrong from SQL point of view( see result of count)
--a                    b
----                   ---
--[ 1,  null  ]       1
--[  null , 3 ]       2
--[  null ,  null  ] 3
--(null)              5
go
 
4) select a,b from arrnull where a is not null group by a,b
--wrong from SQL point of view( see result of count)
--a       b
----      ----
--[  ]     4
go
 
5) select count(a[0]) as cnt from arrnull 
--cnt
--0
--work correct 
--db.arrnull.find({$and:[ { "a.0" : { "$exists" : true,  $not:{$type:10} } }]}).count()
go
 
6) select a[0] as a0,count(a[0]) as cnt from arrnull group by a0
--a0 cnt
--(null) 0
--[  ]    4
go
 
7) select a[0] ,b from arrnull where a[0] is null 
--works correct
--a                  b
----                 ---
--[  null ]         2
--[  null ]       3
go
 
8) --but count wrong
select count(a[0]) from arrnull where a[0] is null
--cnt
----
--0
--should be 2
go
 
So first of all $ne:null should be changed on $not:{$type:10} this will solve problems with elements of arrays and IS NULL/IS NOT NULL 
and then can be 2 decissions:
1. Perform all operations of COUNT( ), IS NULL/IS NOT NULL through aggregation framework and get correct results from SQL point of view
2. Change realization of COUNT( ) with GROUP BY in way as it is done for regular one. But thus we will have not same results as in SQL. Generaly it is not so important because we already have some other operations with NULLs differ than in SQL     
1 attachment

Issue #9905

Closed
Won't Fix
Resolved 2015-04-24T19:08:03Z
 
 
Completion
No due date
No fixed build
No time estimate

About AquaClusters Privacy Policy Support Version - 19.0.2-4 AquaFold, Inc Copyright © 2007-2017