Search in sources :

Example 26 with TransferConfig

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 :");
}
Also used : HashMap(java.util.HashMap) Value(com.google.protobuf.Value) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) Test(org.junit.Test)

Example 27 with TransferConfig

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");
}
Also used : HashMap(java.util.HashMap) Value(com.google.protobuf.Value) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) ServiceAccountCredentials(com.google.auth.oauth2.ServiceAccountCredentials) Test(org.junit.Test)

Example 28 with TransferConfig

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);
    }
}
Also used : PrintStream(java.io.PrintStream) DataTransferServiceClient(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient) HashMap(java.util.HashMap) ProjectName(com.google.cloud.bigquery.datatransfer.v1.ProjectName) Value(com.google.protobuf.Value) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CreateTransferConfigRequest(com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest) Before(org.junit.Before)

Example 29 with TransferConfig

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");
}
Also used : TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) FieldMask(com.google.protobuf.FieldMask) Test(org.junit.Test)

Example 30 with TransferConfig

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);
}
Also used : PrintStream(java.io.PrintStream) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FieldMask(com.google.protobuf.FieldMask) Before(org.junit.Before)

Aggregations

TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)49 Value (com.google.protobuf.Value)22 HashMap (java.util.HashMap)22 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)21 ApiException (com.google.api.gax.rpc.ApiException)19 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)16 Test (org.junit.Test)13 FieldMask (com.google.protobuf.FieldMask)9 UpdateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.UpdateTransferConfigRequest)4 ListTransferConfigsPagedResponse (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient.ListTransferConfigsPagedResponse)3 AbstractMessage (com.google.protobuf.AbstractMessage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 Before (org.junit.Before)3 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)1 GetTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.GetTransferConfigRequest)1