Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Dataform: Loading data from local CSV file

I want to be able to load data from a local csv file to a Bigquery table (i.e similar to the dbt <URL removed by staff> command) and keep the csv file version controlled in the Dataform repository. If the data is stored in GCS this is possible by using an operation (related post) but I would ideally like to do something along the lines of the approach in this post, i.e running a js function to load the csv data and then declaring the table using `declare` afterwards (see sample code below). Is this in any way possible using `declare` or `operate` ? I realize I could just execute my js method using node, but I want the creation to be part of the Dataform execution.

 

The below code fails to compile with the error `t.target.name.includes is not a function`, other rewrite attempts also fail to compile with the error `Failed to resolve events`. 

```

async function main(
datasetId,
tableId,
filename
) {
const {
BigQuery
} = require('@google-cloud/bigquery');
const bigquery = new BigQuery({ projectId: "my-project" });
async function loadLocalFile() {
const [job] = await bigquery
.dataset(datasetId)
.table(tableId)
.load(filename);

console.log(`Job ${job.id} completed.`);
}
await loadLocalFile();
return tableId
};

const table = main("my_dataset", "my_table", "data/my_data.csv")
declare({
schema: "my_dataset",
name: table,
});
```
0 1 561
1 REPLY 1

Hello,

Thank you for contacting the Google Cloud Community.

I have gone through your reported issue, however it seems like this is an issue observed specifically at your end. It would need more specific debugging and analysis. To ensure a faster resolution and dedicated support for your issue, I kindly request you to file a support ticket by clicking here. Our support team will prioritize your request and provide you with the assistance you need.

For individual support issues, it is best to utilize the support ticketing system. We appreciate your cooperation!