Solved Writing a custom CSV importer
-
I want to write a custom CSV importer by extending the AbstractCSVDataSource and overriding the appropriate method:
@Override public void importRow(String[] row, int rowNum)
My issue is that I don't know what
String[] row
will look like. There's obviously a parser that provides this but I'm not sure where to find it or whether it changes.Can anyone point me in the right direction? For now I'll just hack in a
System.out.println()
and go from what I see there.Thanks,
C -
Hi cbyrne,
Unfortunately the Data File Data Source is in one of our private repositories, so I cannot link you to the source code directly.
The parser being used is a
au.com.bytecode.opencsv.CSVReader.CSVReader
which is getting its separator, quote character, and escape character from the AbstractCSVDataSource class, unless you override the methods providing these in your implementing class, i.e.@Override public char getSeparatorCharacter() { return ','; //split on commas } @Override public char getQuoteCharacter() { return '"'; //unless the commas are in quote pairs } @Override public char getEscapeCharacter() { return '\\'; }
It will pass each line that it reads as it reads and parses it to the import row function.
-
Perfect, thanks for your help @phildunlap . Much appreciated!