Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating column headers in CSV/TSV files using AWS Data Pipeline?

I'm creating CSV & TSV files using AWS Data Pipeline. The files are creating just fine, but I can't figure out how to create files with column headers.

At first, I expected the headers to generate automatically based on the SQL query I'm running to get the export. That didn't work, but was ok.

Then I added a list of column definitions to the "column" attribute of the DefaultDataFormat3 feature/node.

{
  "escapeChar": "\\",
  "name": "DefaultDataFormat3",
  "column": [
    "id INT",
    "field1 STRING",
    "field2 STRING"
  ],
  "columnSeparator": "|",
  "id": "DataFormatId_jEXqL",
  "type": "TSV",
  "recordSeparator": "\\n"
}

I still just get CSVs and TSVs with no header row in the export.

like image 948
T. Brian Jones Avatar asked Mar 10 '23 02:03

T. Brian Jones


1 Answers

I ran across a blog post explaining a solution for this. If you are using a query for your data you can add the column names as the first result:

SELECT 'firstName', 'lastName', 'email'
UNION ALL
SELECT firstName, lastName, email
FROM users
like image 184
MrHen Avatar answered Apr 08 '23 13:04

MrHen