Search in sources :

Example 46 with TransferConfig

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

Example 47 with 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());
    }
}
Also used : DataTransferServiceClient(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient) ProjectName(com.google.cloud.bigquery.datatransfer.v1.ProjectName) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) CreateTransferConfigRequest(com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest) ApiException(com.google.api.gax.rpc.ApiException)

Example 48 with TransferConfig

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());
    }
}
Also used : DataTransferServiceClient(com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient) ProjectName(com.google.cloud.bigquery.datatransfer.v1.ProjectName) TransferConfig(com.google.cloud.bigquery.datatransfer.v1.TransferConfig) CreateTransferConfigRequest(com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest) ApiException(com.google.api.gax.rpc.ApiException)

Example 49 with TransferConfig

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

Example 50 with TransferConfig

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

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