복붙노트

[HADOOP] HBase의 타임 스탬프 기반 스캔?

HADOOP

HBase의 타임 스탬프 기반 스캔?

hbase 테이블 'test_table'의 예제에서 삽입 된 값은 다음과 같습니다.

Row1 - Val1 => t
Row1 - Val2 => t + 3
Row1 - Val3 => t + 5

Row2 - Val1 => t
Row2 - Val2 => t + 3
Row2 - Val3 => t + 5

스캔 'test_table'어디 버전 = t + 4 반환해야합니다

Row1 - Val1 => t + 3
Row2 - Val2 => t + 3

HBase에서 타임 스탬프 기반 검색 (시간 스탬프보다 작거나 같은 최신 값을 기준으로)을 어떻게 얻을 수 있습니까?

해결법

  1. ==============================

    1.다음 표를 고려하십시오.

    다음 표를 고려하십시오.

    hbase(main):009:0> create 't1', { NAME => 'f1', VERSIONS => 100 }
    hbase(main):010:0> put 't1', 'key1', 'f1:a', 'value1'
    hbase(main):011:0> put 't1', 'key1', 'f1:a', 'value2'
    hbase(main):012:0> put 't1', 'key1', 'f1:a', 'value3'
    hbase(main):013:0> put 't1', 'key2', 'f1:a', 'value4'
    hbase(main):014:0> put 't1', 'key2', 'f1:a', 'value5'
    hbase(main):015:0> put 't1', 'key1', 'f1:a', 'value6'
    

    다음은 모든 버전의 쉘 스캔입니다.

    hbase(main):003:0> scan 't1', {VERSIONS => 100 }
    ROW              COLUMN+CELL
     key1            column=f1:a, timestamp=1416083314098, value=value6
     key1            column=f1:a, timestamp=1416083294981, value=value3
     key1            column=f1:a, timestamp=1416083293273, value=value2
     key1            column=f1:a, timestamp=1416083291009, value=value1
     key2            column=f1:a, timestamp=1416083305050, value=value5
     key2            column=f1:a, timestamp=1416083299840, value=value4
    

    다음은 요청한 특정 타임 스탬프로 제한된 검사입니다.

    hbase(main):002:0> scan 't1', { TIMERANGE => [0, 1416083300000] }
    ROW              COLUMN+CELL
     key1            column=f1:a, timestamp=1416083294981, value=value3
     key2            column=f1:a, timestamp=1416083299840, value=value4
    

    Java 코드에서도 마찬가지입니다.

    package org.example.test;
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.client.*;
    import org.apache.hadoop.hbase.util.Bytes;
    import java.io.IOException;
    
    public class test {
        public static void main (String[] args) throws IOException {
            HTable table = new HTable(HBaseConfiguration.create(), "t1");
            Scan s = new Scan();
            s.setMaxVersions(1);
            s.setTimeRange (0L, 1416083300000L);
            ResultScanner scanner = table.getScanner(s);
            for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
                System.out.println(Bytes.toString(rr.getRow()) + " => " +
                        Bytes.toString(rr.getValue(Bytes.toBytes("f1"), Bytes.toBytes("a"))));
            }
        }
    }
    

    시간 범위 최대 값 지정은 제외됩니다. 즉, 최대 시간 소인 T를 갖는 모든 키의 최종 값을 얻으려면 범위의 상한값을 T + 1로 지정해야합니다

  2. from https://stackoverflow.com/questions/26880169/timestamp-based-scans-in-hbase by cc-by-sa and MIT license