cancel
Showing results for 
Search instead for 
Did you mean: 

Combine rows with the same RowNumber into one row

philliperamos
Contributor

Hi all, I have a table output with from a JSON generator that has its values in a separate row and column with the same Row Number. (see screenshot)
image
I’d like to combine those rows into one row with the same Row Number.
Any thoughts on how to go about doing this?

1 ACCEPTED SOLUTION

tstack
Former Employee

You are probably looking for the GroupByFields snap. That will allow you to group all of the input documents with the same Row number into a single output document. You can then use a Mapper to merge the resulting array of input documents together (if that’s what you’re after).

The expression to use in the Mapper would leverage the extend() method on Objects to construct a new object from its arguments. In this case, we’ll be using the spread operator (i.e. three dots) to specify that the array of input documents should be passed as individual arguments to the extend() method, like so:

{}.extend(...$group)

(Note: The {} just makes an empty object that will be used as the base for the extension.)

Here’s a pipeline that does the above:

CombineRows_2019_09_16.slp (7.3 KB)

View solution in original post

4 REPLIES 4

anubhav_nautiya
Contributor

Hi,

You can use an aggregate Snap on all the fields, and in the group by section use Row number, and you will get the desired result

Images below for reference.

image

image

Thanks Anub, this will work for 4 fields, but what if I have 200+ and if I want to dynamically set the column headings.
I’ve attached the same sample pipeline, that generates the table as shown before.
JsonToMapperToTable_2019_09_16.slp (13.1 KB)

tstack
Former Employee

You are probably looking for the GroupByFields snap. That will allow you to group all of the input documents with the same Row number into a single output document. You can then use a Mapper to merge the resulting array of input documents together (if that’s what you’re after).

The expression to use in the Mapper would leverage the extend() method on Objects to construct a new object from its arguments. In this case, we’ll be using the spread operator (i.e. three dots) to specify that the array of input documents should be passed as individual arguments to the extend() method, like so:

{}.extend(...$group)

(Note: The {} just makes an empty object that will be used as the base for the extension.)

Here’s a pipeline that does the above:

CombineRows_2019_09_16.slp (7.3 KB)

Thanks you @tstack ! That seems to do the trick!