`
superlxw1234
  • 浏览: 550763 次
  • 性别: Icon_minigender_1
  • 来自: 西安
博客专栏
Bd1c0a0c-379a-31a8-a3b1-e6401e2f1523
Hive入门
浏览量:44355
社区版块
存档分类
最新评论

java api读取RCFile

 
阅读更多
private static List<String> showRCFile (Path src,Configuration conf) {
		List<String> list = new ArrayList<String>();
		try {
			FileSystem fs = FileSystem.get(src.toUri(), conf);
			long fileLen = fs.getFileStatus(src).getLen();
			FileSplit split = new FileSplit(src,0, fileLen, new JobConf(conf));
			RCFileRecordReader recordReader = new RCFileRecordReader(conf, split);
			LongWritable key = new LongWritable();
		    BytesRefArrayWritable value = new BytesRefArrayWritable();
		    Text txt = new Text();
		    String resultStr = null;
		    int y = 0;
		    while (recordReader.next(key, value)) {
		      //if (y == 10) break;
		      resultStr = "";
		      txt.clear();
		      for (int i = 0; i < value.size(); i++) {
		        BytesRefWritable v = value.get(i);
		        txt.set(v.getData(), v.getStart(), v.getLength());
		        resultStr = resultStr + txt.toString();
		        if (i < value.size() - 1) {
		          // do not put the TAB for the last column
		        	resultStr = resultStr + TAB;
		        }
		      }
		      resultStr = resultStr + NEWLINE;
		      list.add(resultStr);
		      y++;
		    }
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
		
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics