1. 程式人生 > >複製部分HBase表用於測試

複製部分HBase表用於測試

2013-04-02

周海漢/文

2013.4.2

可以將日期’08/08/16 20:56:29’從hbase log 轉換成一個 timestamp, 操作如下:

                    hbase(main):021:0> import java.text.SimpleDateFormat
                    hbase(main):022:0> import java.text.ParsePosition
                    hbase(main):023:0> SimpleDateFormat.new("yy/MM/dd HH:mm:ss").parse("08/08/16 20:56:29", ParsePosition.new(0)).getTime() => 1218920189000

也可以逆過來操作。

                    hbase(main):021:0> import java.util.Date
                    hbase(main):022:0> Date.new(1218920189000).toString() => "Sat Aug 16 20:56:29 UTC 2008"













$ bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable [--starttime=X] [--endtime=Y] [--new.name=NEW] [--peer.adr=ADR] tablename

hbase(main):001:0> import java.text.SimpleDateFormat => Java::JavaText::SimpleDateFormat hbase(main):002:0> import java.text.ParsePosition => Java::JavaText::ParsePosition

hbase(main):004:0> SimpleDateFormat.new(“yyyy/MM/dd HH:mm:ss”).parse(“2013/03/28 00:00:00”, ParsePosition.new(0)).getTime() => 1364400000000 hbase(main):005:0> SimpleDateFormat.new(“yyyy/MM/dd HH:mm:ss”).parse(“2013/03/28 00:00:10”, ParsePosition.new(0)).getTime() => 1364400010000

[[email protected] sh]$ hbase org.apache.hadoop.hbase.mapreduce.CopyTable Usage: CopyTable [general options] [–starttime=X] [–endtime=Y] [–new.name=NEW] [–peer.adr=ADR]

匯出部分資料到另一個表myolc,需先建立該表,也可以指定另一個叢集:

--peer.adr=server1,server2,server3:2181:/hbase

[[email protected] hbase]$ hbase org.apache.hadoop.hbase.mapreduce.CopyTable –starttime=1364400000000 –endtime=1364400010000 –new.name=myolc online_count

匯出實用工具可以將表的內容輸出成HDFS的序列化檔案,如下呼叫:

$ bin/hbase org.apache.hadoop.hbase.mapreduce.Export <tablename> <outputdir> [<versions> [<starttime> [<endtime>]]]

匯出2000秒資料

[[email protected] hbase]$ hbase org.apache.hadoop.hbase.mapreduce.Export online_count onlinecount 1 1364400000000 1364402000000

[[email protected] hbase]$ hadoop fs -ls /user/hbase/onlinecount Found 3 items -rw-r–r–   3 hbase supergroup          0 2013-04-01 15:56 /user/hbase/onlinecount/_SUCCESS drwxr-xr-x   - hbase supergroup          0 2013-04-01 15:55 /user/hbase/onlinecount/_logs -rw-r–r–   3 hbase supergroup        451 2013-04-01 15:56 /user/hbase/onlinecount/part-m-00000

匯入實用工具可以載入匯出的資料回到HBase,如下呼叫:

$ bin/hbase org.apache.hadoop.hbase.mapreduce.Import <tablename> <inputdir>

[[email protected] ~]$ hadoop fs -put olc onlinecount

[[email protected] ~]$ hbase shell

hbase(main):001:0> create ‘online_count’,’info’

 [[email protected] ~]$ hbase org.apache.hadoop.hbase.mapreduce.Import online_count onlinecount

如非註明轉載, 均為原創. 本站遵循知識共享CC協議,轉載請註明來源