简体   繁体   中英

Transfer data from MySQL to HBase

I am trying to insert data from MySQL to HBase using Python (not sqoop). There is a table called tblTest in MySQL with below schema and data:

create table tblTest(idTest int, idObj int, sName varchar(25));

insert into tblTest values (202, 7678, 'sMfg1'), (203, 7679, 'sMfg2'), (204, 7680, 'sMfg3');

I need to create an HBase table:

> create 'tblHTest', 'cf'

Now, how do I insert data into the HBase table (could you explain in python code)? Please correct my HBase schema accordingly. I am new to Python and HBase.

Thank you in advance.

There are some ways to connect to HBase from Python, and one of them (the one I use) is Thrift.

Take a look at the Thrift API , it is used not only for python, but PHP, perl, ruby and many other langages.

You will need to run the Thrift server (included within HBase, go for the second version of thrift)

$HBASE_DIR/bin/hbase start thrift2

Download and install thrift as well as all necessary package like python dev that will be used to generate the python files, then generate them:

thrift --gen py path-to/Hbase.thrift

You can then download and use those classes in you python code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM