0

I have a table that has more than 3,000+ tables and when I generate the DDLS for all of them, it gives me an error of " /user/hive Argument list to long".

I am trying to edit my code to scan through the first 1,000 first and then the next 1,000, and then the remaining. That way the argument can be split.

Here is my code:

 hiveDBName=$1;


 showcreate="show create table "
 showpartitions="show partitions "
 terminate=";"
 tables=`hive -e "use $hiveDBName;show tables;"`
 tab_list=`echo "${tables}"`

  for list in $tab_list
  do
         echo "Generating table script for " #${hiveDBName}.${list}
          showcreatetable=${showcreatetable}${showcreate}${hiveDBName}.${list}${terminate}

        done

        echo " ====== Create Tables ======= : "# $showcreatetable

 #Creates a filter ddls
 hive -e "use $hiveDBName; ${showcreatetable}"> a.sql
 #Removes the Warn: from the file
 grep -v "WARN" a.sql > /home/hive_ddls/${hiveDBName}_extract_all_tables.sql

 echo "Removing Filter File"
 #Remove Filter file
 rm -f a.sql

#Puts a ; after each create table statement in the document 
sed -i '/transient/s/$/;/' "/home/hive_ddls/${hiveDBName}_extract_all_tables.sql"

Is there any way to put a for loop in above script so that it splits the output by the thousands for it to run?

vikrant rana
  • 4,509
  • 6
  • 32
  • 72
James Davinport
  • 303
  • 7
  • 19

0 Answers0