Skip to content
This repository was archived by the owner on Sep 9, 2023. It is now read-only.

Commit 818acab

Browse files
feat(samples): add all feature values samples (#981)
* feat(samples): add all feature values samples * feat(samples): update all feature values samples * feat(samples): update big query dependency in pom.xml * feat(samples): code review changes * feat(samples): updated feature values samples with close method call and list variable * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 26391a3 commit 818acab

File tree

10 files changed

+921
-1
lines changed

10 files changed

+921
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr
9595

9696
| Sample | Source Code | Try it |
9797
| --------------------------- | --------------------------------- | ------ |
98+
| Batch Create Features Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/BatchCreateFeaturesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/BatchCreateFeaturesSample.java) |
99+
| Batch Read Feature Values Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/BatchReadFeatureValuesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/BatchReadFeatureValuesSample.java) |
98100
| Cancel Batch Prediction Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CancelBatchPredictionJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CancelBatchPredictionJobSample.java) |
99101
| Cancel Data Labeling Job Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CancelDataLabelingJobSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CancelDataLabelingJobSample.java) |
100102
| Cancel Training Pipeline Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/CancelTrainingPipelineSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/CancelTrainingPipelineSample.java) |
@@ -150,6 +152,8 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr
150152
| Delete Training Pipeline Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeleteTrainingPipelineSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeleteTrainingPipelineSample.java) |
151153
| Deploy Model Custom Trained Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeployModelCustomTrainedModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeployModelCustomTrainedModelSample.java) |
152154
| Deploy Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/DeployModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/DeployModelSample.java) |
155+
| Export Feature Values Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportFeatureValuesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportFeatureValuesSample.java) |
156+
| Export Feature Values Snapshot Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportFeatureValuesSnapshotSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportFeatureValuesSnapshotSample.java) |
153157
| Export Model Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelSample.java) |
154158
| Export Model Tabular Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelTabularClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelTabularClassificationSample.java) |
155159
| Export Model Video Action Recognition Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ExportModelVideoActionRecognitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ExportModelVideoActionRecognitionSample.java) |
@@ -180,6 +184,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-aiplatform/tr
180184
| Import Data Video Action Recognition Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoActionRecognitionSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoActionRecognitionSample.java) |
181185
| Import Data Video Classification Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoClassificationSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoClassificationSample.java) |
182186
| Import Data Video Object Tracking Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportDataVideoObjectTrackingSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportDataVideoObjectTrackingSample.java) |
187+
| Import Feature Values Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ImportFeatureValuesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ImportFeatureValuesSample.java) |
183188
| List Entity Types Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListEntityTypesAsyncSample.java) |
184189
| List Entity Types Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListEntityTypesSample.java) |
185190
| List Features Async Sample | [source code](https://github.com/googleapis/java-aiplatform/blob/main/samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-aiplatform&page=editor&open_in_editor=samples/snippets/src/main/java/aiplatform/ListFeaturesAsyncSample.java) |

samples/install-without-bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<version>1.1.3</version>
5555
<scope>test</scope>
5656
</dependency>
57+
<dependency>
58+
<groupId>com.google.cloud</groupId>
59+
<artifactId>google-cloud-bigquery</artifactId>
60+
<version>2.13.6</version>
61+
</dependency>
5762
</dependencies>
5863

5964
<!-- compile and run all snippet tests -->

samples/snapshot/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
<version>1.1.3</version>
5555
<scope>test</scope>
5656
</dependency>
57+
<dependency>
58+
<groupId>com.google.cloud</groupId>
59+
<artifactId>google-cloud-bigquery</artifactId>
60+
<version>2.13.6</version>
61+
</dependency>
5762
</dependencies>
5863

5964
<!-- compile and run all snippet tests -->

samples/snippets/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
<artifactId>proto-google-cloud-aiplatform-v1beta1</artifactId>
6363
<version>0.17.0</version>
6464
</dependency>
65-
65+
<dependency>
66+
<groupId>com.google.cloud</groupId>
67+
<artifactId>google-cloud-bigquery</artifactId>
68+
<version>2.13.6</version>
69+
</dependency>
6670
</dependencies>
6771
</project>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*
17+
* Create features in bulk for an existing entity type. See
18+
* https://cloud.google.com/vertex-ai/docs/featurestore/setup
19+
* before running the code snippet
20+
*/
21+
22+
package aiplatform;
23+
24+
// [START aiplatform_batch_create_features_sample]
25+
26+
import com.google.api.gax.longrunning.OperationFuture;
27+
import com.google.cloud.aiplatform.v1.BatchCreateFeaturesOperationMetadata;
28+
import com.google.cloud.aiplatform.v1.BatchCreateFeaturesRequest;
29+
import com.google.cloud.aiplatform.v1.BatchCreateFeaturesResponse;
30+
import com.google.cloud.aiplatform.v1.CreateFeatureRequest;
31+
import com.google.cloud.aiplatform.v1.EntityTypeName;
32+
import com.google.cloud.aiplatform.v1.Feature;
33+
import com.google.cloud.aiplatform.v1.Feature.ValueType;
34+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceClient;
35+
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
36+
import java.io.IOException;
37+
import java.util.ArrayList;
38+
import java.util.List;
39+
import java.util.concurrent.ExecutionException;
40+
import java.util.concurrent.TimeUnit;
41+
import java.util.concurrent.TimeoutException;
42+
43+
public class BatchCreateFeaturesSample {
44+
45+
public static void main(String[] args)
46+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
47+
// TODO(developer): Replace these variables before running the sample.
48+
String project = "YOUR_PROJECT_ID";
49+
String featurestoreId = "YOUR_FEATURESTORE_ID";
50+
String entityTypeId = "YOUR_ENTITY_TYPE_ID";
51+
String location = "us-central1";
52+
String endpoint = "us-central1-aiplatform.googleapis.com:443";
53+
int timeout = 300;
54+
batchCreateFeaturesSample(project, featurestoreId, entityTypeId, location, endpoint, timeout);
55+
}
56+
57+
static void batchCreateFeaturesSample(
58+
String project,
59+
String featurestoreId,
60+
String entityTypeId,
61+
String location,
62+
String endpoint,
63+
int timeout)
64+
throws IOException, InterruptedException, ExecutionException, TimeoutException {
65+
FeaturestoreServiceSettings featurestoreServiceSettings =
66+
FeaturestoreServiceSettings.newBuilder().setEndpoint(endpoint).build();
67+
68+
// Initialize client that will be used to send requests. This client only needs to be created
69+
// once, and can be reused for multiple requests. After completing all of your requests, call
70+
// the "close" method on the client to safely clean up any remaining background resources.
71+
try (FeaturestoreServiceClient featurestoreServiceClient =
72+
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {
73+
74+
List<CreateFeatureRequest> createFeatureRequests = new ArrayList<>();
75+
76+
Feature titleFeature =
77+
Feature.newBuilder()
78+
.setDescription("The title of the movie")
79+
.setValueType(ValueType.STRING)
80+
.build();
81+
Feature genresFeature =
82+
Feature.newBuilder()
83+
.setDescription("The genres of the movie")
84+
.setValueType(ValueType.STRING)
85+
.build();
86+
Feature averageRatingFeature =
87+
Feature.newBuilder()
88+
.setDescription("The average rating for the movie, range is [1.0-5.0]")
89+
.setValueType(ValueType.DOUBLE)
90+
.build();
91+
92+
createFeatureRequests.add(
93+
CreateFeatureRequest.newBuilder().setFeature(titleFeature).setFeatureId("title").build());
94+
95+
createFeatureRequests.add(
96+
CreateFeatureRequest.newBuilder()
97+
.setFeature(genresFeature)
98+
.setFeatureId("genres")
99+
.build());
100+
101+
createFeatureRequests.add(
102+
CreateFeatureRequest.newBuilder()
103+
.setFeature(averageRatingFeature)
104+
.setFeatureId("average_rating")
105+
.build());
106+
107+
BatchCreateFeaturesRequest batchCreateFeaturesRequest =
108+
BatchCreateFeaturesRequest.newBuilder()
109+
.setParent(
110+
EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
111+
.addAllRequests(createFeatureRequests)
112+
.build();
113+
114+
OperationFuture<BatchCreateFeaturesResponse, BatchCreateFeaturesOperationMetadata>
115+
batchCreateFeaturesFuture =
116+
featurestoreServiceClient.batchCreateFeaturesAsync(batchCreateFeaturesRequest);
117+
System.out.format(
118+
"Operation name: %s%n", batchCreateFeaturesFuture.getInitialFuture().get().getName());
119+
System.out.println("Waiting for operation to finish...");
120+
BatchCreateFeaturesResponse batchCreateFeaturesResponse =
121+
batchCreateFeaturesFuture.get(timeout, TimeUnit.SECONDS);
122+
System.out.println("Batch Create Features Response");
123+
System.out.println(batchCreateFeaturesResponse);
124+
featurestoreServiceClient.close();
125+
}
126+
}
127+
}
128+
// [END aiplatform_batch_create_features_sample]

0 commit comments

Comments
 (0)