Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion automl/cloud-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-automl</artifactId>
<version>1.1.1</version>
<version>1.1.2</version>
</dependency>
<!-- [END automl_java_dependencies] -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,23 @@
package com.example.automl;

// [START automl_import_dataset]
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1.AutoMlClient;
import com.google.cloud.automl.v1.DatasetName;
import com.google.cloud.automl.v1.GcsSource;
import com.google.cloud.automl.v1.InputConfig;
import com.google.cloud.automl.v1.OperationMetadata;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

class ImportDataset {

public static void main(String[] args)
throws IOException, ExecutionException, InterruptedException {
throws IOException, ExecutionException, InterruptedException, TimeoutException {
// TODO(developer): Replace these variables before running the sample.
String projectId = "YOUR_PROJECT_ID";
String datasetId = "YOUR_DATASET_ID";
Expand All @@ -39,7 +43,7 @@ public static void main(String[] args)

// Import a dataset
static void importDataset(String projectId, String datasetId, String path)
throws IOException, ExecutionException, InterruptedException {
throws IOException, ExecutionException, InterruptedException, TimeoutException {
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
Expand All @@ -55,8 +59,22 @@ static void importDataset(String projectId, String datasetId, String path)
InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
System.out.println("Processing import...");

Empty response = client.importDataAsync(datasetFullId, inputConfig).get();
System.out.format("Dataset imported. %s\n", response);
// Start the import job
OperationFuture<Empty, OperationMetadata> operation =
client.importDataAsync(datasetFullId, inputConfig);

System.out.format("Operation name: %s%n", operation.getName());

// If you want to wait for the operation to finish, adjust the timeout appropriately. The
// operation will still run if you choose not to wait for it to complete. You can check the
// status of your operation using the operation's name.
Empty response = operation.get(30, TimeUnit.MINUTES);
System.out.format("Dataset imported. %s%n", response);
} catch (TimeoutException e) {
System.out.println("The operation's polling period was not long enough.");
System.out.println("You can use the Operation's name to get the current status.");
System.out.println("The import job will still complete as expected.");
throw e;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -83,7 +84,8 @@ public void tearDown() throws InterruptedException, ExecutionException, IOExcept
}

@Test
public void testImportDataset() throws IOException, ExecutionException, InterruptedException {
public void testImportDataset()
throws IOException, ExecutionException, InterruptedException, TimeoutException {
ImportDataset.importDataset(PROJECT_ID, datasetId, BUCKET + "/entity-extraction/dataset.csv");
String got = bout.toString();
assertThat(got).contains("Dataset imported.");
Expand Down