Skip to content

HBase + Sqoop + Oozie

HBase + Sqoop + Oozie

Sqoop can be used to import data from the relational database into HBase. Although exporting data from HBase is not natively supported you can still manage it by putting Hive and HCatalog between HBase and Sqoop. Here’s how to do both importing and exporting with Oozie in Kerberised environment.

Contents

HOW TO

I used CDH 5.8.4 with Kerberos.

 

1. Import data to HBase with Sqoop and Oozie

HBase table doesn’t need to be prepared upfront. You may ask Sqoop to create it for you by specifying some of Sqoop arguments:

  • hbase-create-table
  • hbase-row-key pointing to column which will be used as HBase row key. If none is specified Sqoop will try to identify one by using primary key column, if it exists.
  • column-family defining HBase column family. Only one can be defined though. All imported columns will be put into this column family.

 
To create an Oozie workflow Sqooping data into HBase you need to:

  • specify HBase credentials in the workflow:

  • define HBase config parameters by uploading to HDFS and attaching hbase-site.xml as “job-xml” configuration file. It needs to be in the workflow global job config section, otherwise Oozie won’t be able to connect to HBase. hbase-site.xml needs to contain at least following properties:

    Note: Instead of attaching hbase-site.xml you may define mentioned properties in the workflow global config section. You may add some additional Oozie configurations in this section as well.

  • attach following jar files with action file property:
    • jdbc connection jar i.e. sqljdbc4.jar if you connect to SQLServer
    • hbase-client.jar
    • hbase-protocol.jar
    • hbase-hadoop-compat.jar

    Note: Instead of adding those jars to the job, you may put them into oozie libs folder. Oozie will then pick them up automatically. To set up such folder you should specify in Oozie job.properties 2 parameters: oozie.libpath pointing to folder with jars and oozie.use.system.libpath=true.

 
Here’s a complete Oozie workflow for importing data from SQLServer database to HBase:

 

2. Export data from HBase with Sqoop, Hive and Oozie

Exporting data from HBase with Sqoop is not supported. To workaround this you may create a Hive table on top of HBase table and then export the data using Sqoop and HCatalog.

In order to make it work you first need to create a Hive table mapped to the one in HBase. Your Hive and HBase tables may have different column names (although then mapping needs to be specified with mapping parameter – for details check Hive-HBase post). Then you need to create a table on database side prior to loading. This table needs to have the same column names as the Hive table as it’s required by HCatalog.

To make it work through Oozie you need to:

  • specify HCatalog credentials with metastore uri and principal properties
  • specify HBase credentials

  • attach hive-site.xml with file property. It should contain following properties:

    Note: There’s no way to put those as workflow configuration properties.

  • define HBase config parameters by uploading to HDFS and attaching hbase-site.xml as “job-xml” configuration file. It needs to be in the workflow global job config section, otherwise Oozie won’t be able to connect to HBase. hbase-site.xml needs to contain at least following properties:

    Note: Instead of attaching hbase-site.xml you may define mentioned properties in the workflow global config section. You may add some additional Oozie configurations in this section as well.l.

  • add skip-dist-cache property to avoid error:

  • attach following jar files with action file property:
    • jdbc connection jar i.e. sqljdbc4.jar if you connect to SQLServer
    • hbase-client.jar
    • hbase-protocol.jar
    • hbase-hadoop-compat.jar

    Note: Instead of adding those jars to the job, you may put them into oozie libs folder. Oozie will then pick them up automatically. To set up such folder you should specify in Oozie job.properties 2 parameters: oozie.libpath pointing to folder with jars and oozie.use.system.libpath=true.

 
Here’s a complete Oozie workflow for exporting data from HBase to SQLServer database using HCatalog:

HBase table always holds a row key, which then also needs to be present in the Hive table. To omit that during the export use Sqoop export columns parameter specifying set of columns to be exported into the database.

Leave a Reply

Your email address will not be published. Required fields are marked *