2017-12-11 2 views
0

내부 및 외부 테이블과 파티션 및 파티션되지 않은 하이브 테이블에 아카이브 및 제거 메커니즘을 적용하려고합니다.하이브 테이블 아카이브

나는 site_visitors 테이블을 가지고 있으며 visit_date로 파티션되어 있습니다. 그리고 지난 1 년 동안 사용자가 내 사이트를 방문하지 않은 site_visitors 테이블 데이터를 보관하려고했습니다. 동시에이 보관 된 데이터를 동일한 테이블 디렉토리에 보관하고 싶지 않습니다. 특정 위치에 데이터를 보관할 수 있습니다.

답변

1

HDFS 디렉토리의 파티션에서 처리 할 수 ​​있습니다. 아래에서 그 중 하나를 달성 할 수 있습니다.

귀하의 내부 테이블/홈페이지 표는 HDFS의 꼭대기에 앉아되며, 당신은 단지 데이터를 보관하고자하는 경우 디렉토리는 HDFS 위에 아카이브 테이블을 만들 수 있습니다

hdfs:namenonde/user/hive/warehouse/schema.db/site_visitors/visit_date=2017-01-01 hdfs:namenonde/user/hive/warehouse/schema.db/site_visitors/visit_date=2017-01-02 hdfs:namenonde/user/hive/warehouse/schema.db/site_visitors/visit_date=2017-01-03 아래처럼 보일 또는 것 파티션을 HDFS의 다른 위치로 덤프 할 수 있습니다. 어쨌든 HDFS 위치는 다음과 같습니다.

hdfs:namenonde/hdfs_location/site_visitors/visit_date=2017-01-01 hdfs:namenonde/hdfs_location/site_visitors/visit_date=2017-01-02 hdfs:namenonde/hdfs_location/site_visitors/visit_date=2017-01-03

당신은 UNIX 스크립트 나 자바 스크립트 또는 파티션 날짜를 기준으로 다른 아카이브 HDFS 위치에 하나 개의 HDFS 위치에서 파일을 이동 환경에서 사용되는 다른 언어로 실행할 수 있습니다.

또한 데이터를 아카이브 테이블로로드하고 원래 테이블에 데이터를 놓을 수있는 다음 방법으로 수행 할 수도 있습니다. 귀하의 제안에 대한

#!bin/bash 
 
ARCHIVE=$1 
 
now=$(date +%Y-%m-%d) 
 
StartDate=$now 
 
#archive_dt will give a date based on the ARCHIVE date and that be will used for alterations and loading 
 
archive_dt=$(date --date="${now} - ${ARCHIVE} day" +%Y-%m-%d) 
 
EndDate=$archive_dt 
 
#You can use hive or beeline or impala to insert the data into archive table, i'm using beeline for my example 
 
beeline -u ${CONN_URL} -e "insert into table ${SCHEMA}.archive_table partition (visit_date) select * from ${SCHEMA}.${TABLE_NAME} where visit_date < ${archive_dt}" 
 
#After the data been loaded to the archive table i can drop the partitions in original table 
 
beeline -u ${CONN_URL} -e "ALTER TABLE ${SCHEMA}.main_table DROP PARTITION(visit_date < ${archive_dt})" 
 
#Repair the tables to sync the metadata after alterations 
 
beeline -u ${CONN_URL} -e "MSCK REPAIR TABLE ${SCHEMA}.main_table; MSCK REPAIR TABLE archiveSchema.archive_table"

+0

감사 강탈을. 이것은 좋은 접근 방법입니다. HBase 테이블에서 이전 데이터를 보관하려면 어떻게해야합니까? – RahulN

+0

내 대답이 도움이되었다고 생각하면 내 대답에 체크하십시오. – roh

+0

HBase 질문을 별도의 질문으로 요청하면,이 경우 광산 이외의 많은 답변을들을 수 있습니다. 당신이 내 제안을 좋아하길 바래. – roh