use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CopyDatasetIT method testCopyDataset.
@Test
public void testCopyDataset() throws IOException {
Map<String, Value> params = new HashMap<>();
params.put("source_project_id", Value.newBuilder().setStringValue("bigquery-public-data").build());
params.put("source_dataset_id", Value.newBuilder().setStringValue("usa_names").build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetName).setDisplayName(displayName).setDataSourceId("cross_region_copy").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").build();
CopyDataset.copyDataset(PROJECT_ID, transferConfig);
String result = bout.toString();
name = result.substring(result.indexOf(":") + 1, result.length() - 1);
assertThat(result).contains("Copy dataset created successfully :");
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateScheduledQueryWithServiceAccountIT method testCreateScheduledQueryWithServiceAccount.
@Test
public void testCreateScheduledQueryWithServiceAccount() throws IOException {
String query = "SELECT CURRENT_TIMESTAMP() as current_time, @run_time as intended_run_time, " + "@run_date as intended_run_date, 17 as some_integer";
String destinationTableName = "MY_DESTINATION_TABLE_" + UUID.randomUUID().toString().substring(0, 8) + "_{run_date}";
Map<String, Value> params = new HashMap<>();
params.put("query", Value.newBuilder().setStringValue(query).build());
params.put("destination_table_name_template", Value.newBuilder().setStringValue(destinationTableName).build());
params.put("write_disposition", Value.newBuilder().setStringValue("WRITE_TRUNCATE").build());
params.put("partitioning_field", Value.newBuilder().setStringValue("").build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetName).setDisplayName(displayName).setDataSourceId("scheduled_query").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").setState(TransferState.CANCELLED).build();
ServiceAccountCredentials credentials = (ServiceAccountCredentials) ServiceAccountCredentials.getApplicationDefault();
CreateScheduledQueryWithServiceAccount.createScheduledQueryWithServiceAccount(PROJECT_ID, transferConfig, credentials.getClientEmail());
String result = bout.toString();
name = result.substring(result.indexOf(":") + 1, result.length() - 1);
assertThat(result).contains("Scheduled query with service account created successfully");
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class DeleteTransferConfigIT method setUp.
@Before
public void setUp() throws IOException {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
displayName = "MY_SCHEDULE_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8);
datasetName = "MY_DATASET_NAME_TEST_" + UUID.randomUUID().toString().substring(0, 8);
// create a temporary dataset
bigquery = BigQueryOptions.getDefaultInstance().getService();
bigquery.create(DatasetInfo.of(datasetName));
// create a scheduled query
String query = "SELECT CURRENT_TIMESTAMP() as current_time, @run_time as intended_run_time, " + "@run_date as intended_run_date, 17 as some_integer";
String destinationTableName = "MY_DESTINATION_TABLE_" + UUID.randomUUID().toString().substring(0, 8) + "_{run_date}";
Map<String, Value> params = new HashMap<>();
params.put("query", Value.newBuilder().setStringValue(query).build());
params.put("destination_table_name_template", Value.newBuilder().setStringValue(destinationTableName).build());
params.put("write_disposition", Value.newBuilder().setStringValue("WRITE_TRUNCATE").build());
params.put("partitioning_field", Value.newBuilder().setStringValue("").build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetName).setDisplayName(displayName).setDataSourceId("scheduled_query").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").build();
try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
ProjectName parent = ProjectName.of(PROJECT_ID);
CreateTransferConfigRequest request = CreateTransferConfigRequest.newBuilder().setParent(parent.toString()).setTransferConfig(transferConfig).build();
name = dataTransferServiceClient.createTransferConfig(request).getName();
System.out.println("Transfer config created successfully :" + name);
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class ReEnableTransferConfigIT method testReEnableTransferConfig.
@Test
public void testReEnableTransferConfig() throws IOException {
TransferConfig transferConfig = TransferConfig.newBuilder().setName(CONFIG_NAME).setDisabled(false).build();
FieldMask updateMask = FieldMaskUtil.fromString("disabled");
ReEnableTransferConfig.reEnableTransferConfig(transferConfig, updateMask);
assertThat(bout.toString()).contains("Transfer config reenable successfully");
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class ScheduleBackFillIT method setUp.
@Before
public void setUp() throws IOException {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
// enable transfer config
TransferConfig transferConfig = TransferConfig.newBuilder().setName(CONFIG_NAME).setDisabled(false).build();
FieldMask updateMask = FieldMaskUtil.fromString("disabled");
ReEnableTransferConfig.reEnableTransferConfig(transferConfig, updateMask);
}
Aggregations