forked from twitter/elephant-bird
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request twitter#102 from miguno/issue65
Issue 65: LzoJsonRecordReader and JsonLoader may fail with NullPointerException
- Loading branch information
Showing
4 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
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
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
31 changes: 31 additions & 0 deletions
31
src/test/com/twitter/elephantbird/mapreduce/input/TestLzoJsonRecordReader.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.twitter.elephantbird.mapreduce.input; | ||
|
||
import junit.framework.TestCase; | ||
import org.apache.hadoop.io.MapWritable; | ||
import org.apache.hadoop.io.Text; | ||
import org.json.simple.parser.JSONParser; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test the LzoJsonRecordReader, make sure it reads the data properly. | ||
*/ | ||
public class TestLzoJsonRecordReader extends TestCase { | ||
|
||
/** | ||
* {@link LzoJsonRecordReader#decodeLineToJson(JSONParser, Text, MapWritable)} | ||
* must not choke on lines containing the word "null" (i.e. not the null | ||
* value but the string "null"). | ||
* | ||
* This can happen when the original input line to JSONParser contains "null" | ||
* as a string. In this case {@link JSONParser#parse(java.io.Reader)} will | ||
* return a null reference. | ||
* | ||
*/ | ||
@Test | ||
public void testNullString() { | ||
Text line = new Text("null"); | ||
boolean result = LzoJsonRecordReader.decodeLineToJson(new JSONParser(), line, new MapWritable()); | ||
assertEquals("Parsing line with contents 'null'", false, result); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
src/test/com/twitter/elephantbird/pig/load/TestJsonLoader.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.twitter.elephantbird.pig.load; | ||
|
||
import junit.framework.TestCase; | ||
import org.apache.pig.data.Tuple; | ||
import org.json.simple.parser.JSONParser; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test the JsonLoader, make sure it reads the data properly. | ||
*/ | ||
|
||
public class TestJsonLoader extends TestCase { | ||
|
||
/** | ||
* {@link JsonLoader#parseStringToTuple(String)} must not choke on lines | ||
* containing the word "null" (i.e. not the null value but the string | ||
* "null"). | ||
* | ||
* This can happen when the original input line to JSONParser contains "null" | ||
* as a string. In this case {@link JSONParser#parse(java.io.Reader)} will | ||
* return a null reference. | ||
* | ||
*/ | ||
@Test | ||
public void testNullString() { | ||
String nullString = "null"; | ||
JsonLoader jsonLoader = new JsonLoader(); | ||
Tuple result = jsonLoader.parseStringToTuple(nullString); | ||
assertEquals("Parsing line with contents 'null'", null, result); | ||
} | ||
|
||
} |