Skip to content

Commit

Permalink
Fix up minor leftover bits in JsonLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
dvryaboy committed Mar 7, 2011
1 parent 9d9c229 commit ecf8356
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/java/com/twitter/elephantbird/pig/load/JsonLoader.java
Expand Up @@ -23,15 +23,15 @@
*/
public class JsonLoader extends PigStorage {

private static final Logger LOG = LoggerFactory.getLogger(LzoJsonLoader.class);
private static final Logger LOG = LoggerFactory.getLogger(JsonLoader.class);

private static final TupleFactory tupleFactory_ = TupleFactory.getInstance();
private static final Charset UTF8 = Charset.forName("UTF-8");
private static final byte RECORD_DELIMITER = (byte)'\n';

private final JSONParser jsonParser_ = new JSONParser();

protected enum LzoJsonLoaderCounters { LinesRead, LinesJsonDecoded, LinesParseError, LinesParseErrorBadNumber }
protected enum JsonLoaderCounters { LinesRead, LinesJsonDecoded, LinesParseError, LinesParseErrorBadNumber }

// Making accessing Hadoop counters from Pig slightly more convenient.
private final PigCounterHelper counterHelper_ = new PigCounterHelper();
Expand All @@ -47,15 +47,16 @@ public Tuple getNext() throws IOException {
return null;
}
Text value = new Text();
boolean notDone = in.next(value);
if (!notDone) {

if (!in.next(value)) {
return null;
}
incrCounter(LzoJsonLoaderCounters.LinesRead, 1L);

incrCounter(JsonLoaderCounters.LinesRead, 1L);

Tuple t = parseStringToTuple(value.toString());
if (t != null) {
incrCounter(LzoJsonLoaderCounters.LinesJsonDecoded, 1L);
incrCounter(JsonLoaderCounters.LinesJsonDecoded, 1L);
}
return t;
}
Expand Down Expand Up @@ -87,15 +88,15 @@ protected Tuple parseStringToTuple(String line) {
return tupleFactory_.newTuple(values);
} catch (ParseException e) {
LOG.warn("Could not json-decode string: " + line, e);
incrCounter(LzoJsonLoaderCounters.LinesParseError, 1L);
incrCounter(JsonLoaderCounters.LinesParseError, 1L);
return null;
} catch (NumberFormatException e) {
LOG.warn("Very big number exceeds the scale of long: " + line, e);
incrCounter(LzoJsonLoaderCounters.LinesParseErrorBadNumber, 1L);
incrCounter(JsonLoaderCounters.LinesParseErrorBadNumber, 1L);
return null;
} catch (ClassCastException e) {
LOG.warn("Could not convert to Json Object: " + line, e);
incrCounter(LzoJsonLoaderCounters.LinesParseError, 1L);
incrCounter(JsonLoaderCounters.LinesParseError, 1L);
return null;
}
}
Expand Down
Expand Up @@ -76,7 +76,6 @@ public void testStableHashcodeAcrossJVMs() throws IOException {
otherJvm.setNewenvironment(true);
otherJvm.setFork(true);
otherJvm.setClassname(OtherJvmClass.class.getName());
System.getenv();
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
Environment.Variable var = new Environment.Variable();
var.setKey(entry.getKey());
Expand Down

0 comments on commit ecf8356

Please sign in to comment.