加入收藏 | 设为首页 | 会员中心 | 我要投稿 我爱故事小小网_铜陵站长网 (http://www.0562zz.com/)- 视频终端、云渲染、应用安全、数据安全、安全管理!
当前位置: 首页 > 教程 > 正文

RCFileInputFormat的使用技巧

发布时间:2021-12-13 16:18:31 所属栏目:教程 来源:互联网
导读:在使用RCFileInputFormat时可以设置需要读取的列的序号: /** * Sets read columns ids(start from zero) for RCFiles Reader. Once a column * is included in the list, RCFiles reader will not skip its value. * */ public static void setReadColumnIDs
在使用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<Integer> ids) {
 
    String id = toReadColumnIDString(ids);
 
    setReadColumnIDConf(conf, id);
 
  }
 
如果使用RCFileInputFormat,在map当中传入的value为数据库表的一行。如要读取该行的每一列可以使用如下方法:
 
String[] columns = new String[columnNum];
 
for(int i=0;i<columnNum;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数组。

(编辑:我爱故事小小网_铜陵站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读