title: Rules to be followed before creating a Hive partitioned table
body: <p>As part of my requirement, I have to create a new Hive table and insert into it programmatically. To do that, I have the following DDL to create a Hive table:</p>
  
  <pre><code>CREATE EXTERNAL TABLE IF NOT EXISTS countData (
      tableName String,
      ssn String,
      hiveCount String,
      sapCount String,
      countDifference String,
      percentDifference String,
      sap_UpdTms String,
      hive_UpdTms String)
  COMMENT 'This table contains record count of corresponding tables of all the source systems present on Hive &amp; SAP'
  ROW FORMAT DELIMITED
  FIELDS TERMINATED BY ','
  STORED AS TEXTFILE
  LOCATION '';
  </code></pre>
  
  <p>To insert data into a partition of a Hive table I can handle using an insert query from the program. Before creating the table, in the above DDL, I haven't added the "PARTITIONED BY" column as I am not totally clear with the rules of partitioning a Hive table. Couple of rules I know are </p>
  
  <ol>
  <li>While inserting the data from a query, partition column should be the last one.</li>
  <li>PARTITIONED BY column shouldn't be an existing column in the table.</li>
  </ol>
  
  <p><strong>Could anyone let me know if there are any other rules for partitioning a Hive table ?</strong>
  Also in my case, we run the program twice a day to insert data into the table and every time it runs, there could be 8k to 10k records. I am thinking of adding a PARTITIONED BY column for current date (just "mm/dd/yyyy") and inserting it from the code. 
  Is there a better way to implement the partition idea for my requirement, if adding a date (String format) is not recommended ?</p>