2014-03-04 3 views
0

하이브 테이블 (Hadoop 2.2.0.2.0.6.0-101)에서 필드 값의 분포를 계산하는 map-reduce 작업을 작성하려고합니다.MapReduce에서 HCatalog를 사용하여 하이브 테이블

입력 하이브 테이블 "ATABLE": 예를 들어

+------+--------+ 
! name | rating | | 
+------+--------+ 
| Bond | 7  | 
| Megre| 2  | 
! Holms| 11 | 
| Puaro| 7  | 
! Holms| 1  | 
| Puaro| 7  | 
| Megre| 2  |  
| Puaro| 7  | 
+------+--------+ 

지도-감소 하이브 또한 다음과 같은 출력 테이블을 생성해야 작업을 :

+--------+-------+--------+ 
| Field | Value | Count | 
+--------+-------+--------+ 
| name | Bond | 1 | 
| name | Puaro | 3 | 
| name | Megre | 2 | 
| name | Holms | 1 | 
| rating | 7  | 4 | 
| rating | 11 | 1 | 
| rating | 1  | 1 | 
| rating | 2  | 2 | 
+--------+-------+--------+ 

는 내가 필요로하는 필드 이름/값을 얻으려면 HCatalog 메타 데이터에 액세스하기 위해 map 메소드 (org.apache.hadoop.mapreduce.Mapper)에서 이것을 사용할 수 있습니다. http://java.dzone.com/articles/mapreduce-hive-tables-using

0을 예제로 사용하려고합니다.

protected void map(WritableComparable key, HCatRecord value, 
org.apache.hadoop.mapreduce.Mapper.Context context) 
throws IOException, InterruptedException { 

// Get table schema 
HCatSchema schema = HCatBaseInputFormat.getTableSchema(context); 

Integer year = new Integer(value.getString("year", schema)); 
Integer month = new Integer(value.getString("month", schema)); 
Integer DayofMonth = value.getInteger("dayofmonth", schema); 

context.write(new IntWritable(month), new IntWritable(DayofMonth)); 
} 

중단 경고 :이 예에서

코드는하지만 많이 사용 중단 경고 생산 때문에 컴파일에 HCatalog를 사용하는 유사한 예를 찾기 위해

HCatRecord 
HCatSchema 
HCatBaseInputFormat.getTableSchema 

, 최신하지지도 - 감소 사용되지 않는 인터페이스?

감사합니다.

답변

0

Cloudera examples 중 하나의 예제를 사용하고 this blog에 주어진 프레임 워크를 사용하여 코드를 컴파일했습니다. pom.xml에 hcatalog에 대한 maven repo를 추가해야했습니다. 이 예제는 새로운 mapreduce API를 사용하고 사용되지 않는 mapredduce API는 사용하지 않습니다. 희망이 도움이됩니다.

 <dependency> 
     <groupId>org.apache.hcatalog</groupId> 
     <artifactId>hcatalog-core</artifactId> 
     <version>0.11.0</version> 
     </dependency>