Search in sources :

Example 21 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class TableReaderTest method testTableCursor.

private void testTableCursor(long inc) throws NumericException {
    Rnd rnd = new Rnd();
    int N = 100;
    long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z") / 1000;
    long blob = allocBlob();
    try {
        testAppend(rnd, configuration, ts, N, inc, blob, 0);
        final LongList rows = new LongList();
        try (TableReader reader = new TableReader(configuration, "all")) {
            Assert.assertEquals(N, reader.size());
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            assertCursor(cursor, ts, inc, blob, N, BATCH1_ASSERTER);
            cursor.toTop();
            while (cursor.hasNext()) {
                rows.add(record.getRowId());
            }
            Rnd exp = new Rnd();
            final Record rec = cursor.getRecordB();
            for (int i = 0, n = rows.size(); i < n; i++) {
                cursor.recordAt(rec, rows.getQuick(i));
                BATCH1_ASSERTER.assertRecord(rec, exp, ts += inc, blob);
            }
        }
    } finally {
        freeBlob(blob);
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record)

Example 22 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class RecordCursorPrinter method print.

public void print(RecordCursor cursor, RecordMetadata metadata, boolean header, Log sink) {
    LogRecordSinkAdapter logRecSink = new LogRecordSinkAdapter();
    if (header) {
        LogRecord line = sink.xDebugW();
        printHeaderNoNl(metadata, logRecSink.of(line));
        line.$();
    }
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        LogRecord line = sink.xDebugW();
        printRecordNoNl(record, metadata, logRecSink.of(line));
        line.$();
    }
}
Also used : LogRecord(io.questdb.log.LogRecord) Record(io.questdb.cairo.sql.Record) LogRecord(io.questdb.log.LogRecord)

Example 23 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class RecordCursorPrinter method printFullColumn.

public void printFullColumn(RecordCursor cursor, RecordMetadata metadata, int i, boolean header, CharSink sink) {
    if (header) {
        printHeader(metadata, sink);
    }
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        printColumn(record, metadata, i, sink);
        sink.put('\n');
    }
}
Also used : Record(io.questdb.cairo.sql.Record) LogRecord(io.questdb.log.LogRecord)

Example 24 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class TruncateTest method testTruncateOpenReader.

@Test
public void testTruncateOpenReader() throws Exception {
    assertMemoryLeak(() -> {
        createX(1_000_000);
        assertQuery("count\n" + "1000000\n", "select count() from x", null, false, true);
        try (RecordCursorFactory factory = compiler.compile("select * from x", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                final Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    record.getInt(0);
                    record.getSym(1);
                    record.getDouble(2);
                }
            }
        }
        compiler.compile("truncate table 'x'", sqlExecutionContext);
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 25 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class TableReaderReloadBenchmark method setup.

@Setup(Level.Iteration)
public void setup() throws NumericException {
    writer = new TableWriter(configuration, "test");
    writer.truncate();
    // create 10 partitions
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-01T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-02T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-03T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-04T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-05T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-06T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-07T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-08T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-09T00:00:00.000000Z"));
    appendRow(TimestampFormatUtils.parseTimestamp("2012-03-10T00:00:00.000000Z"));
    writer.commit();
    reader = new TableReader(configuration, "test");
    // ensure reader opens all partitions and maps all data
    RecordCursor cursor = reader.getCursor();
    Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        sum += record.getTimestamp(0);
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record)

Aggregations

Record (io.questdb.cairo.sql.Record)171 Test (org.junit.Test)130 RecordCursor (io.questdb.cairo.sql.RecordCursor)121 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)79 TableWriter (io.questdb.cairo.TableWriter)70 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)66 Rnd (io.questdb.std.Rnd)32 Function (io.questdb.cairo.sql.Function)28 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)16 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)15 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)15 IntList (io.questdb.std.IntList)15 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)14 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)14 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)14 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)14 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)14 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)14 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)13 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)13