Home > Database > Mysql Tutorial > 复制部分HBase表用于测试

复制部分HBase表用于测试

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:30:03
Original
1035 people have browsed it

周海汉/文 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

周海汉/文

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
Copy after login

也可以逆过来操作。

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

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

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

[hbase@h46 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
Copy after login

[hbase@h46 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>]]]</endtime></starttime></versions></outputdir></tablename>
Copy after login

导出2000秒数据

[hbase@h46 hbase]$ hbase org.apache.hadoop.hbase.mapreduce.Export online_count onlinecount 1 1364400000000 1364402000000

[hbase@h46 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></inputdir></tablename>
Copy after login

[zhouhh@Hadoop48 ~]$ hadoop fs -put olc onlinecount

[zhouhh@Hadoop48 ~]$ hbase shell

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

?[zhouhh@Hadoop48 ~]$ hbase org.apache.hadoop.hbase.mapreduce.Import online_count onlinecount

相关博文:

  1. hbase shell中timestamp转为可读格式
  2. hadoop 中的 ClassNotFoundException
  3. 从HDFS分析数据到HBase
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template