利用hadoop命令rcc生成Record 一种简单的方式实现自定义的writable对象

 
hadoop 的bin目录下面一个rcc命令,网上介绍很少。看了一下源码。发现可以用来生成 java和c++的hadoop Record 类代码,比起自己直接实现writable 接口,简单很多而且不容易出错,不妨试一下。具体方法如下:
 
    
>rcc
Usage: rcc --language [java|c++] ddl-files
 
1 新建 ddl文件
 
    
>vim stud.ddl
module com.xschao.bean {
class Stud{
ustring name;
long id;
int age;
ustring time;
}
}

其他的类型补充,具体是啥自行脑补:
 
      
"\"byte\"",
"\"boolean\"",
"\"int\"",
"\"long\"",
"\"float\"",
"\"double\"",
"\"ustring\"",
"\"buffer\"",
"\"vector\"",
"\"map\"",


2 执行编译命令
 
    
> rcc --language java stud.ddl
查看生成的文件:

 
    
>tree
.
|-- com
| `-- xschao
| `-- bean
| `-- Stud.java
|-- command_example.sh
`-- stud.ddl
3 directories, 3 files
Stud.java即为生成的java代码
 
    
// File generated by hadoop record compiler. Do not edit.
package com.xschao.bean;
public class Stud extends org.apache.hadoop.record.Record {
private static final org.apache.hadoop.record.meta.RecordTypeInfo _rio_recTypeInfo;
private static org.apache.hadoop.record.meta.RecordTypeInfo _rio_rtiFilter;
private static int[] _rio_rtiFilterFields;
static {
_rio_recTypeInfo = new org.apache.hadoop.record.meta.RecordTypeInfo("Stud");
_rio_recTypeInfo.addField("name", org.apache.hadoop.record.meta.TypeID.StringTypeID);
_rio_recTypeInfo.addField("id", org.apache.hadoop.record.meta.TypeID.LongTypeID);
_rio_recTypeInfo.addField("age", org.apache.hadoop.record.meta.TypeID.IntTypeID);
_rio_recTypeInfo.addField("time", org.apache.hadoop.record.meta.TypeID.StringTypeID);
}
private String name;
private long id;
private int age;
private String time;
public Stud() { }
public Stud(
final String name,
final long id,
final int age,
final String time) {
this.name = name;
this.id = id;
this.age = age;
this.time = time;
}
。。。。。。。。。。。。。。。。。。。。。


ok










格格巫--蓝精灵- 

你可能感兴趣的:(hadoop)