writeCsv Documentation
Overview
The writeCsv function is a component of the Vantage analytics and data platform specifically designed to facilitate the process of converting a dataset into CSV format and saving it to a specified location in Google Drive. This functionality is crucial for users who need to export data for reporting, sharing, or further analysis.
Purpose
The primary purpose of the writeCsv function is to enable users to take structured dataset input, transform it into a CSV file, and write that file directly to a designated folder within Google Drive. This automation supports efficient data handling and sharing across different platforms.
Settings
The writeCsv component includes several configurable settings that control its behavior and output.
1. fileName
- Input Type: String
- Description: This setting defines the name of the CSV file that will be saved in Google Drive. Changing the file name will affect how the file appears in the specified location, allowing users to organize their exports more effectively.
- Default Value:
'export.csv'- If no custom name is specified, the default file name will be used.
2. subfolder
- Input Type: String (optional)
- Description: This setting allows users to specify a subfolder in which the CSV file should be saved. If this setting is provided, the file will be created in the designated subfolder path within the main Intuidy folder on Google Drive. If omitted, the file will be saved at the root level.
- Default Value: Not specified (optional setting)
Additional Configurations
Beyond the configurable settings, the function also internally defines a few properties:
-
mimeType:
'text/csv'- This specifies the file format being written, informing Google Drive that the output is a CSV file.
-
format:
'csv'- This reaffirms the format type the output should adhere to, consistent with the MIME type.
-
asSpreadsheet:
false- This boolean indicates that the output should be treated as a standard CSV file instead of a Google Sheets spreadsheet. Changing this to
truewould alter how the file is handled upon writing.
- This boolean indicates that the output should be treated as a standard CSV file instead of a Google Sheets spreadsheet. Changing this to
How It Works
The writeCsv function operates asynchronously, taking three parameters: inputs, config, and context.
-
Inputs: This function expects an array of objects as input. Each object in this array represents a data row, and the keys of the object represent the column names for the CSV.
-
Config: The
configparameter allows the customization of settings such asfileNameandsubfolder. The default values will be used if these are not explicitly provided. -
Context: This parameter is used for any additional contextual information required during the execution of the file write operation.
The function then calls the writeFileNode to handle the actual file writing process, passing the combined configuration and the provided dataset.
Expected Data
The writeCsv function expects a well-structured input array that conforms to the following definition:
- Data Format: Array of objects
- Example:
json
[ {"name": "John Doe", "age": 30, "city": "New York"}, {"name": "Jane Smith", "age": 25, "city": "Los Angeles"} ]
Each object represents a row in the final CSV file, with keys corresponding to column headers.
Use Cases & Examples
Use Cases
-
Data Export for Reporting: A marketing team may want to export customer data for quarterly reporting. By using
writeCsv, they can create a CSV of their customer database and share it with stakeholders. -
Backup Data: A data analyst may need to back up datasets routinely. Using
writeCsv, they can automate the export of critical project datasets to secure storage in Google Drive. -
Integration with Other Tools: Teams using external analytics tools might require data in CSV format to conduct further analysis. The
writeCsvfunction enables seamless preparation and migration of data across platforms.
Example Configuration
Scenario
A company needs to export employee records for a quarterly performance review and save the file in a subfolder named "Performance Reviews".
Configuration
Sample configuration for achieving this might look like:
const inputs = [
{"name": "Alice Johnson", "department": "HR", "performanceScore": 85},
{"name": "Bob Lee", "department": "Finance", "performanceScore": 90}
];
const config = {
fileName: 'Q1_Performance_Review.csv',
subfolder: 'Performance Reviews'
};
const context = {}; // Any necessary context information
// Function Call
await writeCsvNode({ inputs, config, context });In this example, the file Q1_Performance_Review.csv will be saved within the "Performance Reviews" subfolder on Google Drive, containing the performance data of the employees in CSV format.