Hadoop mostly deals with unstructured data. And all your structured data lives in relational databases. After you made necessary processing it on the Hadoop cluster you may need to bring your analysis to your data warehouse or to your RDBMS tables for further analysis so that unstructured data could compliment to structured database.
As I was playing around with HDInsight (Microsoft’s implementation of Apache Hadoop) on Azure I thought it will be useful to compile a step by step guide to integrate data from Hadoop cluster (HDInsight) using SQL Server Integration service.
Here I will be importing a simple key-value pairs from Hadoop cluster to a SQL Server table with two columns on the local machine.
Prepare what to import from Hadoop
Here I will be importing the analysis of the most common demo of a Hadoop job – Word Count. I am using HDInsight Preview and the WordCount sample comes as one of the default samples. After the job has been deployed I created an external table in Hive for the top ten words based on count.
If you are a newbie and just want to get started with HdInsight on Azure from scratch then follow the step by step guide: http://www.windowsazure.com/en-us/manage/services/hdinsight/get-started-hdinsight/. This link also guides you to deploy the WordCount sample job.
Create the Hive table
- Click Hive on the upper right to open the Hive console.
- Enter the following command to create a two column table named DaVinciWordCountTable from the WordCount sample output that was saved in the “DaVinciTop10Words” folder:
(word STRING,count INT)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘\t’
STORED AS TEXTFILE LOCATION ‘/user/admin/DaVinciTop10Words’;
Replace admin with the login username.
Note that the table is created as an EXTERNAL table to keep the folder targeted independent of the table. Also, note that you need only specify the folder in which the output file is located, not the file name itself.
- Click EVALUATE on the lower left.
- Enter the following commands to confirm that the two column table has been created:
- Click EVALUATE.
Then test if the external table is working fine by passing SQL query into it.
- Run the following command to query for the words with the top ten number of occurrences:
ORDER BY count DESC LIMIT 10
The results of this query are:
Now your data in the Hadoop is ready to be imported.
Create destination table in SQL Server Database
I just created a simple a table in a SQL Server database named HadoopData with following schema.
ODBC Driver for HDInsight
You need to download and install ODBC driver for HDInsight from the following link:
SSIS Package to Import data
- Create an Integration Service project using SQL Server data tools (or BIDS).
- The solution looked as below for me.
- Add a connection manager for Hadoop Hive (your source data!)
- Right Click on the Connection manager panel and choose New Connection.
- Choose ODBC and click Add.
- On Configure ODBC Connection Manager Click New and then Select Use Connection String on Connection Manager.
- On Select Data Source choose Machine Data Source tab and click New. Then on Create New Data Source choose System Data Source and click Next.
- Then choose HIVE and click Next and then Finish on the following screen.
- On Hive Data Source Configuration, Type a data source name. Also Host – This is the Hadoop cluster you have e.g. myhadoop.azurehdinsight.net. Finish it with user name and password to access your Hadoop cluster.
- Click OK to close the screens. Then test for the connection. Finally click OK to finish on Connection manager to finish the creation of connection manger to Hadoop data.
- Similarly, create a connection manager for the local database table.
- Add a control flow task and then add an ODBC Source and ADO.NET destination.
- Configure Hadoop External Table (Source) to use MyHadoopHiveDS connection manager. And also write SQL query to pull data from Hive table. Refer pic below.
- Configure destination (SQL DB Table) to write values to SQL Server data table.
- Run the package.
- Now go to the local DB table to check if data has written successfully.