cancel
Showing results for 
Search instead for 
Did you mean: 

Converting value of input schema to distinct columns

darshthakkar
Valued Contributor

Hi Team,

I’m reading a text file and wanted to fetch DISTINCT columns out of the data itself, screenshot below for your reference.

.txt file:
image

When I read the above data in snaplogic, the format is:
image

Tried with $.merge(), GroupByN, CSV parse (contains headers) and Aggregrate (Concat) but didn’t find any luck.

Any suggestions over here?
Thank you.

Regards,
Darsh

2 ACCEPTED SOLUTIONS

koryknick
Employee
Employee

Assuming it is always 8 properties, here is an example pipeline
Community 16940 - Converting value to distinct columns_2023_06_20.slp (6.3 KB)
Community-16940.txt (177 Bytes)

View solution in original post

darshthakkar
Valued Contributor

Thank you @koryknick, the solution worked.
I happen to tweak the expression in the mapper a bit so that no extra spaces were observed:

image

Yes, the text file will always have “x” fields, it wouldn’t even go to x-1 or x+1.

Moreover, as there is no max value in a group size as per documentation, I can pretty much keep it to 100 for instance to handle the additional rows coming in the future. What are your thoughts?
Intentionally, kept 100 and not 99999999 as I’m not anticipating anything more than 8.

Thank you.

Regards,
Darsh

View solution in original post

10 REPLIES 10

darshthakkar
Valued Contributor

Desired Output:

Name: Darsh
City: Toronto
Province-State: Ontario
Population: 126723

Country: Canada
IPV4: cc1d3198da257e12dffff507be1faeea
Phone: 70025416
Total Population: 126723

where Name, City, etc. are columns and Darsh, Toronto, etc. are values.

koryknick
Employee
Employee

If you can guarantee that these same 8 fields are always present, you could do a Group By N of 8, then process the array into an object. If missing values would remove the line, it becomes a bit more complex and may require a Script snap to handle the contextual parsing of the input.

@koryknick - We can handle “n” no. of rows with Group Size as 0
image

I will modify my 50 to 0 now as 0 will handle all the incoming rows.

koryknick
Employee
Employee

Assuming it is always 8 properties, here is an example pipeline
Community 16940 - Converting value to distinct columns_2023_06_20.slp (6.3 KB)
Community-16940.txt (177 Bytes)