Fix writables.tableOf to handle nested tables
Project: http://git-wip-us.apache.org/repos/asf/incubator-crunch/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-crunch/commit/4b732490 Tree: http://git-wip-us.apache.org/repos/asf/incubator-crunch/tree/4b732490 Diff: http://git-wip-us.apache.org/repos/asf/incubator-crunch/diff/4b732490 Branch: refs/heads/master Commit: 4b7324908055cc6e041199014b81081c3347d030 Parents: eb3de88 Author: Josh Wills <[email protected]> Authored: Mon Jun 18 16:48:18 2012 -0700 Committer: Josh Wills <[email protected]> Committed: Mon Jun 18 16:48:18 2012 -0700 ---------------------------------------------------------------------- .../crunch/types/writable/WritableTypeFamily.java | 5 +-- .../cloudera/crunch/types/writable/Writables.java | 23 ++++++-------- 2 files changed, 11 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/4b732490/src/main/java/com/cloudera/crunch/types/writable/WritableTypeFamily.java ---------------------------------------------------------------------- diff --git a/src/main/java/com/cloudera/crunch/types/writable/WritableTypeFamily.java b/src/main/java/com/cloudera/crunch/types/writable/WritableTypeFamily.java index 69f7399..8a51e9a 100644 --- a/src/main/java/com/cloudera/crunch/types/writable/WritableTypeFamily.java +++ b/src/main/java/com/cloudera/crunch/types/writable/WritableTypeFamily.java @@ -94,10 +94,7 @@ public class WritableTypeFamily implements PTypeFamily { } public <K, V> PTableType<K, V> tableOf(PType<K> key, PType<V> value) { - if (!(key instanceof WritableType) || !(value instanceof WritableType)) { - throw new IllegalArgumentException("Cannot use non-WritableType in Writables.tableOf"); - } - return Writables.tableOf((WritableType) key, (WritableType) value); + return Writables.tableOf(key, value); } public <V1, V2> PType<Pair<V1, V2>> pairs(PType<V1> p1, PType<V2> p2) { http://git-wip-us.apache.org/repos/asf/incubator-crunch/blob/4b732490/src/main/java/com/cloudera/crunch/types/writable/Writables.java ---------------------------------------------------------------------- diff --git a/src/main/java/com/cloudera/crunch/types/writable/Writables.java b/src/main/java/com/cloudera/crunch/types/writable/Writables.java index 4c59133..060f411 100644 --- a/src/main/java/com/cloudera/crunch/types/writable/Writables.java +++ b/src/main/java/com/cloudera/crunch/types/writable/Writables.java @@ -257,20 +257,17 @@ public class Writables { public static <K, V> WritableTableType<K, V> tableOf( PType<K> key, PType<V> value) { - if (!(key instanceof WritableType)) { - if (key instanceof WritableTableType) { - WritableTableType wtt = (WritableTableType) key; - key = pairs(wtt.getKeyType(), wtt.getValueType()); - } else { - throw new IllegalArgumentException("Key type must be of class WritableType"); - } + if (key instanceof WritableTableType) { + WritableTableType wtt = (WritableTableType) key; + key = pairs(wtt.getKeyType(), wtt.getValueType()); + } else if (!(key instanceof WritableType)) { + throw new IllegalArgumentException("Key type must be of class WritableType"); + } + if (value instanceof WritableTableType) { + WritableTableType wtt = (WritableTableType) value; + value = pairs(wtt.getKeyType(), wtt.getValueType()); } else if (!(value instanceof WritableType)) { - if (value instanceof WritableTableType) { - WritableTableType wtt = (WritableTableType) value; - value = pairs(wtt.getKeyType(), wtt.getValueType()); - } else { - throw new IllegalArgumentException("Value type must be of class WritableType"); - } + throw new IllegalArgumentException("Value type must be of class WritableType"); } return new WritableTableType((WritableType) key, (WritableType) value); }
