Forum Discussion
Indeed, there’s a Pivot snap, but that does the opposite of what you’re looking to do. Until such a snap exists, you can do this using a GroupByN snap and the expression language. If you add a GroupByN snap with a “Group Size” of zero, it will collect all of the incoming data into a single document. You can then follow that up with a Mapper that has this expression:
{}.extend($group.map(x => [x.Category, x.DataType]))
The extend() method will construct a new object containing the key/value pairs returned by the $group.map()
call.
Here’s a screenshot:
Here’s an export of this pipeline:
TransposeExample_2018_08_15.slp (6.8 KB)
Thanks Team!
It is working fine. 😄
- vsunilbabu6 years agoNew Contributor II
Hello everybody,
Can someone help me with exactly the opposite.
to
Also, in my challenge, the names of columns and number of columns will change(dynamic).
Thanks in advance,
Sunil- tstack6 years agoFormer Employee
If this wasn’t the case, I would suggest the Pivot snap. But, since it is, I think you’ll need to use an expression like the following:
$.entries().map(col => { Category: col[0], DataType: col[1] })
The
entries()
method will return a list of all the properties in the input document as pairs. The.map()
method and callback then turn the pairs into their own objects. You can then follow up with a JSONSplitter to turn the array output by that expression into a series of documents.Here’s an example pipeline that does that:
PivotProperties_2019_09_16.slp (6.9 KB)