Using User-Supplied Metadata in Read Operations

You can retrieve the user-supplied metadata with the help of APIs below. For more information, see Using User-Supplied Metadata.

  • GetRequest API: You can use the GetRequest API to retrieve the user-supplied metadata of a single row. After executing the GetRequest API to retrieve the row, given a table name and primary key, you can retrieve the metadata by calling the getLastWriteMetadata() method. The operation returns a GetResult object that contains the retrieved data. If no metadata exists, it returns null.
    See the readRowMetadata() in ManageUserSuppliedMetadata.java for more details, available in the examples here.
    /*Method to fetch a user-supplied metadata using GET API*/
    private static void readRowMetadata(NoSQLHandle handle, int acctId) throws Exception {
            GetRequest gr = new GetRequest()
                .setKey(new MapValue().put("acct_Id", acctId)) //key of the row to fetch
                .setTableName(tableName);                     //table name
     
            GetResult gres = handle.get(gr);
            String rm= gres.getLastWriteMetadata();
     
            if (rm != null) {
                System.out.println("Row metadata for acct_Id " + acctId + ": " + rm);
            } else {
                System.out.println("No metadata found for acct_Id " + acctId);
            }
          }
  • QueryRequest API: You can write a SQL SELECT statement using the QueryRequest API to explicitly fetch user-supplied metadata. This allows metadata to be returned as part of the result set. It's especially helpful when you want to view the user-supplied metadata across multiple rows for data clarification or analysis purposes. See the readAllRowMetadataViaQuery() in ManageUserSuppliedMetadata.java for more details, available in the examples here.