You can use the KARTE Data Connector to import the contents of .tsv and .csv files stored in your Google Cloud Storage (GCS) bucket into Treasure Data.
Basic knowledge of Treasure Data
An existing Google Service Account
Use the TD Console to Create Your Connection
You can use the TD Console to configure your connection.
Create a New Connection
Go to Integrations Hub > Catalog and search. Select KARTE.
Create a New KARTE Connector
The following dialog opens.
Provide the required credentials. In the TD Console, you can use only a JSON key file to authenticate:
JSON key file: Copy and paste the contents of the JSON key file generated from the Google Developers Console into this field.
Application Name: KARTE is the default value. KARTE is the Treasure Data chosen name for this connector.
Specify a name for your data connector and select Done.
Import KARTE Data to Treasure Data
The Connections page displays. Select New Transfer.
The following sections provide instructions to help you fetch, preview, transfer, schedule, and review details.
You need to register the information that you would like to ingest:
Bucket. Google Cloud Storage bucket name (Example: your_bucket_name).
Path Prefix. The prefix for target keys. (Example: logs/data_).
Path Regex. Specify the regexp to match file paths. If a file path doesn’t match with this pattern, the file is skipped. (Example: In the case of .csv$ #, a file is skipped if its path doesn’t match with this pattern.).
Start after path. Inserts the last_path parameter so that the first execution skips files before the path. (Example: logs/data_20170101.csv).
Incremental. Enables incremental loading. If incremental loading is enabled, the config diff for the next execution will include the last_path parameter and the next execution skips files before the path. Otherwise, last_path will not be included.
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:
In this case, Fetch from setting should be as follows:
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 logfiles from 2017-04-23-16.)
Incremental: true (if you want to schedule this job.)
You’ll see a preview of your data. For more information on how data preview works, review About Data Preview.
To make changes, such as set specified column name, select Advanced Settings otherwise, select Next.
Advanced Settings allow you to edit properties. The following properties are available:
Default timezone. Changes the time zone of timestamp columns if the value itself doesn’t include time zone.
Name. Changes the name of the column. The column name supports lowercase alphabets, numbers, and “_” only.
Type. Type parses a value as a specified type and then stores the type after converting to TreasureData schema.
timestamp: Imported as string type at TreasureData (Ex. 2017-04-01 00:00:00.000)
Total file count limit. The maximum number of files to read. (optional)
Choose an existing or create a new database and table for the import.
Mode: Append or Replace. Select whether to append records to an existing table or replace your existing table.
Partition Key Seed: Choose the long or timestamp column as the partitioning time. As the default time column, it uses the upload_time with the add_time filter.
You can specify a one-time transfer, or you can schedule an automated recurring transfer.
Use the following parameters to set your schedule:
Once now. Run the job one time.
Schedule. You can schedule with three options: @hourly, @daily and @monthly and custom cron.
Delay Transfer. Add a delay to the specified run time.
Timezone. supports extended time zone formats, for example, Asia/Tokyo.
Create a name for your source and then select DONE to save your KARTE connector as a new source.
My Input Transfers
Edit your existing jobs in My Input Transfers. To view the details of previous transfers for this data connector, select the jobs icon.
Using the CLI to Configure the Connector
Before setting up the connector, install the Treasure Data Toolbelt.
Create Seed Config File (seed.yml)
Prepare seed.yml with the following example and your JSON key file. You must also specify the bucket name and target file name (or prefix for multiple files).
The Data Connector for KARTE imports all files that match a specified prefix. For example, path_prefix:
For more details on available out modes, see the Appendix below.
Guess Fields (Generate load.yml)
Use connector:guess. This command automatically reads the target file, and intelligently guesses the file format.
Open up load.yml to see the guessed file format definitions including file formats, encodings, column names, and types.
Preview how the system parses the file by using the preview command.
The guess command requires more than 3 rows and 2 columns in the 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 Data Connector supports parsing of "boolean", "long", "double", "string", and "timestamp" types.
The preview command downloads one file from the specified bucket and displays the results from that file. This might cause a difference in results from the preview and issue commands.
Execute Load Job
Finally, submit the load job. It might 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 (see also data partitioning). If you don’t specify the option, the Data Connector selects 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 can add it using add_time filter option. Find more details at add_time filter plugin.
The previs example command assumes you have already created database(td_sample_db) and table(td_sample_table). If the database or the table do not exist in Treasure Data, this command cannot be successful. Instead, create the database and table manually or use --auto-create-table option with the td connector:issue command to auto-create the database and table.
The 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.
Scheduling Run Times
You can schedule periodic Data Connector to run for incremental KARTE file imports using our high availability scheduler. By using this feature, you no longer need a cron daemon on your local data center.
For the scheduled import, the Data Connector for KARTE imports all files that match with the specified prefix (e.g. path_prefix:
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 only imports files that come after the last path in alphabetical (lexicographic) order. For example,
Create the Schedule
You can create a new schedule with the td connector:create command. The following are required:
The schedule name.
The cron-style schedule.
The database and table where their data will be stored.
The Data Connector configuration file.
We also recommend that you specify the --time-column option, because Treasure Data’s storage is partitioned by time (see also Architecture).
The `cron` parameter also accepts three special options: `@hourly`, `@daily` and `@monthly`.
By default, a schedule is set up in the UTC timezone. You can set the schedule in a timezone using -t or --timezone option. `--timezone` option only supports extended timezone formats like 'Asia/Tokyo', 'America/Los_Angeles' etc. Timezone abbreviations like PST, CST are not supported and might lead to unexpected schedules.
List the Schedules
You can see the list of scheduled entries by running the command td connector:list.
Show the Settings and Schedule History
td connector:show shows the execution settings of a schedule entry.
td connector:history shows the execution history of a schedule entry. To investigate the results of each individual run, use td job <jobid>.
Delete the Schedule
td connector:delete will remove the schedule.
Modes for Out Plugin
You can specify file import mode in out section of seed.yml.
This is the default mode and records are appended to the target table.
replace (In td 0.11.10 and later)
This mode replaces data in the target table.Any manual schema changes made to the target table will remain intact with this mode.