I have to write a map reduce batch (using the org.apache.hadoop.mapreduce.*
API) to process text files with the following properties:
- ISO-8859-1 encoding.
- CSV like
- Separator is
0xef
I use a TextInputFormat
since I want to perform the field splitting by myself. However it seems that TextInputFormat
is only able to handle UTF-8 encoded files.
According to MAPREDUCE-232 there is a pending patch since 2008 but I have not been able to found a workaround. What are my options ? Converting the files in UTF-8 before-hand is not an option.
Edit: While reading the Hadoop source code I figured out a possible workaround. LineReader
& friends only deal with bytes. They never convert bytes into String, they only match hard coded end of line separators and fill a byte buffer. Since ISO_8859_1 and UTF-8 share the same byte sequence for \n
, it is thus possible to use:
public class MyMapper extends Mapper<IntWritable, Text, Text, Text> {
public void map(IntWritable key, Text value, Context context)
throws IOException, InterruptedException {
String data = new String(value.getBytes(),
0, value.getLength(),
Charsets.ISO_8859_1)
// [...]
}
}
Is this solution acceptable ?
value
? – jtahlborn Apr 8 '13 at 17:38str.append(buffer, startPosn, appendLength);
(where str is of type Text) to append to the buffer but if you see the javadoc for Text.append(), it mentions utf8 as the buffer encoding, though it's really of type byte[]. Do you think utf8 shouldn't be mentioned there? I'm getting little confused now. – SSaikia_JtheRocker Apr 19 '14 at 18:15