The expression language is extremely confusing. Query variants exposes one top-level object,
Aggregable. Aggregables are unordered distributed collections of things, like rows or columns of the VDS or its annotation tables.
The most confusing thing about them is that they carry an implicit “scope” around – extra variables you can access for free and can’t map away. In query_variants, the
variants aggregable is an
Aggregable[Variant] that has
va in its scope.
Aggregables support ‘aggregator’ operations like count, collect, stats, counter, and more. These functions work on the elements in the aggregable, so usually you’ll need to change the elements with
flatMap. The difference between
flatMap is that
map changes elements one-to-one, while
flatMap can change the number of elements in the Aggregable because the function supplied returns an array.
For the contigs, you’ll want to use
flatMap. if you swap that out in your second line, it’ll work!
The first is incorrect because
v is not a top-level variable in query_variants.