Hive statistics using beeline and expect script

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, [email protected]
# 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://hive-server: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"
}

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *