Java Code Examples for org.apache.hadoop.hbase.client.Result#getColumn()

The following examples show how to use org.apache.hadoop.hbase.client.Result#getColumn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicFraudHBaseService.java    From hadoop-arch-book with Apache License 2.0 4 votes vote down vote up
public ProfilePojo[] getProfilesFromHBase(List<Long> userIds) throws IOException {
  
  ArrayList<Get> getList = new ArrayList<Get>();
  for (Long userId: userIds) {
    getList.add(new Get(generateProfileRowKey(userId)));
  }
  
  HTableInterface profileTable = hTablePool.getTable(DataModelConsts.PROFILE_TABLE);
  Result[] results = profileTable.get(getList);
  
  ProfilePojo[] profiles = new ProfilePojo[getList.size()];
  
  int counter = 0;
  for (Result result: results) {
    
    String[] fixedInfoValues = Bytes.toString(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.FIXED_INFO_COL).getValue()).split("|");
    String username = fixedInfoValues[0];
    int age = Integer.parseInt(fixedInfoValues[1]);
    long firstLogIn = Long.parseLong(fixedInfoValues[2]);
    
    long lastLogIn = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LAST_LOG_IN_COL).getValue());
    long logInCount = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_COUNT_COL).getValue());
    
    long logInCountHavingASell = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_SELLS_COL).getValue());
    long logInCountHavingAPurchase = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_PURCHASES_COL).getValue());
    
    long totalValueOfPastPurchases = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_PURCHASES_COL).getValue());
    long totalValueOfPastSells = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.TOTAL_VALUE_OF_PAST_SELLS_COL).getValue());
    
    long currentLogInSellsValue = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_SELLS_VALUE_COL).getValue());
    long currentLogInPurchasesValue = Bytes.toLong(result.getColumnLatest(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.CURRENT_LOG_IN_PURCHASES_VALUE_COL).getValue());
    
    HashSet<String> last20LogOnIpAddresses = new HashSet<String>();
    
    List<KeyValue> ipAddresses = result.getColumn(DataModelConsts.PROFILE_COLUMN_FAMILY, DataModelConsts.LOG_IN_IP_ADDERSSES);
    boolean isFirst = true;
    String lastLogInIpAddress = null;
    
    for (KeyValue kv: ipAddresses) {
      if (isFirst) {
        isFirst = false;
        lastLogInIpAddress = Bytes.toString(kv.getValue());
      } else {
        last20LogOnIpAddresses.add(Bytes.toString(kv.getValue()));
      }
    }
    
    ProfilePojo pojo = new ProfilePojo(username, age, firstLogIn, lastLogIn, lastLogInIpAddress,
    logInCount, logInCountHavingASell, totalValueOfPastSells,
    currentLogInSellsValue, logInCountHavingAPurchase,
    totalValueOfPastPurchases, currentLogInPurchasesValue,
    last20LogOnIpAddresses);
    
    profiles[counter++] = pojo;
  }
  
  return profiles;
}