How do we get the 1000 tables description using hive?

前端 未结 2 1945
甜味超标
甜味超标 2021-01-25 00:27

I have 1000 tables, need to check the describe

; for one by one. Instead of running one by one, can you please give me one command to fetch \"N\"
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-25 01:07

    You can make a shell script and call it with a parameter. For example following script receives schema, prepares list of tables in the schema, calls DESCRIBE EXTENDED command, extracts location, prints table location for first 1000 tables in the schema ordered by name. You can modify and use it as a single command:

    #!/bin/bash
    
    #Create table list for a schema (script parameter)
    HIVE_SCHEMA=$1
    echo Processing Hive schema $HIVE_SCHEMA...
    tablelist=tables_$HIVE_SCHEMA
    
     hive -e " set hive.cli.print.header=false; use $HIVE_SCHEMA; show tables;" 1>  $tablelist
    
    #number of tables
    tableNum_limit=1000
    
    #For each table do:
    for table in $(cat $tablelist|sort|head -n "$tableNum_limit") #add proper sorting
     do 
    
     echo Processing table $table ...
    
         #Call DESCRIBE
         out=$(hive client -S -e "use $HIVE_SCHEMA; DESCRIBE EXTENDED $table")
    
         #Get location for example
         table_location=$(echo "${out}" | egrep -o 'location:[^,]+' | sed 's/location://')
         echo Table location: $table_location
         #Do something else here
    
    done 
    

提交回复
热议问题