Created
June 14, 2012 13:49
-
-
Save Stivo/2930414 to your computer and use it in GitHub Desktop.
Performance fixes for crunch's join
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* {@inheritDoc} | |
*/ | |
@SuppressWarnings("unchecked") | |
// No static typeinfo on Tuples | |
public void readFields(DataInput in) throws IOException { | |
int card = WritableUtils.readVInt(in); | |
if (values == null || values.length != card) { | |
values = new Writable[card]; | |
} | |
written = WritableUtils.readVLong(in); | |
Class<? extends Writable>[] cls = new Class[card]; | |
try { | |
for (int i = 0; i < card; ++i) { | |
if (has(i)) { | |
cls[i] = lookupClass(Text.readString(in)); | |
} | |
} | |
for (int i = 0; i < card; ++i) { | |
if (has(i)) { | |
if (!cls[i].isInstance(values[i])) { | |
values[i] = cls[i].newInstance(); | |
} | |
values[i].readFields(in); | |
} else { | |
values[i] = null; | |
} | |
} | |
} catch (ClassNotFoundException e) { | |
throw (IOException) new IOException("Failed tuple init").initCause(e); | |
} catch (IllegalAccessException e) { | |
throw (IOException) new IOException("Failed tuple init").initCause(e); | |
} catch (InstantiationException e) { | |
throw (IOException) new IOException("Failed tuple init").initCause(e); | |
} | |
} | |
private Map<String, Class<? extends Writable>> writableClassCache = new HashMap<String, Class<? extends Writable>>(); | |
private Class<? extends Writable> lookupClass(String readString) throws ClassNotFoundException { | |
if (!writableClassCache.containsKey(readString)) { | |
writableClassCache.put(readString, | |
Class.forName(readString).asSubclass(Writable.class)); | |
} | |
return writableClassCache.get(readString); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment