我在Postgres中有一个表,我想将其移动到Hbase

我在Postgres中有一个表,我想将其移动到Hbase,hbase,Hbase,我在Postgres中有一个表,但现在我应该实现Hbase作为后端数据库,所以我想将下面的表移动到Hbase中,如何重新设计这个表?我是Hbase的新手 id geom osm_id name type 1 00003381C75CBE6443 24254755 Millenium Hall office 2 00003382D5B5D76S3G ... ... 您需要在hbase中创建一个具有

我在Postgres中有一个表,但现在我应该实现Hbase作为后端数据库,所以我想将下面的表移动到Hbase中,如何重新设计这个表?我是Hbase的新手

id        geom            osm_id         name           type
1  00003381C75CBE6443    24254755   Millenium Hall     office
2  00003382D5B5D76S3G    ...
...

您需要在hbase中创建一个具有一个列族名称的表,并且您的所有列都将是该列族的一部分

您的id将成为hbase中的行键

hbase(main):002:0> create 'hbaseTable', 'column1'
0 row(s) in 1.2620 seconds

hbase(main):003:0> 
其中hbaseTable是您的名称空间,column1是您的表名。 然后,您可以使用thrift/native hbase API将数据保存到hbase表中

Configuration conf = HBaseConfiguration.create();
HTableInterface table = new HTable(conf, "hbaseTable".getBytes());

Put put = new Put(1.getBytes());// for id 1.
put.add("column1".getBytes(), "geom".getBytes(), 00003381C75CBE6443.getBytes());
put.add("column1".getBytes(), "osm_id".getBytes(), 24254755.getBytes());
put.add("column1".getBytes(), "name".getBytes(), Millenium Hall.getBytes());
put.add("column1".getBytes(), "type".getBytes(), office.getBytes());

puts.add(put);// same can do for other ids as well.


hTable.put(puts);

如果您只想将已经存在的表数据从postgres移动到hbase,请节省一些时间并使用。否则,如果要手动执行此操作,则由于hbase在创建表时没有显式定义列的概念,并且它将数据存储在ByteArray中,因此可以使用put命令put‘table_name’、‘1’、‘colfam:geom’、‘00003381C75CBE6443’。同样,对每一列执行此操作。

可能重复的