Java Code Examples for org.apache.hadoop.io.WritableComparable#toString()
The following examples show how to use
org.apache.hadoop.io.WritableComparable#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateGroup2.java From MapReduce-Demo with MIT License | 6 votes |
@SuppressWarnings("rawtypes") @Override public int compare(WritableComparable a, WritableComparable b) { String d1 = a.toString(); String d2 = b.toString(); if (d1.startsWith("2015")) d1 = "2015"; else if (d1.startsWith("2016")) d1 = "2016"; else d1 = "2017"; if (d2.startsWith("2015")) d2 = "2015"; else if (d2.startsWith("2016")) d2 = "2016"; else d2 = "2017"; return d1.compareTo(d2); //将原本KEY(年月日)的比较变成年份的比较 }
Example 2
Source File: TestFileSystem.java From RDFS with Apache License 2.0 | 4 votes |
public void map(WritableComparable key, LongWritable value, OutputCollector<K, LongWritable> collector, Reporter reporter) throws IOException { String name = key.toString(); long size = value.get(); long seed = Long.parseLong(name); if (size == 0) return; reporter.setStatus("opening " + name); FSDataInputStream in = fs.open(new Path(DATA_DIR, name)); try { for (int i = 0; i < SEEKS_PER_FILE; i++) { // generate a random position long position = Math.abs(random.nextLong()) % size; // seek file to that position reporter.setStatus("seeking " + name); in.seek(position); byte b = in.readByte(); // check that byte matches byte checkByte = 0; // advance random state to that position random.setSeed(seed); for (int p = 0; p <= position; p+= check.length) { reporter.setStatus("generating data for " + name); if (fastCheck) { checkByte = (byte)random.nextInt(Byte.MAX_VALUE); } else { random.nextBytes(check); checkByte = check[(int)(position % check.length)]; } } assertEquals(b, checkByte); } } finally { in.close(); } }
Example 3
Source File: TestFileSystem.java From hadoop-gpu with Apache License 2.0 | 4 votes |
public void map(WritableComparable key, LongWritable value, OutputCollector<K, LongWritable> collector, Reporter reporter) throws IOException { String name = key.toString(); long size = value.get(); long seed = Long.parseLong(name); if (size == 0) return; reporter.setStatus("opening " + name); FSDataInputStream in = fs.open(new Path(DATA_DIR, name)); try { for (int i = 0; i < SEEKS_PER_FILE; i++) { // generate a random position long position = Math.abs(random.nextLong()) % size; // seek file to that position reporter.setStatus("seeking " + name); in.seek(position); byte b = in.readByte(); // check that byte matches byte checkByte = 0; // advance random state to that position random.setSeed(seed); for (int p = 0; p <= position; p+= check.length) { reporter.setStatus("generating data for " + name); if (fastCheck) { checkByte = (byte)random.nextInt(Byte.MAX_VALUE); } else { random.nextBytes(check); checkByte = check[(int)(position % check.length)]; } } assertEquals(b, checkByte); } } finally { in.close(); } }