Java Time Format formatStartRowKeyString(String id, String timestampStart)

Here you can find the source of formatStartRowKeyString(String id, String timestampStart)

Description

HBase takes in a string to start the scan at.

License

Apache License

Parameter

Parameter Description
id id to be used in HBase scan
timestampEnd the timestamp representing an end time for HBase scan

Return

a string value to use in Hbase scan as an end bound.

Declaration

public static String formatStartRowKeyString(String id, String timestampStart) 

Method Source Code

//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();
    }
}

Related

  1. formatRemainingTime(float seccounds)
  2. formatRuntime(long runtime)
  3. formatRuntime(long time, boolean fixedlength)
  4. formatSample(final int aValue, final long aTimestamp)
  5. formatSignificantElapsedTime(final long seconds)
  6. formatStrDateTime(String stringDateTime)
  7. formatString(String agentId, long agentStartTime, long transactionSequence)
  8. formattedStats(String pExecTime, int pTxns)
  9. formattedUnixTime()