The Data Connector for Google Cloud Storage enables import of the contents of .tsv and .csv files stored in your GCS bucket. For export Integration, see Google Cloud Storage Export Integration.
- Basic knowledge of Treasure Data
- An existing Google Service Account
- Generate and obtain a JSON key file from Google Developers Console. See Generating a service account credential.
If your security policy requires IP whitelisting, you must add Treasure Data's IP addresses to your allowlist to ensure a successful connection.
Please find the complete list of static IP addresses, organized by region, at the following link:
https://api-docs.treasuredata.com/en/overview/ip-addresses-integrations-result-workers/
When you configure a data connection, you provide authentication to access the integration. In Treasure Data, you configure the authentication and then specify the source information.
Open TD Console.
Navigate to Integrations Hub > Catalog
Search and select Google Cloud Storage.

The following dialog opens.

Create a New Google Cloud Storage Connector
Set the following parameters:
| Parameters | Description |
|---|---|
| Authentication mode | Select a JSON keyfile. This method uses the JSON keyfile generated from the Google Developers Console. |
| JSON Keyfile | Copy and paste the contents of the JSON keyfile generated from the Google Developers Console in this field. |
| Application Name | Treasure Data GCS Output is the default value. As this is an arbitrary client name associated with API requests, you can leave the default value (Treasure Data GCS Output). |
- Type a name for your connection.
- Select Done.
After creating the authenticated connection, you are automatically taken to Authentications.
- Search for the connection you created.
- Select New Source.
- Type a name for your Source in the Data Transfer field**.**
- Click Next.

- Select Next.
- The Source Table dialog opens. Edit the following parameters

| Parameters | Description |
|---|---|
| Bucket | Google Cloud Storage bucket name (Ex. your_bucket_name) |
| Path Prefix | Prefix of target keys. (Ex. logs/data_) |
| Path Regex | regexp to match file paths. If a file path doesn’t match with this pattern, the file is skipped. (Ex. .csv$ # in this case, a file is skipped if its' path doesn’t match with this pattern.) |
| Start after path | Inserts last_path parameter so that the first execution skips files before the path. (Ex. logs/data_20170101.csv) |
| Incremental | Enables incremental loading. If incremental loading is enabled, config diff for the next execution will include last_path parameter so that next execution skips files before the path. Otherwise, last_path will not be included. |
Example: CloudFront Log
Amazon CloudFront is a web service that speeds up the distribution of your static and dynamic web content. You can configure CloudFront to create log files that contain detailed information about every user request that CloudFront receives. If you enable logging, you can save CloudFront log files, shown as follows:
[your_bucket] - [logging] - [E231A697YXWD39.2017-04-23-15.a103fd5a.gz]
[your_bucket] - [logging] - [E231A697YXWD39.2017-04-23-15.b2aede4a.gz]
[your_bucket] - [logging] - [E231A697YXWD39.2017-04-23-16.594fa8e6.gz]
[your_bucket] - [logging] - [E231A697YXWD39.2017-04-23-16.d12f42f9.gz]In this case, the Source Table setting should be as shown:
- Bucket: your_bucket
- Path Prefix: logging/
- Path Regex: .gz$ (Not Required)
- Start after path: logging/E231A697YXWD39.2017-04-23-15.b2aede4a.gz (Assuming that you want to import the log files from 2017-04-23-16.)
- Incremental: true (If you want to schedule this job.)
- Select Next.
- The Data Settings page opens.
Optionally, edit the data settings or skip this page of the dialog.


| Parameters | Description |
|---|---|
| Type | Following types are supported: - Avro - CSV - json - Query String |
| Default timezone | Changes time zone of timestamp columns if the value itself doesn’t include time zone. |
| Total file count limit | Maximum number of files to read. (optional) |
| Schema Settings | You can name the columns and set the data type. TD parses a value as a specified data type. And then, it stores after converting to Treasure Data schema. - boolean - long - timestamp: will be imported as String type at Treasure Data (Ex. 2017-04-01 00:00:00.000) - double - string - json |
You can see a preview of your data before running the import by selecting Generate Preview. Data preview is optional and you can safely skip to the next page of the dialog if you choose to.
- Select Next. The Data Preview page opens.
- If you want to preview your data, select Generate Preview.
- Verify the data.
For data placement, select the target database and table where you want your data placed and indicate how often the import should run.
Select Next. Under Storage, you will create a new or select an existing database and create a new or select an existing table for where you want to place the imported data.
Select a Database > Select an existing or Create New Database.
Optionally, type a database name.
Select a Table> Select an existing or Create New Table.
Optionally, type a table name.
Choose the method for importing the data.
- Append (default)-Data import results are appended to the table. If the table does not exist, it will be created.
- Always Replace-Replaces the entire content of an existing table with the result output of the query. If the table does not exist, a new table is created.
- Replace on New Data-Only replace the entire content of an existing table with the result output when there is new data.
Select the Timestamp-based Partition Key column. If you want to set a different partition key seed than the default key, you can specify the long or timestamp column as the partitioning time. As a default time column, it uses upload_time with the add_time filter.
Select the Timezone for your data storage.
Under Schedule, you can choose when and how often you want to run this query.
- Select Off.
- Select Scheduling Timezone.
- Select Create & Run Now.
- Select On.
- Select the Schedule. The UI provides these four options: @hourly, @daily and @monthly or custom cron.
- You can also select Delay Transfer and add a delay of execution time.
- Select Scheduling Timezone.
- Select Create & Run Now.
After your transfer has run, you can see the results of your transfer in Data Workbench > Databases.
For sample workflows importing data from GCS, view the Treasure Boxes.
Before setting up the connector, install the most current TD Toolbelt.
The Data Connector supports parsing of "boolean", "long", "double", "string", and "timestamp" types.
Prepare seed.yml , with your JSON keyfile. You must also specify bucket name and target file name (or prefix for multiple files).
in:
type: gcs
bucket: sample_bucket
path_prefix: path/to/sample_file # path the the *.csv or *.tsv file on your GCS bucket
auth_method: json_key
json_keyfile:
content: |
{
"private_key_id": "1234567890",
"private_key": "-----BEGIN PRIVATE KEY-----\nABCDEF",
"client_id": "...",
"client_email": "...",
"type": "service_account"
}
out:
mode: appendThe Data Connector for Google Cloud Storage imports all files that match a specified prefix. (e.g. path_prefix: path/to/sample_ –> path/to/sample_201501.csv.gz, path/to/sample_201502.csv.gz, …, path/to/sample_201505.csv.gz)
Use connector:guess. This command automatically reads the target file, and intelligently guesses the file format.
td connector:guess seed.yml -o load.ymlIf you open up load.yml, you see the guessed file format definitions including file formats, encodings, column names, and types.
in:
type: gcs
bucket: sample_bucket
path_prefix: path/to/sample_file
auth_method: json_key
json_keyfile:
content: |
{
"private_key_id": "1234567890",
"private_key": "-----BEGIN PRIVATE KEY-----\nABCDEF",
"client_id": "...",
"client_email": "...",
"type": "service_account"
}
decoders:
- {type: gzip}
parser:
charset: UTF-8
newline: CRLF
type: csv
delimiter: ','
quote: '"'
escape: ''
skip_header_lines: 1
columns:
- name: id
type: long
- name: company
type: string
- name: customer
type: string
- name: created_at
type: timestamp
format: '%Y-%m-%d %H:%M:%S'
out:
mode: appendYou can preview how the system parses the file by using the preview command.
td connector:preview load.ymlThe guess command needs over 3 rows and 2 columns in source data file, because it guesses column definition using sample rows from source data.
If the system detects your column name or column type unexpectedly, modify load.yml directly and preview again.
The preview command will download one file from the specified bucket and display the results from that file. This may cause a difference in results from the preview and issue commands.
Submit the load job. It may take a couple of hours depending on the size of the data. Users need to specify the database and table where their data is stored.
It’s also recommended to specify --time-column option since Treasure Data’s storage is partitioned by time. If the option is not given, the Data Connector will choose the first long or timestamp column as the partitioning time. The type of the column specified by --time-column must be either of long or timestamp type.
If your data doesn’t have a time column, you may add it using the add_time filter option. More details at add_time filter plugin.
td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column created_atThe preceding command assumes you have already created a database(td_sample_db) and a table(td_sample_table). If the database or the table do not exist in TD, this command will not succeed so create the database and table manually or use --auto-create-table option with td connector:issue command to auto-create the database and table:
td connector:issue load.yml --database td_sample_db --table td_sample_table --time-column created_at --auto-create-tableThe Data Connector does not sort records server-side. To use time-based partitioning effectively, sort records in files beforehand.
If you have a field called time, you don’t have to specify the --time-column option.
td connector:issue load.yml --database td_sample_db --table td_sample_tableYou can schedule a periodic Data Connector execution for incremental Google Cloud Storage file imports. TD manages the scheduler carefully to ensure high availability. By using this feature, you no longer need a cron daemon on your local data center.
For the scheduled import, the Data Connector for Google Cloud Storage imports all files that match with the specified prefix (e.g. path_prefix: path/to/sample_ –> path/to/sample_201501.csv.gz, path/to/sample_201502.csv.gz, …, path/to/sample_201505.csv.gz) at first and remembers the last path (path/to/sample_201505.csv.gz) for the next execution.
On the second and subsequent runs, it will only imports files that comes after the last path in alphabetical (lexicographic) order. (path/to/sample_201506.csv.gz, …)
A new schedule can be created using the td connector:create command. The following are required: the name of the schedule, the cron-style schedule, the database and table where their data will be stored, and the Data Connector configuration file.
td connector:create daily_import "10 0 * * *" td_sample_db td_sample_table load.ymlIt’s also recommended to specify the --time-column option, since Treasure Data’s storage is partitioned by time.
td connector:create daily_import "10 0 * * *" td_sample_db td_sample_table load.yml --time-column created_atThe cron parameter also accepts three special options: @hourly, @daily and @monthly. By default, schedule is setup in UTC timezone. You can set the schedule in a timezone using -t or --timezone option. The --timezone option only supports extended timezone formats like 'Asia/Tokyo', 'America/Los_Angeles' etc. Timezone abbreviations like PST, CST are *not* supported and may lead to unexpected schedules.
You can see the list of currently scheduled entries by running the command td connector:list.
$ td connector:list