Here you can find the source of formatStartRowKeyString(String id, String timestampStart)
Parameter | Description |
---|---|
id | id to be used in HBase scan |
timestampEnd | the timestamp representing an end time for HBase scan |
public static String formatStartRowKeyString(String id, String timestampStart)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w .j av a 2s . c om * HBase takes in a string to start the scan at. This method formats that * string. HBase will start scan at the row key which represents this * string. * * @param id * id to be used in HBase scan * @param timestampEnd * the timestamp representing an end time for HBase scan * @return a string value to use in Hbase scan as an end bound. */ public static String formatStartRowKeyString(String id, String timestampStart) { // timestamps are saved in HBase as 13 digits. Need to make timestamps // passed in from HTTP get request 13 digits long so HBase can use them // to filter scan. Otherwise 2 would be interpreted as 2000000000000 timestampStart = formatTimestampStart(timestampStart); // create row key filter strings to pass to scan class. // Scanner will get data starting at this value String startRowKeyString = buildRowKeyFilterString(id, timestampStart); return startRowKeyString; } /** * Formats timestamp value to be 13 digits long * * @param timestamp * string value representing a timestamp value * @return timestamp value that is 13 digits long */ public static String formatTimestampStart(String timestamp) { if (timestamp != null && timestamp != "") timestamp = String.format("%013d", Long.parseLong(timestamp)); return timestamp; } /** * Builds the row key filter string based on an id and timestamp. Does not * manipulate parameters. * * @param id * to be used in filter string * @param timestamp * to be used in filter string. Already formatted * @return a formatted value to use HBase scan */ public static String buildRowKeyFilterString(String id, String timestamp) { StringBuilder sb = new StringBuilder(); // if no id present then return null as all data should be retrieved if (id == null || id == "") return id; // id and timestamp else if (timestamp != null && timestamp != "") { sb.append(id); sb.append("-"); sb.append(timestamp); } // id no timestamp else { sb.append(id); } return sb.toString(); } }