use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreatePlayTransfer method main.
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "MY_PROJECT_ID";
String datasetId = "MY_DATASET_ID";
String bucket = "gs://cloud-sample-data";
String tableSuffix = "_test";
Map<String, Value> params = new HashMap<>();
params.put("bucket", Value.newBuilder().setStringValue(bucket).build());
params.put("table_suffix", Value.newBuilder().setStringValue(tableSuffix).build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetId).setDisplayName("Your Play Config Name").setDataSourceId("play").setParams(Struct.newBuilder().putAllFields(params).build()).build();
createPlayTransfer(projectId, transferConfig);
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateRedshiftTransfer method createRedshiftTransfer.
public static void createRedshiftTransfer(String projectId, TransferConfig transferConfig) throws IOException {
try (DataTransferServiceClient client = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
TransferConfig config = client.createTransferConfig(request);
System.out.println("Cloud redshift transfer created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("Cloud redshift transfer was not created." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateScheduledQuery method createScheduledQuery.
public static void createScheduledQuery(String projectId, TransferConfig transferConfig) throws IOException {
try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
TransferConfig config = dataTransferServiceClient.createTransferConfig(request);
System.out.println("\nScheduled query created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("\nScheduled query was not created." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateScheduledQueryWithServiceAccount method main.
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "MY_PROJECT_ID";
final String datasetId = "MY_DATASET_ID";
final String serviceAccount = "MY_SERVICE_ACCOUNT";
final String query = "SELECT CURRENT_TIMESTAMP() as current_time, @run_time as intended_run_time, " + "@run_date as intended_run_date, 17 as some_integer";
Map<String, Value> params = new HashMap<>();
params.put("query", Value.newBuilder().setStringValue(query).build());
params.put("destination_table_name_template", Value.newBuilder().setStringValue("my_destination_table_{run_date}").build());
params.put("write_disposition", Value.newBuilder().setStringValue("WRITE_TRUNCATE").build());
params.put("partitioning_field", Value.newBuilder().build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetId).setDisplayName("Your Scheduled Query Name").setDataSourceId("scheduled_query").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").build();
createScheduledQueryWithServiceAccount(projectId, transferConfig, serviceAccount);
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateTeradataTransfer method main.
public static void main(String[] args) throws IOException {
// TODO(developer): Replace these variables before running the sample.
final String projectId = "MY_PROJECT_ID";
String datasetId = "MY_DATASET_ID";
String databaseType = "Teradata";
String bucket = "cloud-sample-data";
String databaseName = "MY_DATABASE_NAME";
String tableNamePatterns = "*";
String serviceAccount = "MY_SERVICE_ACCOUNT";
String schemaFilePath = "/your-schema-path";
Map<String, Value> params = new HashMap<>();
params.put("database_type", Value.newBuilder().setStringValue(databaseType).build());
params.put("bucket", Value.newBuilder().setStringValue(bucket).build());
params.put("database_name", Value.newBuilder().setStringValue(databaseName).build());
params.put("table_name_patterns", Value.newBuilder().setStringValue(tableNamePatterns).build());
params.put("agent_service_account", Value.newBuilder().setStringValue(serviceAccount).build());
params.put("schema_file_path", Value.newBuilder().setStringValue(schemaFilePath).build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetId).setDisplayName("Your Teradata Config Name").setDataSourceId("on_premises").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").build();
createTeradataTransfer(projectId, transferConfig);
}
Aggregations