Java Time Format formatEndRowKeyString(String id, String timestampEnd)

Here you can find the source of formatEndRowKeyString(String id, String timestampEnd)

Description

HBase takes in a string to end 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 formatEndRowKeyString(String id, String timestampEnd) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from w  ww. j  a  va  2s  .  com*/
     * HBase takes in a string to end the scan at. This method formats that
     * string. HBase will stop scan when the row key which represents this
     * string is encountered.
     * 
     * @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 formatEndRowKeyString(String id, String timestampEnd) {

        String endRowKeyString = null;

        if (timestampEnd != null && timestampEnd != "") {
            // format to ensure data at current timestamp is retrieved
            timestampEnd = formatTimestampEnd(timestampEnd);
        } else {
            // format to ensure all data for the given timestamp isretrieved
            id = formatId(id);
        }

        endRowKeyString = buildRowKeyFilterString(id, timestampEnd);

        return endRowKeyString;
    }

    /**
     * Formats a string timestamp to be used as the end bound filter string in
     * HBase scan. Adds 1 ms to it and makes it 13 digits
     * 
     * @param timestamp
     *            is the timestamp to be formated
     * @return a formated string to be used in HBase scan
     */
    public static String formatTimestampEnd(String timestamp) {

        if (timestamp == null || timestamp == "")
            return timestamp;

        timestamp = String.format("%013d", Long.parseLong(timestamp) + 1);

        return timestamp;
    }

    /**
     * Formats an id to be used as the end bound filter string in HBase scan.
     * Adds 1 to sensorId and a dash delimiter.
     * 
     * @param id
     *            to be formated
     * @return a formated string to be used in HBase scan
     */
    public static String formatId(String id) {
        if (id != null && id != "") {
            id = String.valueOf((Long.parseLong(id) + 1) + "-");
        }
        return id;
    }

    /**
     * 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. formatDateTimeString(final String dateTimeString, final boolean wrapForCodeUsage)
  2. formatDelay(long startTime, long endTime)
  3. formatElapsedTime(int seconds)
  4. formatElapsedTime(long elapsedTime)
  5. formatElapsedTime(long time)
  6. formatExecutionTime(long executionTime)
  7. formatExecutionTime(long ms)
  8. formatInformalTime(final String minuteRoundedName, final String minuteRoundingToken, final String informalHourName)
  9. formatMeasures(final int quartersPerMeasure, final double time, final int startOffset)