@@ -124,5 +124,91 @@ describe("Queries", function() {
124124 "second batch element should be doc3"
125125 ) ;
126126 } ) ;
127+
128+ describe ( "SUM query iterator" , function ( ) {
129+ this . timeout ( process . env . MOCHA_TIMEOUT || 30000 ) ;
130+
131+ it ( "returns undefined sum with null value in aggregator" , async function ( ) {
132+ const container = await getTestContainer (
133+ "Validate QueryIterator Functionality" ,
134+ undefined ,
135+ {
136+ throughput : 10100 ,
137+ partitionKey : "/id"
138+ }
139+ ) ;
140+ await container . items . create ( { id : "5eded6f8asdfasdfasdfaa21be0109ae34e29" , age : 22 } ) ;
141+ await container . items . create ( { id : "5eded6f8a21be0109ae34e29" , age : 22 } ) ;
142+ await container . items . create ( { id : "5edasdfasdfed6f8a21be0109ae34e29" , age : null } ) ;
143+ await container . items . create ( { id : "5eded6f8a2dd1be0109ae34e29" , age : 22 } ) ;
144+ await container . items . create ( { id : "AndersenFamily" } ) ;
145+ await container . items . create ( { id : "1" } ) ;
146+
147+ const queryIterator = container . items . query ( "SELECT VALUE SUM(c.age) FROM c" ) ;
148+ const { resources : sum } = await queryIterator . fetchAll ( ) ;
149+ assert . equal ( sum . length , 0 ) ;
150+ } ) ;
151+ it ( "returns undefined sum with false value in aggregator" , async function ( ) {
152+ const container = await getTestContainer (
153+ "Validate QueryIterator Functionality" ,
154+ undefined ,
155+ {
156+ throughput : 10100 ,
157+ partitionKey : "/id"
158+ }
159+ ) ;
160+ await container . items . create ( { id : "5eded6f8asdfasdfasdfaa21be0109ae34e29" , age : 22 } ) ;
161+ await container . items . create ( { id : "5eded6f8a21be0109ae34e29" , age : 22 } ) ;
162+ await container . items . create ( { id : "5edasdfasdfed6f8a21be0109ae34e29" , age : false } ) ;
163+ await container . items . create ( { id : "5eded6f8a2dd1be0109ae34e29" , age : 22 } ) ;
164+ await container . items . create ( { id : "AndersenFamily" } ) ;
165+ await container . items . create ( { id : "1" } ) ;
166+
167+ const queryIterator = container . items . query ( "SELECT VALUE SUM(c.age) FROM c" ) ;
168+ const { resources : sum } = await queryIterator . fetchAll ( ) ;
169+ assert . equal ( sum . length , 0 ) ;
170+ } ) ;
171+ it ( "returns undefined sum with empty array value in aggregator" , async function ( ) {
172+ const container = await getTestContainer (
173+ "Validate QueryIterator Functionality" ,
174+ undefined ,
175+ {
176+ throughput : 10100 ,
177+ partitionKey : "/id"
178+ }
179+ ) ;
180+ await container . items . create ( { id : "5eded6f8asdfasdfasdfaa21be0109ae34e29" , age : 22 } ) ;
181+ await container . items . create ( { id : "5eded6f8a21be0109ae34e29" , age : 22 } ) ;
182+ await container . items . create ( { id : "5edasdfasdfed6f8a21be0109ae34e29" , age : [ ] } ) ;
183+ await container . items . create ( { id : "5eded6f8a2dd1be0109ae34e29" , age : 22 } ) ;
184+ await container . items . create ( { id : "AndersenFamily" } ) ;
185+ await container . items . create ( { id : "1" } ) ;
186+
187+ const queryIterator = container . items . query ( "SELECT VALUE SUM(c.age) FROM c" ) ;
188+ const { resources : sum } = await queryIterator . fetchAll ( ) ;
189+ assert . equal ( sum . length , 0 ) ;
190+ } ) ;
191+ it ( "returns a valid sum with undefined value in aggregator" , async function ( ) {
192+ const container = await getTestContainer (
193+ "Validate QueryIterator Functionality" ,
194+ undefined ,
195+ {
196+ throughput : 10100 ,
197+ partitionKey : "/id"
198+ }
199+ ) ;
200+ await container . items . create ( { id : "5eded6f8asdfasdfasdfaa21be0109ae34e29" , age : 22 } ) ;
201+ await container . items . create ( { id : "5eded6f8a21be0109ae34e29" , age : 22 } ) ;
202+ await container . items . create ( { id : "5edasdfasdfed6f8a21be0109ae34e29" , age : undefined } ) ;
203+ await container . items . create ( { id : "5eded6f8a2dd1be0109ae34e29" , age : 22 } ) ;
204+ await container . items . create ( { id : "AndersenFamily" } ) ;
205+ await container . items . create ( { id : "1" } ) ;
206+
207+ const queryIterator = container . items . query ( "SELECT VALUE SUM(c.age) FROM c" ) ;
208+ const { resources : sum } = await queryIterator . fetchAll ( ) ;
209+ assert . equal ( sum . length , 1 ) ;
210+ assert . equal ( sum [ 0 ] , 66 ) ;
211+ } ) ;
212+ } ) ;
127213 } ) ;
128214} ) ;
0 commit comments