use of com.google.cloud.automl.v1beta1.BigQuerySource in project java-automl by googleapis.
the class TablesBatchPredictBigQuery method batchPredict.
static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (PredictionServiceClient client = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, "us-central1", modelId);
// Configure the source of the file from BigQuery
BigQuerySource bigQuerySource = BigQuerySource.newBuilder().setInputUri(inputUri).build();
BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().setBigquerySource(bigQuerySource).build();
// Configure where to store the output in BigQuery
BigQueryDestination bigQueryDestination = BigQueryDestination.newBuilder().setOutputUri(outputUri).build();
BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().setBigqueryDestination(bigQueryDestination).build();
// Build the request that will be sent to the API
BatchPredictRequest request = BatchPredictRequest.newBuilder().setName(name.toString()).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
// Start an asynchronous request
OperationFuture<BatchPredictResult, OperationMetadata> future = client.batchPredictAsync(request);
System.out.println("Waiting for operation to complete...");
BatchPredictResult response = future.get();
System.out.println("Batch Prediction results saved to BigQuery.");
}
}
use of com.google.cloud.automl.v1beta1.BigQuerySource in project java-automl by googleapis.
the class TablesImportDataset method importDataset.
// Import a dataset via BigQuery or Google Cloud Storage
static void importDataset(String projectId, String datasetId, String path) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the complete path of the dataset.
DatasetName datasetFullId = DatasetName.of(projectId, "us-central1", datasetId);
InputConfig.Builder inputConfigBuilder = InputConfig.newBuilder();
// Determine which source type was used for the input path (BigQuery or GCS)
if (path.startsWith("bq")) {
// Get training data file to be imported from a BigQuery source.
BigQuerySource.Builder bigQuerySource = BigQuerySource.newBuilder();
bigQuerySource.setInputUri(path);
inputConfigBuilder.setBigquerySource(bigQuerySource);
} else {
// Get multiple Google Cloud Storage URIs to import data from
GcsSource gcsSource = GcsSource.newBuilder().addAllInputUris(Arrays.asList(path.split(","))).build();
inputConfigBuilder.setGcsSource(gcsSource);
}
// Import data from the input URI
System.out.println("Processing import...");
Empty response = client.importDataAsync(datasetFullId, inputConfigBuilder.build()).get();
System.out.format("Dataset imported. %s%n", response);
}
}
Aggregations