cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Generate multiple files based on single column

Surendar
Contributor

I need to generate multiple files based on category, say for example, The table having list of columns and category column have multiple values.

Category:

  • milk_products
  • water_products
  • oil_products
  • rice_products

So from above category, I need to generate 4 files with its records in separate files dynamically in Snap Logic.

Can any one have any idea/suggestion how to achieve this?

6 REPLIES 6

tstack
Former Employee

What is the format of these files (e.g. CSV, JSON, XML, โ€ฆ)?

Any files either CSV or JSON files. by default is CSV

can you post the sample structure? There can be many ways of doing it!

tstack
Former Employee

Iโ€™m attaching an example pipeline that generates a separate JSON file for each document in a particular category:

FilePerCategory_2017_11_17.slp (7.0 KB)

Hereโ€™s some detail on whatโ€™s going on in the pipeline:

  • The Group By Fields Snap can be used to do the category grouping (make sure the input documents are sorted by category, otherwise I think youโ€™ll get multiple outputs for the same category).
  • Once the categories are grouped together in a single document, you can write them out to a file using the JSON Formatter. This JSON Formatter has the โ€˜Format each documentโ€™ option checked, which means that a separate binary output document will be generated for each input document. We want this since every input document will be the collection of items in the category and thatโ€™s what we want in each file. In addition, we set the โ€˜Contentโ€™ property to โ€˜$groupโ€™ since that contains the array of items in the category. The last thing for the formatter is to compute the file name based on the category using the โ€˜Binary Header Propertiesโ€™ to set the โ€˜content-locationโ€™ property in the binary output document header.
  • Finally, thereโ€™s a File Writer that writes out a file using the name as found in the โ€˜content-locationโ€™ property.