Search in sources :

Example 1 with PlainTextParser

use of com.questdb.parser.plaintext.PlainTextParser in project questdb by bluestreak01.

the class CsvTest method testHeaders.

@Test
public void testHeaders() throws Exception {
    final List<String> names = new ArrayList<>();
    final List<String> expected = new ArrayList<String>() {

        {
            add("type");
            add("value");
            add("active");
            add("desc");
            add("grp");
        }
    };
    ImportManager.parse(new File(this.getClass().getResource("/csv/test-headers.csv").getFile()), new PlainTextLexer(env).of(','), 1024 * 1024, true, new PlainTextParser() {

        @Override
        public void onError(int line) {
        }

        @Override
        public void onFieldCount(int count) {
        }

        @Override
        public void onFields(int line, ObjList<DirectByteCharSequence> values, int hi) {
        }

        @Override
        public void onHeader(ObjList<DirectByteCharSequence> values, int hi) {
            for (int i = 0; i < hi; i++) {
                names.add(values.getQuick(i).toString());
            }
        }

        @Override
        public void onLineCount(int count) {
        }
    });
    TestUtils.assertEquals(expected.iterator(), names.iterator());
}
Also used : PlainTextParser(com.questdb.parser.plaintext.PlainTextParser) DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence) ArrayList(java.util.ArrayList) PlainTextLexer(com.questdb.parser.plaintext.PlainTextLexer) File(java.io.File) Test(org.junit.Test)

Aggregations

PlainTextLexer (com.questdb.parser.plaintext.PlainTextLexer)1 PlainTextParser (com.questdb.parser.plaintext.PlainTextParser)1 DirectByteCharSequence (com.questdb.std.str.DirectByteCharSequence)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1