java FileSplit类

Java (4) 2024-07-24 14:23

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说
java FileSplit类,希望能够帮助你!!!。

来源与去向

  • 通过inputformat的getsplits方法产生
  • 传递给inputformat的createRecordReader方法.
/** A section of an input file. Returned by {@link * InputFormat#getSplits(JobContext)} and passed to * {@link InputFormat#createRecordReader(InputSplit,TaskAttemptContext)}. */ * 

属性

看看名字就明白了.

private Path file; private long start; private long length; private String[] hosts; private SplitLocationInfo[] hostInfos; 

以及getset方法
java FileSplit类_https://bianchenghao6.com/blog_Java_第1张

构造方法

有这四个信息就可以创建Split方法了.
这些信息都可以由inputformat提供

public FileSplit() { 
   } /** Constructs a split with host information * * @param file the file name * @param start the position of the first byte in the file to process * @param length the number of bytes in the file to process * @param hosts the list of hosts containing the block, possibly null */ public FileSplit(Path file, long start, long length, String[] hosts) { 
    this.file = file; this.start = start; this.length = length; this.hosts = hosts; } /** Constructs a split with host and cached-blocks information * * @param file the file name * @param start the position of the first byte in the file to process * @param length the number of bytes in the file to process * @param hosts the list of hosts containing the block * @param inMemoryHosts the list of hosts containing the block in memory */ public FileSplit(Path file, long start, long length, String[] hosts, String[] inMemoryHosts) { 
    this(file, start, length, hosts); hostInfos = new SplitLocationInfo[hosts.length]; for (int i = 0; i < hosts.length; i++) { 
    // because N will be tiny, scanning is probably faster than a HashSet boolean inMemory = false; for (String inMemoryHost : inMemoryHosts) { 
    if (inMemoryHost.equals(hosts[i])) { 
    inMemory = true; break; } } hostInfos[i] = new SplitLocationInfo(hosts[i], inMemory); } } 

比较简单的一个类~

今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

发表回复