Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Threaded View
Hive, mail # user - Noob question on creating tables


Copy link to this message
-
Re: Noob question on creating tables
Sanjay Subramanian 2013-03-29, 20:38
Yes when u use EXTERNAL , then u effectively have delinked the table management from its data. So if you drop an EXTERNAL table, the data does not get deleted.
Best is if u don't like the data  , tomorrow u can drop partitions and add partitions pointing to another data LOCATION.

If you create an EXTERNAL table called foo_table_ext u will find a subdirectory /usr/hive/warehouse/foo_table_ext
But if you drop the table this subdirectory won't be deleted…also u have the freedom to "add" any location and partitions of your choice

Hope this clarifies…

sanjay

From: Mark <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
Reply-To: "[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>" <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
Date: Friday, March 29, 2013 1:25 PM
To: "[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>" <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
Subject: Re: Noob question on creating tables

Sweet this makes perfect sense. We are actually already using an ooze job that wait for input and does some pre-processing on the logs before finally archiving in HDFS. It would make sense to just attach some job to import this data and partition it by date at the same time.

Just one last question regarding external tables and tables that Hive manages. Am I correct to assume that when you let hive manager your table it moves everything where you want and it takes care of partitioning. But if I want to manage the directory structure myself, or use an existing one like we have, I will need to use the external keyword. Does that sound about right?

On Mar 29, 2013, at 12:45 PM, Sanjay Subramanian <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:

I agree. BASH is super easy for things like this

I have a daily alter partition script I call thru a java-action in Oozie (that Java class calls a HiveClient interface implementation)
Example script that I run for us where date and server are partitions
for r in $(hdfs dfs -ls  /path/to/directory/in/hdfs |awk '{print $8}')
  do
    datestr=$(echo $r|cut -d "/" -f 10)
    serverstr=$(echo $r|cut -d "/" -f 11)
    $HIVE_HOME/bin/hive -hiveconf hive.root.logger=INFO,console -e "ALTER TABLE my_table ADD PARTITION (header_date='$datestr' , header_servername='$serverstr') LOCATION '$r';"
done

From: Dean Wampler <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
Reply-To: "[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>" <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
Date: Friday, March 29, 2013 11:37 AM
To: "[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>" <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>>
Subject: Re: Noob question on creating tables

That's a drawback of external tables, but it's actually not as difficult as it sounds. It's easy to write a nightly "cron" job that creates the partition for the next day (or a job per month...), if someone on your team has some bash experience. Other job scheduling tools should support this too. Here's an example. First, a hive script that uses parameters for the date (Hive v0.8 or newer):

-- addlogpartition.hql
ALTER TABLE log ADD IF NOT EXISTS PARTITION (year = ${YEAR}, month = ${MONTH}, day = ${DAY});

Then, run this bash script AFTER MIDNIGHT:

#!/bin/bash
YEAR=$(date +%Y)       # returns the string "2013" today.
MONTH=$(date +%m)   # returns the string "03" today, with the leading zero.
DAY=$(date +%d)          # returns the string "29" today. Will prefix with 0 for dates < 10.

# Assumes /path/to/2013/03/29 is the correct directory name:
/path/to/hive -f /path/to/addlogpartition.hql -d YEAR=$YEAR -d MON=$MONTH -d DAY=$DAY
(Of course, all the /path/to will be different...)

So, be careful of how how "03" vs. "3" is handled in both the ALTER TABLE statement and the path. Off hand, I don't know if Hive will complain if you use 03 as an integer value in the ALTER TABLE statement.
On Fri, Mar 29, 2013 at 1:16 PM, Mark <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:
Thanks

Does this mean I need to create a partition for each day manually? There is no way to have infer that from my directory structure?

On Mar 29, 2013, at 10:40 AM, Sanjay Subramanian <[EMAIL PROTECTED]<mailto:[EMAIL PROTECTED]>> wrote:

Dean Wampler, Ph.D.
thinkbiganalytics.com<http://thinkbiganalytics.com/>
+1-312-339-1330
CONFIDENTIALITY NOTICE
=====================This email message and any attachments are for the exclusive use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message along with any attachments, from your computer system. If you are the intended recipient, please be advised that the content of this message is subject to access, review and disclosure by the sender's Email System Administrator.
CONFIDENTIALITY NOTICE
=====================This email message and any attachments are for the exclusive use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message along with any attachments, from your computer system. If you are the intended recipient, please be advised that the content of this message is subject to access, review and disclosure by the sender's Email System Administrator.