Time for action – importing data from a raw query
Let's see an example of an import where a raw SQL statement is used to select the data to be imported.
- Delete any existing output directory:
$ hadoop fs –rmr employees
- Drop any existing Hive employee table:
$ hive -e 'drop table employees'
- Import data using an explicit query:
sqoop import --connect jdbc:mysql://10.0.0.100/hadooptest --username hadoopuser -P --target-dir employees --query 'select first_name, dept, salary, timestamp(start_date) as start_date from employees where $CONDITIONS' --hive-import --hive-table employees --map-column-hive start_date=timestamp -m 1
- Examine the created table:
$ hive -e "describe employees"
You will receive the following response:
OK first_name string
Get Hadoop: Data Processing and Modelling now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.