Search in sources :

Example 1 with DirectByteCharSequence

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

the class CairoTextWriter method onFieldsPartitioned.

public void onFieldsPartitioned(long line, ObjList<DirectByteCharSequence> values, int valuesLength) {
    final int timestampIndex = this.timestampIndex;
    DirectByteCharSequence dbcs = values.getQuick(timestampIndex);
    try {
        final TableWriter.Row w = writer.newRow(timestampAdapter.getTimestamp(dbcs));
        for (int i = 0; i < valuesLength; i++) {
            dbcs = values.getQuick(i);
            if (i == timestampIndex || dbcs.length() == 0) {
                continue;
            }
            if (onField(line, dbcs, w, i))
                return;
        }
        w.append();
        checkMaxAndCommitLag();
    } catch (Exception e) {
        logError(line, timestampIndex, dbcs);
    }
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence)

Example 2 with DirectByteCharSequence

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

the class TextMetadataDetector method stashPossibleHeader.

private void stashPossibleHeader(ObjList<DirectByteCharSequence> values, int hi) {
    for (int i = 0; i < hi; i++) {
        DirectByteCharSequence value = values.getQuick(i);
        utf8Sink.clear();
        if (Chars.utf8Decode(value.getLo(), value.getHi(), utf8Sink)) {
            columnNames.setQuick(i, normalise(utf8Sink));
        } else {
            LOG.info().$("utf8 error [table=").$(tableName).$(", line=0, col=").$(i).$(']').$();
        }
    }
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence)

Example 3 with DirectByteCharSequence

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

the class TextMetadataDetector method onFields.

@Override
public void onFields(long line, ObjList<DirectByteCharSequence> values, int fieldCount) {
    // keep first line in case its a header
    if (line == 0) {
        seedFields(fieldCount);
        stashPossibleHeader(values, fieldCount);
    }
    int count = typeManager.getProbeCount();
    for (int i = 0; i < fieldCount; i++) {
        DirectByteCharSequence cs = values.getQuick(i);
        if (cs.length() == 0) {
            _blanks.increment(i);
        }
        int offset = i * count;
        for (int k = 0; k < count; k++) {
            final TypeAdapter probe = typeManager.getProbe(k);
            if (probe.probe(cs)) {
                _histogram.increment(k + offset);
            }
        }
    }
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) TypeAdapter(io.questdb.cutlass.text.types.TypeAdapter)

Example 4 with DirectByteCharSequence

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

the class HttpMultipartContentParserTest method testWrongStartBoundary.

@Test
public void testWrongStartBoundary() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (HttpMultipartContentParser multipartContentParser = new HttpMultipartContentParser(new HttpHeaderParser(1024, pool))) {
            final String content = "------WebKitFormBoundaryxSLJiij2s--\r\n";
            int len = content.length();
            long p = TestUtils.toMemory(content);
            try {
                String boundary = "\r\n------WebKitFormBoundaryxFKYDBybTLu2rb8P";
                long pBoundary = TestUtils.toMemory(boundary);
                DirectByteCharSequence boundaryCs = new DirectByteCharSequence().of(pBoundary, pBoundary + boundary.length());
                try {
                    multipartContentParser.of(boundaryCs);
                    multipartContentParser.parse(p, p + len, LISTENER);
                    Assert.fail();
                } catch (HttpException e) {
                    TestUtils.assertContains(e.getFlyweightMessage(), "Malformed start boundary");
                } finally {
                    Unsafe.free(pBoundary, boundary.length(), MemoryTag.NATIVE_DEFAULT);
                }
            } finally {
                Unsafe.free(p, len, MemoryTag.NATIVE_DEFAULT);
            }
        }
    });
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) Test(org.junit.Test)

Example 5 with DirectByteCharSequence

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

the class HttpMultipartContentParserTest method testEmpty.

@Test
public void testEmpty() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (HttpMultipartContentParser multipartContentParser = new HttpMultipartContentParser(new HttpHeaderParser(1024, pool))) {
            final String content = "------WebKitFormBoundaryxFKYDBybTLu2rb8P--\r\n";
            final String expected = "";
            int len = content.length();
            long p = TestUtils.toMemory(content);
            try {
                String boundary = "\r\n------WebKitFormBoundaryxFKYDBybTLu2rb8P";
                long pBoundary = TestUtils.toMemory(boundary);
                DirectByteCharSequence boundaryCs = new DirectByteCharSequence().of(pBoundary, pBoundary + boundary.length());
                try {
                    for (int i = 0; i < len; i++) {
                        sink.clear();
                        multipartContentParser.clear();
                        multipartContentParser.of(boundaryCs);
                        multipartContentParser.parse(p, p + i, LISTENER);
                        multipartContentParser.parse(p + i, p + i + 1, LISTENER);
                        if (len > i + 1) {
                            multipartContentParser.parse(p + i + 1, p + len, LISTENER);
                        }
                        TestUtils.assertEquals(expected, sink);
                    }
                } finally {
                    Unsafe.free(pBoundary, boundary.length(), MemoryTag.NATIVE_DEFAULT);
                }
            } finally {
                Unsafe.free(p, len, MemoryTag.NATIVE_DEFAULT);
            }
        }
    });
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) Test(org.junit.Test)

Aggregations

DirectByteCharSequence (io.questdb.std.str.DirectByteCharSequence)18 Test (org.junit.Test)5 Utf8Exception (io.questdb.cutlass.text.Utf8Exception)3 RecordMetadata (io.questdb.cairo.sql.RecordMetadata)1 HttpChunkedResponseSocket (io.questdb.cutlass.http.HttpChunkedResponseSocket)1 HttpRequestHeader (io.questdb.cutlass.http.HttpRequestHeader)1 TypeAdapter (io.questdb.cutlass.text.types.TypeAdapter)1 NumericException (io.questdb.std.NumericException)1