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数组。

  • 相关阅读:
    树莓派4B(4G版本)安装Ubuntu 19.10
    PyQt5通过使用QSS语法制作精美界面
    PyQt5 界面设计和业务处理分离
    Python多线程同步
    PyQt界面
    pip设置
    Vim 常用配置
    python日期处理
    vue项目创建与使用
    vue 指令,成员,组件
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3078521.html
Copyright © 2011-2022 走看看