SQOOP - Execute Hive query with beeline

Preamble

This article describe how to execute an Hive query in SQOOP with beeline

Be sure to have enought rights to access database.

Query Hive with SQOOP and beeline 

Sqoop Hive query
#Declare Hive query
my_query='use default;show tables'

#Execute the beeline command with the Hive query
beeline -u 'jdbc:hive2://nn1:10000/;ssl=false' -n "$user_name" -p "$password" -e "$my_query"

Query Hive with SQOOP and beeline with HDFS file

Sqoop Hive query from HDFS file
#Get Hive Query from HDFS file
my_query='hdfs dfs -cat /user/full_path/hive_query.txt'

#Execute the beeline command with the Hive query
beeline -u 'jdbc:hive2://nn1:10000/;ssl=false' -n "$user_name" -p "$password" -e "$my_query"

Note: The Hive query has to be written in one line with semicolon to separate multiple Hive query.

Example:

Hive query
use default;show tables