私は以前に Map Reduce で行った宿題で、Pig Latin を理解しようとしています。PS: 私の入力は 10 行のシンプルな csv ファイルです。
csv形式をarffに変換しようとしています。
私のUDF:
public class CSV2ARFF extends EvalFunc<String> {
private String arffDataString;
private String arffHeaderString;
public String exec(Tuple input) throws IOException {
if (input == null || input.size() == 0)
return null;
try{
System.out.println(">>> " + input.get(0).toString());
// csv to instances
ByteArrayInputStream inputStream = new ByteArrayInputStream(input.get(0).toString().getBytes("UTF-8"));
CSVLoader loader = new CSVLoader();
loader.setSource(inputStream);
Instances data = loader.getDataSet(); //**Line #30**
//convert into arff
ArffSaver arff = new ArffSaver();
arff.setInstances(data);
this.arffDataString = arff.getInstances().toString();
Instances arffdata = arff.getInstances();
// header
Instances header = new Instances(arffdata, 0);
this.arffHeaderString = header.toString();
this.arffDataString = this.arffDataString.substring(this.arffHeaderString.length());
return arffDataString;
}catch(Exception e){
System.err.println("CSV2ARFF: failed to proces input; error - " + e.getMessage());
return null;
}
}
}
私のscript.pig
REGISTER ./csv2arff.jar;
REGISTER ./weka.jar;
csvraw = LOAD 'sample' USING PigStorage('\n') as (c);
arffraws = FOREACH csvraw GENERATE pighw2java.CSV2ARFF(c);
--output
STORE arffraws INTO 'output' using PigStorage();
エラー
java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.nio.CharBuffer.wrap(CharBuffer.java:369)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:310)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.read(BufferedReader.java:175)
at java.io.StreamTokenizer.read(StreamTokenizer.java:500)
at java.io.StreamTokenizer.nextToken(StreamTokenizer.java:544)
at weka.core.converters.ConverterUtils.getToken(ConverterUtils.java:888)
at weka.core.converters.CSVLoader.readHeader(CSVLoader.java:937)
at weka.core.converters.CSVLoader.readStructure(CSVLoader.java:578)
at weka.core.converters.CSVLoader.getStructure(CSVLoader.java:563)
at weka.core.converters.CSVLoader.getDataSet(CSVLoader.java:596)
at pighw2java.CSV2ARFF.exec(CSV2ARFF.java:30)
at pighw2java.CSV2ARFF.exec(CSV2ARFF.java:1)