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

feat(samples): add all feature values samples #981

Merged
merged 8 commits into from
Aug 3, 2022
Prev Previous commit
Next Next commit
feat(samples): code review changes
  • Loading branch information
sai-chaithu committed Jul 8, 2022
commit 71bdbce7e52c8f15cd093dd5496f87b5a117979f
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ static void batchCreateFeaturesSample(String project, String featurestoreId, Str
List<CreateFeatureRequest> createFeatureRequests = new ArrayList<>();

Feature titleFeature = Feature.newBuilder().setDescription("The title of the movie")
.setValueType(ValueType.valueOf("STRING")).build();
.setValueType(ValueType.STRING).build();
Feature genresFeature = Feature.newBuilder().setDescription("The genres of the movie")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: change to singular genre, to me genres represents an array of genres.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the same features as https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store/gapic-feature-store.ipynb sample tutorial provided in SOW.
So thought it is ok, should we change it here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, let's retain it for now. It was a minor nit.

.setValueType(ValueType.valueOf("STRING")).build();
.setValueType(ValueType.STRING).build();
Feature averageRatingFeature = Feature.newBuilder()
.setDescription("The average rating for the movie, range is [1.0-5.0]")
.setValueType(ValueType.valueOf("DOUBLE")).build();
.setValueType(ValueType.DOUBLE).build();

createFeatureRequests.add(
CreateFeatureRequest.newBuilder().setFeature(titleFeature).setFeatureId("title").build());
Expand All @@ -85,16 +85,19 @@ static void batchCreateFeaturesSample(String project, String featurestoreId, Str
createFeatureRequests.add(CreateFeatureRequest.newBuilder().setFeature(averageRatingFeature)
.setFeatureId("average_rating").build());

BatchCreateFeaturesRequest request = BatchCreateFeaturesRequest.newBuilder()
BatchCreateFeaturesRequest batchCreateFeaturesRequest = BatchCreateFeaturesRequest
.newBuilder()
.setParent(EntityTypeName.of(project, location, featurestoreId, entityTypeId).toString())
.addAllRequests(createFeatureRequests).build();

OperationFuture<BatchCreateFeaturesResponse, BatchCreateFeaturesOperationMetadata> future =
featurestoreServiceClient.batchCreateFeaturesAsync(request);
System.out.format("Operation name: %s%n", future.getInitialFuture().get().getName());
OperationFuture<BatchCreateFeaturesResponse, BatchCreateFeaturesOperationMetadata>
batchCreateFeaturesFuture =
featurestoreServiceClient.batchCreateFeaturesAsync(batchCreateFeaturesRequest);
System.out.format("Operation name: %s%n",
batchCreateFeaturesFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
BatchCreateFeaturesResponse batchCreateFeaturesResponse =
future.get(timeout, TimeUnit.SECONDS);
batchCreateFeaturesFuture.get(timeout, TimeUnit.SECONDS);
System.out.println("Batch Create Features Response");
System.out.println(batchCreateFeaturesResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ static void batchReadFeatureValuesSample(String project, String featurestoreId,
.setCsvReadInstances(CsvSource.newBuilder().setGcsSource(gcsSource))
.setDestination(
FeatureValueDestination.newBuilder().setBigqueryDestination(bigQueryDestination))
// .addAllPassThroughFields(passThroughFieldsList)
.addAllEntityTypeSpecs(entityTypeSpecs).build();

OperationFuture<BatchReadFeatureValuesResponse, BatchReadFeatureValuesOperationMetadata> brf =
featurestoreServiceClient.batchReadFeatureValuesAsync(batchReadFeatureValuesRequest);
System.out.format("Operation name: %s%n", brf.getInitialFuture().get().getName());
OperationFuture<BatchReadFeatureValuesResponse, BatchReadFeatureValuesOperationMetadata>
batchReadFeatureValuesFuture =
featurestoreServiceClient.batchReadFeatureValuesAsync(batchReadFeatureValuesRequest);
System.out.format("Operation name: %s%n",
batchReadFeatureValuesFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
BatchReadFeatureValuesResponse batchReadFeatureValuesResponse =
brf.get(timeout, TimeUnit.SECONDS);
batchReadFeatureValuesFuture.get(timeout, TimeUnit.SECONDS);
System.out.println("Batch Read Feature Values Response");
System.out.println(batchReadFeatureValuesResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
import com.google.cloud.aiplatform.v1.IdMatcher;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -70,10 +69,9 @@ static void exportFeatureValuesSample(String project, String featurestoreId, Str
try (FeaturestoreServiceClient featurestoreServiceClient =
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {

List<String> ids = new ArrayList<>();
ids.add("*");
FeatureSelector featureSelector = FeatureSelector.newBuilder()
.setIdMatcher(IdMatcher.newBuilder().addAllIds(ids).build()).build();
FeatureSelector featureSelector =
FeatureSelector.newBuilder().setIdMatcher(IdMatcher.newBuilder()
.addAllIds(Arrays.asList("title", "genres", "average_rating")).build()).build();

ExportFeatureValuesRequest exportFeatureValuesRequest =
ExportFeatureValuesRequest.newBuilder()
Expand All @@ -83,13 +81,14 @@ static void exportFeatureValuesSample(String project, String featurestoreId, Str
BigQueryDestination.newBuilder().setOutputUri(destinationTableUri)))
.setFeatureSelector(featureSelector).setFullExport(FullExport.newBuilder()).build();

OperationFuture<ExportFeatureValuesResponse, ExportFeatureValuesOperationMetadata> future =
featurestoreServiceClient.exportFeatureValuesAsync(exportFeatureValuesRequest);
OperationFuture<ExportFeatureValuesResponse, ExportFeatureValuesOperationMetadata>
exportFeatureValuesFuture =
featurestoreServiceClient.exportFeatureValuesAsync(exportFeatureValuesRequest);
System.out.format("Operation name: %s%n",
future.getInitialFuture().get().getName());
exportFeatureValuesFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
ExportFeatureValuesResponse exportFeatureValuesResponse =
future.get(timeout, TimeUnit.SECONDS);
exportFeatureValuesFuture.get(timeout, TimeUnit.SECONDS);
System.out.println("Export Feature Values Response");
System.out.println(exportFeatureValuesResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
import com.google.cloud.aiplatform.v1.FeaturestoreServiceSettings;
import com.google.cloud.aiplatform.v1.IdMatcher;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -70,10 +69,9 @@ static void exportFeatureValuesSnapshotSample(String project, String featurestor
try (FeaturestoreServiceClient featurestoreServiceClient =
FeaturestoreServiceClient.create(featurestoreServiceSettings)) {

List<String> ids = new ArrayList<>();
ids.add("*");
FeatureSelector featureSelector = FeatureSelector.newBuilder()
.setIdMatcher(IdMatcher.newBuilder().addAllIds(ids).build()).build();
FeatureSelector featureSelector =
FeatureSelector.newBuilder().setIdMatcher(IdMatcher.newBuilder()
.addAllIds(Arrays.asList("title", "genres", "average_rating")).build()).build();

ExportFeatureValuesRequest exportFeatureValuesRequest =
ExportFeatureValuesRequest.newBuilder()
Expand All @@ -84,13 +82,14 @@ static void exportFeatureValuesSnapshotSample(String project, String featurestor
.setFeatureSelector(featureSelector).setSnapshotExport(SnapshotExport.newBuilder())
.build();

OperationFuture<ExportFeatureValuesResponse, ExportFeatureValuesOperationMetadata> future =
featurestoreServiceClient.exportFeatureValuesAsync(exportFeatureValuesRequest);
OperationFuture<ExportFeatureValuesResponse, ExportFeatureValuesOperationMetadata>
exportFeatureValuesFuture =
featurestoreServiceClient.exportFeatureValuesAsync(exportFeatureValuesRequest);
System.out.format("Operation name: %s%n",
future.getInitialFuture().get().getName());
exportFeatureValuesFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
ExportFeatureValuesResponse exportFeatureValuesResponse =
future.get(timeout, TimeUnit.SECONDS);
exportFeatureValuesFuture.get(timeout, TimeUnit.SECONDS);
System.out.println("Snapshot Export Feature Values Response");
System.out.println(exportFeatureValuesResponse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ static void importFeatureValuesSample(String project, String featurestoreId, Str
.setAvroSource(
AvroSource.newBuilder().setGcsSource(GcsSource.newBuilder().addUris(gcsSourceUri)))
.build();
OperationFuture<ImportFeatureValuesResponse, ImportFeatureValuesOperationMetadata> future =
featurestoreServiceClient.importFeatureValuesAsync(importFeatureValuesRequest);
OperationFuture<ImportFeatureValuesResponse, ImportFeatureValuesOperationMetadata>
importFeatureValuesFuture =
featurestoreServiceClient.importFeatureValuesAsync(importFeatureValuesRequest);
System.out.format("Operation name: %s%n",
future.getInitialFuture().get().getName());
importFeatureValuesFuture.getInitialFuture().get().getName());
System.out.println("Waiting for operation to finish...");
ImportFeatureValuesResponse importFeatureValuesResponse =
future.get(timeout, TimeUnit.SECONDS);
importFeatureValuesFuture.get(timeout, TimeUnit.SECONDS);
System.out.println("Import Feature Values Response");
System.out.println(importFeatureValuesResponse);
}
Expand Down