in Java/src/main/java/com/example/customername/FeatureStoreAPIExample.java [67:162]
public static void featureGroupAPIs(
String bucketName,
String filepath,
String[] featureGroupNames,
String recordIdentifierFeatureName,
String eventTimeFeatureName,
String featureGroupDescription,
String sageMakerRoleARN,
int numOfthreads,
Region region) throws IOException{
try {
// Read csv data into list
List < String[] > csvList = CsvIO.readCSVIntoList(filepath);
// Get the feature names from the first row of the CSV file
String[] featureNames = csvList.get(0);
// Get the second row of data for data type inferencing
String[] rowOfData = csvList.get(1);
// Initialize the below variable depending on whether the csv has an idx column or not
boolean isIgnoreIdxColumn = featureNames[0].length() == 0 ? true : false;
// Get column definitions
List < FeatureDefinition > columnDefinitions = FeatureGroupRecordOperations.makeColumnDefinitions(featureNames, rowOfData, eventTimeFeatureName, isIgnoreIdxColumn);
// Build and create a list of records
List < List < FeatureValue >> featureRecordsList = FeatureGroupRecordOperations.makeRecordsList(featureNames, csvList, isIgnoreIdxColumn, true);
//s3://bucket-name/sagemaker-featurestore-demo/
S3StorageConfig s3StorageConfig = S3StorageConfig.builder()
.s3Uri(String.format("s3://%1$s/sagemaker-featurestore-demo/", bucketName))
.build();
OfflineStoreConfig offlineStoreConfig = OfflineStoreConfig.builder()
.s3StorageConfig(s3StorageConfig)
.build();
OnlineStoreConfig onlineStoreConfig = OnlineStoreConfig.builder()
.enableOnlineStore(Boolean.TRUE)
.build();
SageMakerClient sageMakerClient = SageMakerClient.builder()
.region(region)
.build();
S3Client s3Client = S3Client.builder()
.region(region)
.build();
// Set up SageMakerFeatureStoreRuntimeClient
SageMakerFeatureStoreRuntimeClient sageMakerFeatureStoreRuntimeClient = SageMakerFeatureStoreRuntimeClient.builder()
.region(region)
.build();
// Delete feature groups that are in our list of fg names if it already exists in the store FGs
FeatureGroupOperations.deleteExistingFeatureGroups(sageMakerClient, featureGroupNames);
// // Create feature group ======================================== //
FeatureGroupOperations.createFeatureGroups(sageMakerClient, featureGroupNames, featureGroupDescription, onlineStoreConfig, eventTimeFeatureName, offlineStoreConfig, columnDefinitions, recordIdentifierFeatureName, sageMakerRoleARN);
// Total number of threads to create for batch ingestion
int numOfThreadsToCreate = numOfthreads * featureGroupNames.length;
// Ingest data from csv data
Ingest.batchIngest(numOfThreadsToCreate, sageMakerFeatureStoreRuntimeClient, featureRecordsList, featureGroupNames, eventTimeFeatureName);
// Invoke the list feature Group API
List < FeatureGroupSummary > featureGroups = FeatureGroupOperations.getAllFeatureGroups(sageMakerClient);
// Describe each feature Group
FeatureGroupOperations.describeFeatureGroups(sageMakerClient, featureGroups);
// Loop getRecord tests for FeatureGroups in our feature store
int amountToRepeat = 1;
String record_identifier_value = "2997887";
FeatureGroupOperations.runFeatureGroupGetTests(sageMakerClient, sageMakerFeatureStoreRuntimeClient, featureGroups, amountToRepeat, record_identifier_value);
// Delete record demo
FeatureGroupOperations.deleteRecord(sageMakerFeatureStoreRuntimeClient, featureGroupNames[0], record_identifier_value);
// Delete featureGroups
FeatureGroupOperations.deleteExistingFeatureGroups(sageMakerClient, featureGroupNames);
sageMakerFeatureStoreRuntimeClient.close();
sageMakerClient.close();
s3Client.close();
} catch (SageMakerException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}