flow
Search…
sum
Using the sum reduction strategy
sum reduces two numbers or integers by adding their values.
1
collections:
2
- name: example/reductions/sum
3
schema:
4
type: object
5
reduce: { strategy: merge }
6
properties:
7
key: { type: string }
8
value:
9
# Sum only works with types "number" or "integer".
10
# Others will throw an error at build time.
11
type: number
12
reduce: { strategy: sum }
13
required: [key]
14
key: [/key]
15
16
tests:
17
"Expect we can sum two numbers":
18
- ingest:
19
collection: example/reductions/sum
20
documents:
21
- { key: "key", value: 5 }
22
- { key: "key", value: -1.2 }
23
- verify:
24
collection: example/reductions/sum
25
documents:
26
- { key: "key", value: 3.8 }
Copied!
Last modified 3mo ago
Copy link