Trillo Workbench Lessons
  • Introduction
    • Sample Application
  • Introduction to Lessons
    • IDE Lessons
    • Annotated Directory Structure
  • New classes using workbench UI
  • Save many records into tables using the workbench UI
  • New function using Workbench UI
  • Introduction to Code Lessons
    • Anatomy of Trillo Function
  • Begin Code Lessons
    • Paginated list
    • Pagination using SQL Query
    • DataIterator
    • Read file from cloud storage bucket
    • Generating signed URL for a file download
    • Import a CSV file from bucket into BigQuery
    • Query a dataset of BigQuery
    • Using an Document AI Processor
    • Chat using GenAI
    • Function calling another function
    • Accessing Runtime Context
    • Write a workflow (pipeline for data processing)
  • Appendixes
    • ServerlessFunction
    • Map, List and Tree
    • Logs and Audit Logs
    • DataRequest Class
    • DataResponse Class
    • DataIterator Class
    • Result
Powered by GitBook
On this page
  1. Begin Code Lessons

Import a CSV file from bucket into BigQuery

This section describes how to import a csv file from a Google cloud storage bucket into BigQuery

Code: /lessons/Import_a_CSV_file_from_Bucket_into_BigQuery

In this example, the function code accepts the following parameters:

  1. datasetName: the name of BigQuery data set.

  2. tableName: the table in the data set.

  3. schema: table schema (to map CSV file onto the records).

  4. sourceUri: URL of the file on the bucket.

  5. numberOfRowsToSkip: number of rows to skip, default being 1

It imports the contents of the CSV into the BigQuery table and returns a success/failed response.

Prerequisite

In this lesson it is assumed that the CSV file exists in the bucket

Steps

  1. Create a new function called ImportCSVFileFromBucketIntoBigQuery.java.

  2. Upload a CSV file to the GCS bucket having customer details.

  3. Create a BigQuery table for a customer with similar columns as the CSV.

  4. Set parameters as the datasetName, tableName, sourceUri, and schema.

  5. Call BigQueryApi.importCSVbyURIIntoTable function with the above parameters.

  6. Return the successful/failed response as a Result.

PreviousGenerating signed URL for a file downloadNextQuery a dataset of BigQuery

Last updated 1 year ago