use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class RunNotification method runNotification.
public static void runNotification(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 with run notification created successfully :" + config.getName());
} catch (ApiException ex) {
System.out.print("\nScheduled query with run notification was not created." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class UpdateCredentials method updateCredentials.
public static void updateCredentials(TransferConfig transferConfig, String serviceAccount, FieldMask updateMask) throws IOException {
try (DataTransferServiceClient dataTransferServiceClient = DataTransferServiceClient.create()) {
UpdateTransferConfigRequest request = UpdateTransferConfigRequest.newBuilder().setTransferConfig(transferConfig).setUpdateMask(updateMask).setServiceAccountName(serviceAccount).build();
dataTransferServiceClient.updateTransferConfig(request);
System.out.println("Credentials updated successfully");
} catch (ApiException ex) {
System.out.print("Credentials was not updated." + ex.toString());
}
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateCloudStorageTransferIT method testCreateCloudStorageTransfer.
@Test
public void testCreateCloudStorageTransfer() throws IOException {
String sourceUri = "gs://cloud-samples-data/bigquery/us-states/us-states.csv";
String fileFormat = "CSV";
String fieldDelimiter = ",";
String skipLeadingRows = "1";
Map<String, Value> params = new HashMap<>();
params.put("destination_table_name_template", Value.newBuilder().setStringValue(tableName).build());
params.put("data_path_template", Value.newBuilder().setStringValue(sourceUri).build());
params.put("write_disposition", Value.newBuilder().setStringValue("APPEND").build());
params.put("file_format", Value.newBuilder().setStringValue(fileFormat).build());
params.put("field_delimiter", Value.newBuilder().setStringValue(fieldDelimiter).build());
params.put("skip_leading_rows", Value.newBuilder().setStringValue(skipLeadingRows).build());
TransferConfig transferConfig = TransferConfig.newBuilder().setDestinationDatasetId(datasetName).setDisplayName(displayName).setDataSourceId("google_cloud_storage").setParams(Struct.newBuilder().putAllFields(params).build()).setSchedule("every 24 hours").build();
CreateCloudStorageTransfer.createCloudStorageTransfer(PROJECT_ID, transferConfig);
String result = bout.toString();
name = result.substring(result.indexOf(":") + 1, result.length() - 1);
assertThat(result).contains("Cloud storage transfer created successfully :");
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class CreateScheduledQueryIT method testCreateScheduledQuery.
@Test
public void testCreateScheduledQuery() 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();
CreateScheduledQuery.createScheduledQuery(PROJECT_ID, transferConfig);
String result = bout.toString();
name = result.substring(result.indexOf(":") + 1, result.length() - 1);
assertThat(result).contains("Scheduled query created successfully");
}
use of com.google.cloud.bigquery.datatransfer.v1.TransferConfig in project java-bigquerydatatransfer by googleapis.
the class UpdateTransferConfigIT method testUpdateTransferConfig.
@Test
public void testUpdateTransferConfig() throws IOException {
TransferConfig transferConfig = TransferConfig.newBuilder().setName(CONFIG_NAME).setDisplayName("UPDATED_DISPLAY_NAME").build();
FieldMask updateMask = FieldMaskUtil.fromString("display_name");
UpdateTransferConfig.updateTransferConfig(transferConfig, updateMask);
assertThat(bout.toString()).contains("Transfer config updated successfully");
}
Aggregations