Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fix importData sample in order to bump libraries-bom version #3011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 vision/automl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>4.4.1</version>
<version>5.5.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.vision.samples.automl;

// Imports the Google Cloud client library
import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.ClassificationProto.ClassificationType;
import com.google.cloud.automl.v1beta1.Dataset;
Expand All @@ -27,10 +28,13 @@
import com.google.cloud.automl.v1beta1.InputConfig;
import com.google.cloud.automl.v1beta1.ListDatasetsRequest;
import com.google.cloud.automl.v1beta1.LocationName;
import com.google.cloud.automl.v1beta1.OperationMetadata;
import com.google.cloud.automl.v1beta1.OutputConfig;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import net.sourceforge.argparse4j.ArgumentParsers;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
Expand Down Expand Up @@ -211,9 +215,21 @@ static void importData(String projectId, String computeRegion, String datasetId,
// Import data from the input URI
InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
System.out.println("Processing import...");
Empty response = client.importDataAsync(datasetFullId.toString(), inputConfig).get();
System.out.println(String.format("Dataset imported. %s", response));
} catch (IOException | InterruptedException | ExecutionException e) {

// Start the import job
OperationFuture<Empty, OperationMetadata> operation =
client.importDataAsync(datasetFullId, inputConfig);

// More info on gax longrunning Operation:
// http://googleapis.github.io/gax-java/1.4.1/apidocs/com/google/api/gax/grpc/OperationFuture.html
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(5, TimeUnit.MINUTES);
System.out.format("Dataset imported. %s%n", response);
} catch (IOException | InterruptedException | ExecutionException | TimeoutException e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void testCreateImportDeleteDataset() {

// Act
DatasetApi.importData(
PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/flower_traindata.csv");
PROJECT_ID, COMPUTE_REGION, datasetId, "gs://" + BUCKET + "/flower_traindata_concise.csv");

// Assert
got = bout.toString();
Expand Down