All Products
Search
Document Center

Platform For AI:FeatureStore SDK for Java

Last Updated:Mar 05, 2026

This topic describes how to use the Java software development kit (SDK) to read data from FeatureStore online stores. This data includes offline features, real-time features, and sequence features.

Prerequisites

  • Create a project, feature entity, feature view, and model feature in FeatureStore, and synchronize the data. For more information, see Configure a FeatureStore project.

  • Obtain the AccessKey ID and AccessKey secret for your Alibaba Cloud account. For more information, see Create an AccessKey.

    Store your AccessKey ID and AccessKey secret in local environment variables. For more information, see Configure environment variables.

Install the FeatureStore Java SDK

Download and install the FeatureStore Java SDK.

Initialize the FeatureStore client

API

Initialize the Configuration class.

Configuration configuration = new Configuration(regionId,accessKeyId,accessKeySecret,projectName);

Parameters

Parameter

Example

Description

regionId

cn-hangzhou

Region

accessKeyId

System.getenv("ACCESS_KEY_ID")

The AccessKey ID obtained from the environment variable.

accessKeySecret

System.getenv("ACCESS_KEY_SECRET")

The AccessKey secret obtained from the environment variable.

projectName

holo_pro

The name of the FeatureStore project.

Note

The SDK connects directly to the online store. The client must run in a Virtual Private Cloud (VPC) environment. For example, you can connect to a Hologres instance only from within a specified VPC.

Example

public class Constants {
    public static String accessId = "";
    public static String accessKey = "";
    public static String host = "paifeaturestore.cn-hangzhou.aliyuncs.com";

    static {
        accessId = System.getenv("ACCESS_KEY_ID");// System.getenv("") gets the value of the environment variable.
        accessKey = System.getenv("ACCESS_KEY_SECRET");
    }
}
// Initialize the configuration class.
Configuration configuration = new Configuration("cn-hangzhou",Constants.accessId,
                                                Constants.accessKey,"dec8");
configuration.setDomain(Constants.host);
ApiClient apiClient = new ApiClient(configuration);
FeatureStoreClient fsclient = new FeatureStoreClient(apiClient);

Get feature data from a feature view

API

public FeatureResult getOnlineFeatures(String[] joinIds);// Queries the full table without using an alias.
public FeatureResult getOnlineFeatures(String[] joinIds, String[] features, Map<String, String> aliasFields);

Parameters

Parameter

Example

Description

joinIds

{"100001167","100001168"}

An array of primary key values. The query returns data based on these values.

features

{"user_id","city"}

Note: To get all fields, use new String[]{"*"}.

The fields to query from the data table.

aliasFields

{"user_id":"uId"}

An alias for a data table field. The alias is displayed in the returned data.

Examples

  • Example 1: Retrieve feature data from an offline feature view

    • Retrieve a feature view and data synchronized from an offline table

      // Get a feature view by name.
      // mo1 (Offline FeatureView)
      FeatureView mo1 = project.getFeatureViewMap().get("mo1");
      if(mo1==null){
          throw new RuntimeException("This featureView does not exist");
      }
      
      HashMap<String, String> ss = new HashMap<>();
      FeatureResult features = mo1.getOnlineFeatures(new String[]{"100001167", "100004088","100006646"}, new String[]{"*"}, ss);
    • Sample response

      [
        {
          "user_id":100001167,
          "gender":"male",
          "age":28, 
          "city":"Shenyang",
          "item_cnt":0,
          "follow_cnt":0,
          "follower_cnt":0,
          "register_time":1696658585,
          "tags":"2"
        },
        {
          "user_id":100004088,
          "gender":"female",
          "age":28, 
          "city":"Changchun",
          "item_cnt":0,
          "follow_cnt":8,
          "follower_cnt":0,
          "register_time":1695618449,
          "tags":"1"
        },
        {
          "user_id":100006646,
          "gender":"male",
          "age":28, 
          "city":"Changchun",
          "item_cnt":0,
          "follow_cnt":1,
          "follower_cnt":1,
          "register_time":1698213339,
          "tags":"1"
        }
      ]
  • Example 2: Retrieve feature data from a real-time feature view

    • Retrieve a feature view and data from an online table

      // Get a feature view by name.
      // tfv1 (Online FeatureView)
      FeatureView tfv1 = project.getFeatureViewMap().get("tfv1");
      if(tfv1==null){
          throw new RuntimeException("This featureView does not exist");
      }
      // Get data.
      FeatureResult rf = tfv1.getOnlineFeatures(new String[]{"35d3d5a52a7515c2ca6bb4d8e965149b", "0ab7e3efacd56983f16503572d2b9915","84dfd3f91dd85ea105bc74a4f0d7a067"}, new String[]{"*"}, ss);
    • Sample response

      [
        {
          "USER_MD5":"35d3d5a52a7515c2ca6bb4d8e965149b", 
          "USER_NICKNAME":"Miss Sini" 
        }
        {
          "USER_MD5":"0ab7e3efacd56983f16503572d2b9915", 
          "USER_NICKNAME":"Love You"
        }
        {
          "USER_MD5":"84dfd3f91dd85ea105bc74a4f0d7a067", 
          "USER_NICKNAME":"Elementary Student's Dad"
        }
      ]
  • Example 3: Retrieve feature data from a sequence feature view

    • Retrieve a feature view and data synchronized from an offline table

      // Get a feature view by name.
      // ots_seq2 (Sequence FeatureView)
      SequenceFeatureView ots_seq2 = project.getSeqFeatureView("ots_seq2");
      if(ots_seq2==null){
          throw new RuntimeException("This featureView does not exist");
      }
      // Get data.
      FeatureResult features2 = ots_seq2.getOnlineFeatures(new String[]{"157843277", "157843278"});
            
    • Sample response

      [
        {
          "click _50_seq_playtime":"null;15.0",
          "click_50_seq_event_time":"null;1704684504747",
          "click_50_seq_ts":"625662604;625662604",
          "user_id":"157843277",
          "click_50_seq":"null;200167895",
          "click_50_seq_event":"null;click",
          "click_50_seq_item_id":"null;200167895"
        },
        {
          "click_50_seq_playtime":"null;15.0",
          "click_50_seq_event_time":"null;1704684504747",
          "click_50_seq_ts":"625662604;625662604",
          "user_id":"157843278",
          "click_50_seq":"null;200167895",
          "click_50_seq_event":"null;click",
          "click_50_seq_item_id":"null;200167895"
        }
      ]

Get feature data from a model feature

API

public FeatureResult getOnlineFeatures(Map<String, List<String>> joinIds);
public FeatureResult getOnlineFeaturesWithEntity(Map<String, List<String>> joinIds, String featureEntityName);

Parameters

Parameter

Example

Description

joinIds

[

"user_id":

{"101598051",

"101598471",

"101601287"

}

]

A map of join IDs. The key is the join ID name and the value is the join ID value.

featureEntityName

"user"

Retrieves specified data from one side of a FeatureEntity.

Examples

  • Example 1: Retrieve feature data from a model feature that does not include a sequence feature view

    A ModelFeature can be associated with multiple FeatureEntities, and you can set multiple join_ids to return all associated features at once.

    The example contains two of each: join_id, user_id, and item_id. When you retrieve features, you must provide the same number of IDs for each type.

    // Get model features.
    Model mf1 = project.getModelFeature("model_ots1");
    HashMap<String, List<String>> mm = new HashMap<>();
    mm.put("user_id", Arrays.asList("101598051", "101598471", "101601287"));
    mm.put("item_id",Arrays.asList("200004157", "200006185", "200034730"));
    • Retrieve feature data from all feature entities in the model feature

      • Retrieve feature data from all feature entities in the model feature

        // Get the data that all associated entities contain.
        FeatureResult fr1 = mf1.getOnlineFeatures(mm);
      • Sample response

        [
          {
            "user_id":101598051,
            "gender":"male",
            "age":28, 
            "city":"Hangzhou",
            "item_cnt":0,
            "follow_cnt":0,
            "follower_cnt":0,
            "register_time":1695785665,
            "tags":"1",
            "item_id":200004157,
            "author":137649839, 
            "category":2,
            "click_count":0,
            "duration":18.0,
            "praise_count":30,
            "pub_time":1698208690,
            "title":"#Workout_Check-in"
          },
          {
            "user_id":200004157,
            "gender":"female",
            "age":31, 
            "city":"Shenzhen",
            "item_cnt":0,
            "follow_cnt":1,
            "follower_cnt":0,
            "register_time":1695726582,
            "tags":"1",
            "item_id":200006185,
            "author":134195601, 
            "category":14,
            "click_count":50,
            "duration":55.0,
            "praise_count":21,
            "pub_time":1696700908,
            "title":"#Idiom_Story"
          },
          {
            "user_id":101601287,
            "gender":"female",
            "age":33, 
            "city":"Shenzhen",
            "item_cnt":0,
            "follow_cnt":0,
            "follower_cnt":55,
            "register_time":1697519102,
            "tags":"0",
            "item_id":200034730,
            "author":112739045, 
            "category":6,
            "click_count":2,
            "duration":9.0,
            "praise_count":0,
            "pub_time":1696568654,
            "title":"#Workout_Check-in"
          }
        ]
    • Retrieve feature data from a specific feature entity in the model feature

      • Retrieve feature data from a specific feature entity in the model feature

        // Get only the data from the server-side entity.
        FeatureResult fr2 = mf1.getOnlineFeaturesWithEntity(mm, "server");
      • Sample response

        [
        	{
            "item_id":200004157,
            "author":137649839, 
            "category":2,
            "click_count":0,
            "duration":18.0,
            "praise_count":30,
            "pub_time":1698208690,
            "title":"#Workout_Check-in"
          },
          {
            "item_id":200006185,
            "author":134195601, 
            "category":14,
            "click_count":50,
            "duration":55.0,
            "praise_count":21,
            "pub_time":1696700908,
            "title":"#Idiom_Story"
          },
          {
            "item_id":200034730,
            "author":112739045, 
            "category":6,
            "click_count":2,
            "duration":9.0,
            "praise_count":0,
            "pub_time":1696568654,
            "title":"#Workout_Check-in"
          }
        ]
  • Example 2: Retrieve feature data from a model feature that includes a sequence feature view

    A ModelFeature can be associated with multiple FeatureEntities. You can set multiple join_ids to return the features together.

    In this example, join_id corresponds to user_id.

    // Get data from model features that contain serialized features.
    Model mdt1 =project.getModelFeature("mdt1");
    if(mdt1==null){
        throw new RuntimeException("This modelFeature does not exist");
    }
    HashMap<String, List<String>> fsmap = new HashMap<>();
    fsmap.put("user_id",Arrays.asList("100001167","100024146"));
    fsmap.put("item_id",Arrays.asList("200138790","200385417"));
    • Retrieve feature data from the feature entities in the model feature

      • Retrieve feature data from the feature entities in the model feature

        FeatureResult fr3 = mdt2.getOnlineFeatures(fsmap);
      • Sample response

        [
          {
            "click_50_seq_event_time":"null;1698170945",
            "gender":"male",
            "click_50_seq_ts":"1704292557212;1704292557212",
            "city":"Shenyang",
            "item_id":"200138790",
            "click_50_seq":"null;204153583",
            "author":186784264,
            "pub_time":1696574947,
            "follower_cnt":0,
            "follow_cnt":0,
            "item_cnt":0,
            "click_count":2,
            "title":"#Idiom_Story",
            "register_time":1696658585,
            "tags":2,
            "duration":13.0,
            "click_50_seq_playtime":"null;98.93932923011255",
            "user_id":"100001167",
            "praise_count":3,
            "click_50_seq_event":"null;click",
            "category":20,
            "click_50_seq_item_id":"null;204153583",
            "age":28
          },
          {
            "click_50_seq_event_time":"null;1698180365",
            "gender":"male",
            "click_50_seq_ts":"1704292547792;1704292547792;1704292547792",
            "city":"Ningbo",
            "item_id":200385417,
            "click_50_seq":"null;299049390",
            "author":189247964,
            "pub_time":1696432224,
            "follower_cnt":47,
            "follow_cnt":0,
            "item_cnt":0,
            "click_count":4,
            "title":"#Idiom_Story",
            "register_time":1697253820,
            "tags":1,
            "duration":"9.0",
            "click_50_seq_playtime":"null;32.15018252408633",
            "user_id":100024146,
            "praise_count":0,
            "click_50_seq_event":"null;click",
            "category":0,
            "click_50_seq_item_id":"null;299049390",
            "age":28
          },
          {
            "click_50_seq_event_time":"null;1698170945",
            "gender":"male",
            "click_50_seq_ts":"1704292557212;1704292557212",
            "city":"Shenyang",
            "item_id":200138790,
            "click_50_seq":"null;204153583",
            "author":186784264,
            "pub_time":1696574947,
            "follower_cnt":0,
            "follow_cnt":0,
            "item_cnt":0,
            "click_count":2,
            "title":"#Idiom_Story",
            "register_time":1696658585,
            "tags":2,
            "duration":13.0,
            "click_50_seq_playtime":"null;98.93932923011255",
            "user_id":"100001167",
            "praise_count":3,
            "click_50_seq_event":"null;click",
            "category":20,
            "click_50_seq_item_id":"null;204153583",
            "age":28
          },
          {
            "click_50_seq_event_time":"null;1698180365",
            "gender":"male",
            "click_50_seq_ts":"1704292547792;1704292547792",
            "city":"Ningbo",
            "item_id":200385417,
            "click_50_seq":"null;299049390",
            "author":189247964,
            "pub_time":1696432224,
            "follower_cnt":47,
            "follow_cnt":0,
            "item_cnt":0,
            "click_count":4,
            "title":"#Idiom_Story",
            "register_time":1697253820,
            "tags":1,
            "duration":9.0,
            "click_50_seq_playtime":"null;32.15018252408633",
            "user_id":"100024146",
            "praise_count":"0",
            "click_50_seq_event":"null;click",
            "category":0,
            "click_50_seq_item_id":"null;299049390",
            "age":28
          }
        ]
    • Retrieve feature data from a specific feature entity in the model feature

      • Retrieve feature data from a specific feature entity in the model feature

        FeatureResult fr4 = mdt1.getOnlineFeaturesWithEntity(fsmap, "client");
      • Sample response

        [
          {
            "click_50_seq_event_time":"null;1698170945",
            "gender":"male",
            "click_50_seq_ts":"1704292555552;1704292555552",
            "city":"Shenyang",
            "click_50_seq":"null;204153583",
            "follower_cnt":0,
            "follow_cnt":0,
            "item_cnt":0,
            "register_time":1696658585,
            "tags":2,
            "click_50_seq_playtime":"null;98.93932923011255",
            "user_id":"100001167",
            "click_50_seq_event":"null;click",
            "click_50_seq_item_id":"null;204153583",
            "age":28
          },
          {
            "click_50_seq_event_time":"null;1698180365",
            "gender":"male",
            "click_50_seq_ts":"1704292546132;1704292546132;1704292546132",
            "city":"Ningbo",
            "click_50_seq":"null;299049390",
            "follower_cnt":47,
            "follow_cnt":0,
            "item_cnt":0,
            "register_time":1697253820,
            "tags":"1",
            "click_50_seq_playtime":"null;32.15018252408633",
            "user_id":100024146,
            "click_50_seq_event":"null;click",
            "click_50_seq_item_id":"null;299049390",
            "age":28
          },
          {
            "click_50_seq_event_time":"null;1698170945",
            "gender":"male",
            "click_50_seq_ts":"1704292555552;1704292555552",
            "city":"Shenyang",
            "click_50_seq":"null;204153583",
            "follower_cnt":0,
            "follow_cnt":0,
            "item_cnt":0,
            "register_time":1696658585,
            "tags":2,
            "click_50_seq_playtime":"null;98.93932923011255",
            "user_id":"100001167",
            "click_50_seq_event":"null;click",
            "click_50_seq_item_id":"null;204153583",
            "age":28
          },
          {
            "click_50_seq_event_time":"null;1698180365",
            "gender":"male",
            "click_50_seq_ts":"1704292546132;1704292546132;1704292546132",
            "city":"Ningbo",
            "click_50_seq":"null;299049390",
            "follower_cnt":47,
            "follow_cnt":0,
            "item_cnt":0,
            "register_time":1697253820,
            "tags":1,
            "click_50_seq_playtime":"null;32.15018252408633",
            "user_id":"100024146",
            "click_50_seq_event":"null;click",
            "click_50_seq_item_id":"null;299049390",
            "age":28
          }
        ]