Search in sources :

Example 6 with DirectByteCharSequence

use of com.questdb.std.str.DirectByteCharSequence 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)

Example 7 with DirectByteCharSequence

use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.

the class Lexer2Test method testUnicode.

@Test
@Ignore
public void testUnicode() throws Exception {
    Lexer2 lex = new Lexer2();
    lex.defineSymbol("+");
    lex.defineSymbol("++");
    lex.defineSymbol("*");
    String s = "'авг'";
    byte[] bb = s.getBytes("UTF8");
    System.out.println(new String(bb));
    long mem = Unsafe.malloc(bb.length);
    for (int i = 0; i < bb.length; i++) {
        Unsafe.getUnsafe().putByte(mem + i, bb[i]);
    }
    DirectByteCharSequence cs = new DirectByteCharSequence();
    cs.of(mem, mem + bb.length);
    lex.setContent(cs);
    StringSink sink = new StringSink();
    while (lex.hasNext()) {
        sink.put(lex.optionTok());
    }
    TestUtils.assertEquals("a+'b'*abc", sink);
}
Also used : DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence) StringSink(com.questdb.std.str.StringSink) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with DirectByteCharSequence

use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.

the class LexerTest method testUnicode.

@Test
@Ignore
public void testUnicode() throws Exception {
    Lexer lex = new Lexer();
    lex.defineSymbol("+");
    lex.defineSymbol("++");
    lex.defineSymbol("*");
    String s = "'авг'";
    byte[] bb = s.getBytes("UTF8");
    System.out.println(new String(bb));
    long mem = Unsafe.malloc(bb.length);
    for (int i = 0; i < bb.length; i++) {
        Unsafe.getUnsafe().putByte(mem + i, bb[i]);
    }
    DirectByteCharSequence cs = new DirectByteCharSequence();
    cs.of(mem, mem + bb.length);
    lex.setContent(cs);
    StringSink sink = new StringSink();
    while (lex.hasNext()) {
        sink.put(lex.optionTok());
    }
    TestUtils.assertEquals("a+'b'*abc", sink);
}
Also used : DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence) StringSink(com.questdb.std.str.StringSink) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with DirectByteCharSequence

use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.

the class RequestHeaderBuffer method write.

public long write(long ptr, int len, boolean _method) throws HeadersTooLargeException, MalformedHeaderException {
    if (_method && needMethod) {
        int l = parseMethod(ptr, len);
        len -= l;
        ptr += l;
    }
    long p = ptr;
    long hi = p + len;
    DirectByteCharSequence v;
    while (p < hi) {
        if (_wptr == this.hi) {
            throw HeadersTooLargeException.INSTANCE;
        }
        char b = (char) Unsafe.getUnsafe().getByte(p++);
        if (b == '\r') {
            continue;
        }
        Unsafe.getUnsafe().putByte(_wptr++, (byte) b);
        switch(b) {
            case ':':
                if (n == null) {
                    n = pool.next().of(_lo, _wptr - 1);
                    _lo = _wptr + 1;
                }
                break;
            case '\n':
                if (n == null) {
                    incomplete = false;
                    parseKnownHeaders();
                    return p;
                }
                v = pool.next().of(_lo, _wptr - 1);
                _lo = _wptr;
                headers.put(n, v);
                n = null;
                break;
            default:
                break;
        }
    }
    return p;
}
Also used : DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence)

Example 10 with DirectByteCharSequence

use of com.questdb.std.str.DirectByteCharSequence in project questdb by bluestreak01.

the class PlainTextLexer method stashField.

private void stashField() {
    if (calcFields) {
        calcField();
    }
    if (fieldIndex >= fields.size()) {
        plainTextParser.onError(lineCount++);
        ignoreEolOnce = true;
        fieldIndex = 0;
        return;
    }
    DirectByteCharSequence seq = fields.getQuick(fieldIndex);
    if (lastQuotePos > -1) {
        seq.of(this.fieldLo, lastQuotePos - 1);
        lastQuotePos = -1;
    } else {
        seq.of(this.fieldLo, this.fieldHi - 1);
    }
    this.fieldLo = this.fieldHi;
}
Also used : DirectByteCharSequence(com.questdb.std.str.DirectByteCharSequence)

Aggregations

DirectByteCharSequence (com.questdb.std.str.DirectByteCharSequence)12 Test (org.junit.Test)4 NumericException (com.questdb.common.NumericException)2 StringSink (com.questdb.std.str.StringSink)2 Ignore (org.junit.Ignore)2 JournalRuntimeException (com.questdb.common.JournalRuntimeException)1 ImportColumnCountException (com.questdb.ex.ImportColumnCountException)1 ImportNameException (com.questdb.ex.ImportNameException)1 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)1 PlainTextLexer (com.questdb.parser.plaintext.PlainTextLexer)1 PlainTextParser (com.questdb.parser.plaintext.PlainTextParser)1 TypeProbe (com.questdb.parser.typeprobe.TypeProbe)1 JournalException (com.questdb.std.ex.JournalException)1 Path (com.questdb.std.str.Path)1 DateLocale (com.questdb.std.time.DateLocale)1 JournalEntryWriter (com.questdb.store.JournalEntryWriter)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1