Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

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!