Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 8f3cce0

Browse files
author
Praful Makani
authored
docs(samples): add create teradata transfer (#502)
1 parent a029038 commit 8f3cce0

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.bigquerydatatransfer;
18+
19+
// [START bigquerydatatransfer_create_teradata_transfer]
20+
import com.google.api.gax.rpc.ApiException;
21+
import com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest;
22+
import com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient;
23+
import com.google.cloud.bigquery.datatransfer.v1.ProjectName;
24+
import com.google.cloud.bigquery.datatransfer.v1.TransferConfig;
25+
import com.google.protobuf.Struct;
26+
import com.google.protobuf.Value;
27+
import java.io.IOException;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
// Sample to create a teradata transfer config.
32+
public class CreateTeradataTransfer {
33+
34+
public static void main(String[] args) throws IOException {
35+
// TODO(developer): Replace these variables before running the sample.
36+
final String projectId = "MY_PROJECT_ID";
37+
String datasetId = "MY_DATASET_ID";
38+
String databaseType = "Teradata";
39+
String bucketLocation = "gs://cloud-sample-data/";
40+
String databaseName = "MY_DATABASE_NAME";
41+
String tableNamePatterns = "*";
42+
String serviceAccount = "MY_SERVICE_ACCOUNT";
43+
String schemaFilePath = "/your-schema-path";
44+
Map<String, Value> params = new HashMap<>();
45+
params.put("database_type", Value.newBuilder().setStringValue(databaseType).build());
46+
params.put("location", Value.newBuilder().setStringValue(bucketLocation).build());
47+
params.put("database_name", Value.newBuilder().setStringValue(databaseName).build());
48+
params.put("table_name_patterns", Value.newBuilder().setStringValue(tableNamePatterns).build());
49+
params.put("agent_service_account", Value.newBuilder().setStringValue(serviceAccount).build());
50+
params.put("schema_file_path", Value.newBuilder().setStringValue(schemaFilePath).build());
51+
TransferConfig transferConfig =
52+
TransferConfig.newBuilder()
53+
.setDestinationDatasetId(datasetId)
54+
.setDisplayName("Your Teradata Config Name")
55+
.setDataSourceId("on_premises")
56+
.setParams(Struct.newBuilder().putAllFields(params).build())
57+
.setSchedule("every 24 hours")
58+
.build();
59+
createTeradataTransfer(projectId, transferConfig);
60+
}
61+
62+
public static void createTeradataTransfer(String projectId, TransferConfig transferConfig)
63+
throws IOException {
64+
try (DataTransferServiceClient client = DataTransferServiceClient.create()) {
65+
ProjectName parent = ProjectName.of(projectId);
66+
CreateTransferConfigRequest request =
67+
CreateTransferConfigRequest.newBuilder()
68+
.setParent(parent.toString())
69+
.setTransferConfig(transferConfig)
70+
.build();
71+
TransferConfig config = client.createTransferConfig(request);
72+
System.out.println("Cloud teradata transfer created successfully :" + config.getName());
73+
} catch (ApiException ex) {
74+
System.out.print("Cloud teradata transfer was not created." + ex.toString());
75+
}
76+
}
77+
}
78+
// [END bigquerydatatransfer_create_teradata_transfer]

0 commit comments

Comments
 (0)