zoukankan      html  css  js  c++  java
  • 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<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循环中构造每一列。在这里可能会有疑问的地方,为什么每一列还需要startlength呢?因为value.get(i).getData()获取的是该行所有列的数据,不是针对该列的数据,所以需要“开始位置”和“长度”。在这里我们或许还可以推定:该行所有列value.get(i).getData()的方法其实是共享了一个byte数组。

  • 相关阅读:
    gdbinit理解
    debug套路
    node 版本升级
    工作方式
    vscode 插件编写
    函数闭包与装饰器
    高阶函数与递归
    函数嵌套及作用域
    函数
    文件处理
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3078521.html
Copyright © 2011-2022 走看看