SeasonalTilesInputFormat extends PatternBasedInputFormat { @Override protected void createSplits(ProductInventory productInventory, RemoteIterator<LocatedFileStatus> fileStatusIt, List<InputSplit> splits, Configuration conf, int requestSizeLimit, boolean withDirs) throws IOException { while (fileStatusIt.hasNext()) { LocatedFileStatus locatedFileStatus = fileStatusIt.next(); String fileName = locatedFileStatus.getPath().getName(); if (tileNameIn(tileNameOf(fileName), splits)) { continue; } LOG.info("tile " + fileName + " represents " + tileNameOf(fileName)); BlockLocation[] blocks = locatedFileStatus.getPath().getFileSystem(conf).getFileBlockLocations(locatedFileStatus.getPath(), 0, locatedFileStatus.getLen()); ((LazilyLocatedFileStatus) locatedFileStatus).locate(blocks); InputSplit split = createSplit(productInventory, conf, locatedFileStatus, withDirs); if (split != null) { splits.add(split); if (requestSizeLimit > 0 && splits.size() == requestSizeLimit) { break; } } } }    }
@Ignore @Test public void testCreateSplits() throws Exception { BlockLocation[] blockLocations = {new BlockLocation(new String[]{"name"}, new String[]{"host"}, 0, 99)}; SeasonalTilesInputFormat inputFormat = new SeasonalTilesInputFormat(); FileStatus[] files = new FileStatus[] { new FileStatus(99, false, 1, 99, 0, new Path("/ab/cd/ESACCI-LC-L3-SR-MERIS-300m-P7D-h36v08-20090108-v2.0.nc")), new FileStatus(99, false, 1, 99, 0, new Path("/ab/cd/ESACCI-LC-L3-SR-MERIS-300m-P7D-h36v08-20090115-v2.0.nc")), new FileStatus(99, false, 1, 99, 0, new Path("/ab/cd/ESACCI-LC-L3-SR-MERIS-300m-P7D-h36v08-20110115-v2.0.nc")), new FileStatus(99, false, 1, 99, 0, new Path("/ab/cd/ESACCI-LC-L3-SR-MERIS-300m-P7D-h36v09-20090115-v2.0.nc")), }; List<InputSplit> splits = new ArrayList<>(); Iterator<FileStatus> iterator = Arrays.asList(files).iterator(); RemoteIterator<LocatedFileStatus> remoteIter = new RemoteIterator<LocatedFileStatus>() { @Override public boolean hasNext() throws IOException { return iterator.hasNext(); } @Override public LocatedFileStatus next() throws IOException { return new LocatedFileStatus(iterator.next(), blockLocations); } }; inputFormat.createSplits(null, remoteIter, splits, new Configuration(), 0, false); assertEquals(2, splits.size()); }