Skip to content

Commit

Permalink
fix ClassCastException on LazyString in serialize (issue #25)
Browse files Browse the repository at this point in the history
  • Loading branch information
randallwhitman committed Jun 8, 2013
1 parent f3ee894 commit 23121ff
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions hive/src/com/esri/hadoop/hive/serde/JsonSerde.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.hadoop.hive.serde2.SerDe;
import org.apache.hadoop.hive.serde2.SerDeException;
import org.apache.hadoop.hive.serde2.SerDeStats;
import org.apache.hadoop.hive.serde2.lazy.LazyPrimitive;
import org.apache.hadoop.hive.serde2.lazybinary.LazyBinaryStruct;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory;
Expand Down Expand Up @@ -234,10 +235,17 @@ public Writable serialize(Object obj, ObjectInspector oi)
// first write attributes
jsonGen.writeObjectFieldStart("attributes");

for (int i=0;i<fieldWritables.size();i++){
if (i == geometryColumn) continue; // skip geometry, it comes later

Writable writable = (Writable)fieldWritables.get(i);
for (int i = 0; i < fieldWritables.size(); i++) {
if (i == geometryColumn)
continue; // skip geometry, it comes later

Writable writable;
Object tmpObj = fieldWritables.get(i);
if (tmpObj instanceof LazyPrimitive) { // usually Text, but have seen LazyString
writable = ((LazyPrimitive)(tmpObj)).getWritableObject();
} else {
writable = (Writable)tmpObj;
}

jsonGen.writeObjectField(columnNames.get(i), writable.toString());
}
Expand Down

0 comments on commit 23121ff

Please sign in to comment.