CombinationsInputFormat extends InputFormat<NullWritable, NullWritable> { static Path createSplitOutputPath(Path outputPath, String formatName, String... values) { Object[] objs = new Object[values.length]; for (int i = 0; i < objs.length; i++) { String value = values[i]; String[] splits = value.split(","); value = splits[0].trim(); try { objs[i] = Long.parseLong(value); } catch (NumberFormatException nfel) { try { objs[i] = Double.parseDouble(value); } catch (NumberFormatException nfed) { if (value.startsWith("'") && value.endsWith("'") || value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } objs[i] = value; } } } try { String name = String.format(Locale.ENGLISH, formatName, objs); return new Path(outputPath, name); } catch (IllegalFormatConversionException e) { System.out.println(formatName); for (int i = 0; i < objs.length; i++) { Object obj = objs[i]; System.out.printf("obj[%d] = %s (%s)%n", i, obj, obj.getClass()); } throw e; } }  @Override List<InputSplit> getSplits(JobContext context); @Override RecordReader<NullWritable, NullWritable> createRecordReader(InputSplit split,
                TaskAttemptContext context);  }
@Test public void testCreateSplitOutputPath() throws Exception { assertEquals("dir/a_b", create("dir", "a_%s", "b")); assertEquals("dir/a_3", create("dir", "a_%d", "3")); assertEquals("dir/a_4.50", create("dir", "a_%04.2f", "4.5")); assertEquals("dir/a_a", create("dir", "a_%s", "a, b")); assertEquals("dir/a_a", create("dir", "a_%s", "'a', b")); String modtranFormat = "AVHRR_AC_aertype%s_surfref%04.2f_aerdepth%05.3f_wv%04d_o3c0.33176_co2m380_sza%02d_vza%02d_azi%03d_alt%03.1f_band%01d.zip"; String[] modtranValues = new String[]{"'___rural', 'foo'", "0.15", "0.7", "500", "0", "0", "30", "0.0", "1"}; String modtranOutput = create("modtran", modtranFormat, modtranValues); String expected = "modtran/AVHRR_AC_aertype___rural_surfref0.15_aerdepth0.700_wv0500_o3c0.33176_co2m380_sza00_vza00_azi030_alt0.0_band1.zip"; assertEquals(expected, modtranOutput); }