设为首页 加入收藏

TOP

RCFileInputFormat的使用方法
2014-11-24 07:17:42 来源: 作者: 【 】 浏览:0
Tags:RCFileInputFormat 使用方法

在使用RCFileInputFormat时可以设置需要读取的列的序号:

/**

* Sets read columns' ids(start from zero) for RCFile's Reader. Once a column

* is included in the list, RCFile's reader will not skip its value.

*

*/

public static void setReadColumnIDs(Configuration conf, ArrayList ids) {

String id = toReadColumnIDString(ids);

setReadColumnIDConf(conf, id);

}

如果使用RCFileInputFormat,在map当中传入的value为数据库表的一行。如要读取该行的每一列可以使用如下方法:

String[] columns = new String[columnNum];

for(int i=0;i
columns[i]= new String(value.get(i).getData(),value.get(i).getStart(),

Value.get(i).getLength());

}

其中,columnNum为读取的列数,然后在for循环中构造每一列。在这里可能会有疑问的地方,为什么每一列还需要start和length呢?因为value.get(i).getData()获取的是该行所有列的数据,不是针对该列的数据,所以需要“开始位置”和“长度”。在这里我们或许还可以推定:该行所有列value.get(i).getData()的方法其实是共享了一个byte数组。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言需要注意的问题 下一篇Go1.1性能测试报告(和C差距在10%..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·MySQL 安装及连接-腾 (2025-12-25 06:20:28)
·MySQL的下载、安装、 (2025-12-25 06:20:26)
·MySQL 中文网:探索 (2025-12-25 06:20:23)
·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)