Monday, February 20, 2017

Sqoop Import RDBMS Table into HDFS


  • Before moving the RDBMS Table data from Relational data base to Hadoop HDFS, We need to ensure whether table along with the data exists or not.
  • use SQOOP IMPORT to import the Relational table data into HDFS.
For example:

Practical Steps

Let us practically try with an example for this scenario.
Step 1: Log in to Mysql database:
Step 2: Create a Database called StudentInfo.
Step 3: Use the newly created Databases
step 4: Create a table called student in Mysql
step 5: Insert values into student using Mysql INSERT command and then using select check whether the values are properly inserted or not.
Step 6: Use SQOOP IMPORT to import the above RDBMS table into HDFS
Use the following SQOOP IMPORT command :
You can see the SQOOP Import execution like something below.
Now let us see the output on our Command shell:

Friday, February 17, 2017

How to: Oozie + Sqoop + Hive


Importing data directly into Hive is a great way to quickly enable your Hadoop desires. Some times it’s useful to schedule such a job in an Oozie workflow. In this post, we’ll investigate using Sqoop to import data from MySQL into Hive executed by Oozie.

THE BASICS

Using Sqoop to import data into hive via Oozie can be accomplished in 3 easy steps:
  1. Copy your hive-site.xml into HDFS
  2. Copy your mysql JDBC jar into HDFS
  3. Create an Oozie workflow that has a Sqoop action, includes the hive-site.xml in a “file” element of the action, and includes the mysql JDBC jar in a “archive” element of the action
  4. Run your Oozie workflow

EXAMPLE

Here is an example workflow:
<workflow-app name="sqoop-to-hive" xmlns="uri:oozie:workflow:0.4">
    <start to="sqoop2hive"/>
    <action name="sqoop2hive">
        <sqoop xmlns="uri:oozie:sqoop-action:0.2">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <command>import --connect jdbc:mysql://mysql.example.com/sqoop --username sqoop --password sqoop --table test --hive-import --hive-table test</command>
            <archive>/tmp/mysql-connector-java-5.1.31-bin.jar#mysql-connector-java-5.1.31-bin.jar</archive>
            <file>/tmp/hive-site.xml#hive-site.xml</file>
        </sqoop>
        <ok to="end"/>
        <error to="kill"/>
    </action>
    <kill name="kill">
        <message>Action failed</message>
    </kill>
    <end name="end"/>
</workflow-app>
And its corresponding hive-site.xml:
<configuration>

  <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:derby:;databaseName=/var/lib/hive/metastore/metastore_db;create=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
  </property>

  <property>
    <name>hive.metastore.uris</name>
    <value>thrift://sqoop2.example.com:9083</value>
  </property>

</configuration>

KEY POINTS

  1. Hive needs to be configured to use a remote metastore. This is because Sqoop will be ran from any node in your MapReduce cluster. hive-site.xml should be included since Sqoop needs to be able to tell Hive which metastore to write to at minimum. To do this, we set hive.metastore.uris in the hive-site.xml. In the above example, hive.metastore.uris is set to “thrift://sqoop2.example.com:9083″.
  2. hive-site.xml should be uploaded to HDFS and included in the workflow.xml. In the above example, the hive-site.xml file has been uploaded to /tmp/hive-site.xml in HDFS.
  3. The MySQL JDBC jar should be uploaded to HDFS and included in the workflow.xml. In the above example, the MySQL JDBC jar file has been uploaded to /tmp/mysql-connector-java-5.1.31-bin.jar.
  4. Sqoop first imports all data into HDFS, then imports that data into Hive. To do so, Sqoop creates a hive script file and calls the the hive command line directly.
  5. Make sure to include the share lib by setting oozie.use.system.libpath to “true” in the oozie job configuration.

TROUBLE SHOOTING

Q: FILE ALREADY EXISTS EXCEPTION IN TASK LOGS:

ERROR org.apache.sqoop.tool.ImportTool  - Encountered IOException running import job: org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory <path> already exists
A: Sqoop imports into hive first transfers the data to ‘/user/<username>/<table>’ in HDFS, then imports the data into Hive. If this process failed before, then the import directory may already exist. The solution is to remove that directory.

Q: TABLE ALREADY EXISTS EXCEPTION IN TASK LOGS:

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. AlreadyExistsException(message:Table test already exists)
A: The –create-hive-table option is being used and the table already exists in Hive. The table can either be dropped or the –create-hive-table option can be removed from the command.

Q: HIVE IMPORT IS STARTING, BUT SEEING AN ERROR BEFORE FINISHING.

Typically log messages like:
INFO  org.apache.sqoop.hive.HiveImport  - Loading uploaded data into Hive
before:
Intercepting System.exit(1)
are seen.
A: Normally, the hive-site.xml is missing, not in workflow.xml, or not correctly configured. See the example and “key points” section above.

Q: CLASS NOT FOUND EXCEPTION IN THE LAUNCHER JOB LOGS:

java.lang.ClassNotFoundException: Class org.apache.oozie.action.hadoop.SqoopMain not found
A: The share lib hasn’t been included! It can be included by including oozie.use.system.libpath=true in the job configuration passed when submitting the job.

Q: MISSING DRIVER CLASS IN LAUNCHER JOB LOGS:

ERROR org.apache.sqoop.Sqoop  - Got exception running Sqoop: java.lang.RuntimeException: Could not load db driver class: com.mysql.jdbc.Driver
A: Driver can’t be found. Including the JDBC driver jar in “archives” section of your workflow should fix this.

SUMMARY

Topics covered include an overview of “key points”, basic troubleshooting, and a simple walk through to Sqoop data from MySQL to Hive. Hopefully this helps you schedule your sqoop to hive jobs.
The code examples are available at https://github.com/ingesttips/examples.

Tuesday, February 14, 2017

Importing data from RDBMS into Hive using create-hive-table of sqoop

Importing data from RDBMS into Hive using create-hive-table of sqoop


In the Importing data from RDBMS into Hive i blogged about how to import data from RDBMS into Hive using Sqoop. In that case the import command took care of both creating table in Hive based on RDMBS table as well as importing data from RDBMS into Hive. But Sqoop can also be used to import data stored in HDFS text file into Hive. I wanted to try that out, so what i did is i created the contact table in Hive manually and then used the contact table that i exported as text file into HDFS as input
  1. First i used sqoop import command to import content of Contact table into HDFS as text file. By default sqoop will use , for separating columns and newline for separating
    
    sqoop import --connect jdbc:mysql://macos/test --table contact -m 1
    
    After import is done i can see content of the text file by executing hdfs dfs -cat contact/part-m-00000 like this
  2. After that you can use sqoop to create table into hive based on schema of the CONTACT table in RDBMS. by executing following command
    
    sqoop create-hive-table --connect jdbc:mysql://macos/test --table Address --fields-terminated-by ','
    
  3. Last step is to use Hive for loading content of contact text file into contact table. by executing following command.
    
    LOAD DATA INPATH 'contact' into table contact;

Wednesday, February 1, 2017

OBIEE platform DBUSER password reset

Often you may find that when you come to start and OBIEE environment, it may fail with errors relating to the fact the OBIEE platform and mds accounts are either locked, or the stored passwords within the OBIEE configuration are out of step with whats held in the database.  You may see errors in the bi_server.log file such as :-
creating connection for pool “rtd_datasource”: ORA-28000: the account is locked
<BEA-001129> <Received exception while creating connection for pool “mds-owsm”: ORA-28001: the password has expired
When querying the DBA_USERS table within the database, you may discover the accounts are locked/expired :-
SQL> select username,account_status from dba_users where username like ‘DEV%';
USERNAME                    ACCOUNT_STATUS
—————————— ——————————–
DEV_BIPLATFORM  EXPIRED
DEV_MDS                        EXPIRED
If you do know the password, you can get away with reseting the account with the same password i.e.
alter user DEV_MDS identified by <original_password>;
alter user DEV_BIPLATFORM identified by <original_password>;     

You may not know the password, so you may end up having to reset the password as listed below.

alter user DEV_MDS identified by DEV_MDS;
alter user DEV_BIPLATFORM identified by DEV_BIPLATFORM;

Once reset, you will beable to test via a SQL * Plus connection.
However the various connections configured within OBIEE will need to be reset before you can successfully restart the OBIEE environment. The following steps below take you through the areas you will need to reset the DEV_MDS and DEV_BIPLATFORM password if you have had to reset the password with a new password in the steps above
Login to the Web Logic Console i.e. http://hlcdb01:7001/console
navigate to bifoundation_domain –> Services –> Data Sources. Check each data source for where the passwords are storeed typically you will need to modify these :-
bip_datasource > connection pool tab, reset the password for DEV_BIPLATFORM
EPMSystemRegistry > connection pool tab, reset the password for DEV_BIPLATFORM
mds_owsm > connection pool tab, reset the password for DEV_MDS
Click save and apply, a full restart will be required once all steps are performed.
Next step is to Login to the OBIEE Enterprise Manager Console i.e. http://hlcdb01:7001/em. You will need to reset the stored password for the NQS Scheduler, otherwise the service will fail to start
  • Expand “Business intelligence” menu on the left;
  • Click the “Deployment” tab;
  • Click the “Scheduler” tab under deployment;
  • Click “Lock and Edit Configuration” button;
  • Set the password and hit “Apply”;
  • Click the “Activate Changes” button;
Once all new passwords have been applied, a full restart, and all services should now start successfully

Oracle: Export empty tables


   


When taking a database dump from Oracle 11g recently, I found that the export did not include tables that had 0 rows. The Oracle11g instance implements a space saving measure where if your table has no data, it will not be exported. Space is allocated only when you add data to the table.
A workaround to the issue is to pre-allocate some space to such empty tables. Execute the following oracle queries to allocate space for all tables before taking the export:
select 'alter table '||table_name||' allocate extent;'
from dba_tables
where segment_created = 'NO'
and owner = 'DB_USER;

Running the above query will generate some alter table statements for all tables with empty data. Executing these SQL statements will allocate space to the empty tables and allow you to export and import such tables.

How To Fix Hive – Partition Table Query Failed When Stored As Parquet

This article is about the bug in Hive filtering option, when the partition table query stored as parquet. Big data developers will help y...