Hive statistics using beeline and expect script

Datetime:2016-08-22 21:52:49          Topic: Hive           Share

Following expect script uses beeline interface to fetch statistics of tables within a database.

Use username and queuename with your environment values.

#!/usr/bin/expect -f

# hive_statistics, v0.1, 2016-05, d.robin@gmail.com
# Usage: ./hive_statistics [database_name]
set _database [lindex $argv 0]

if { $_database == ""} {
    set _database "default"
}

log_user 0
spawn beeline --showHeader=false -u jdbc:hive2://sndcdfrqhdpmn004:10000 -n username --hiveconf tez.queue.name=queuename;
expect "10000>"
send "use $_database;show tables;\r"
expect "10000>"
#puts $expect_out(buffer);
set _tables "[exec echo $expect_out(buffer) | awk {/\|/{print $2}}]"
#puts "$_tables"
puts "----------------------------------------------------"
puts "  Hive statistics                                   "
puts "----------------------------------------------------"

foreach table $_tables {
    send "DESCRIBE EXTENDED $table;\r"
    expect "10000>"

    set _table_desc $expect_out(buffer);
    #puts "$_table_desc"

    regexp "location:(\[^,\]+)" $_table_desc all  _location
    #puts "hdfs_location: $_location"
    set _size_location "[exec hdfs dfs -du -s -h $_location]"
    puts "\[ $table \]\n$_size_location"
}




About List