Search in sources :

Example 61 with RecordCursor

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

the class VirtualRecordCursorFactory method getCursor.

@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) throws SqlException {
    RecordCursor cursor = baseFactory.getCursor(executionContext);
    Function.init(functions, cursor, executionContext);
    this.cursor.of(cursor);
    return this.cursor;
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor)

Example 62 with RecordCursor

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

the class ExceptRecordCursorFactory method getCursor.

@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) throws SqlException {
    RecordCursor masterCursor = null;
    RecordCursor slaveCursor = null;
    try {
        masterCursor = masterFactory.getCursor(executionContext);
        slaveCursor = slaveFactory.getCursor(executionContext);
        cursor.of(masterCursor, slaveCursor, executionContext);
        return cursor;
    } catch (Throwable ex) {
        Misc.free(masterCursor);
        Misc.free(slaveCursor);
        throw ex;
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor)

Example 63 with RecordCursor

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

the class IntersectRecordCursorFactory method getCursor.

@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) throws SqlException {
    RecordCursor masterCursor = null;
    RecordCursor slaveCursor = null;
    try {
        masterCursor = masterFactory.getCursor(executionContext);
        slaveCursor = slaveFactory.getCursor(executionContext);
        cursor.of(masterCursor, slaveCursor, executionContext);
        return cursor;
    } catch (Throwable ex) {
        Misc.free(masterCursor);
        Misc.free(slaveCursor);
        throw ex;
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor)

Example 64 with RecordCursor

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

the class RecordValueSinkFactoryTest method testSubset.

@Test
public void testSubset() {
    SingleColumnType keyTypes = new SingleColumnType(ColumnType.INT);
    try (TableModel model = new TableModel(configuration, "all", PartitionBy.NONE).col("int", ColumnType.INT).col("short", ColumnType.SHORT).col("byte", ColumnType.BYTE).col("double", ColumnType.DOUBLE).col("float", ColumnType.FLOAT).col("long", ColumnType.LONG).col("sym", ColumnType.SYMBOL).symbolCapacity(64).col("bool", ColumnType.BOOLEAN).col("date", ColumnType.DATE).col("ts", ColumnType.TIMESTAMP)) {
        CairoTestUtils.create(model);
    }
    final int N = 1024;
    final Rnd rnd = new Rnd();
    try (TableWriter writer = new TableWriter(configuration, "all")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow();
            row.putInt(0, rnd.nextInt());
            row.putShort(1, rnd.nextShort());
            row.putByte(2, rnd.nextByte());
            row.putDouble(3, rnd.nextDouble());
            row.putFloat(4, rnd.nextFloat());
            row.putLong(5, rnd.nextLong());
            row.putSym(6, rnd.nextChars(10));
            row.putBool(7, rnd.nextBoolean());
            row.putDate(8, rnd.nextLong());
            row.putTimestamp(9, rnd.nextLong());
            row.append();
        }
        writer.commit();
    }
    try (TableReader reader = new TableReader(configuration, "all")) {
        ArrayColumnTypes valueTypes = new ArrayColumnTypes();
        valueTypes.add(ColumnType.BOOLEAN);
        valueTypes.add(ColumnType.TIMESTAMP);
        valueTypes.add(ColumnType.INT);
        try (final Map map = new FastMap(Numbers.SIZE_1MB, keyTypes, valueTypes, N, 0.5, 100)) {
            ListColumnFilter columnFilter = new ListColumnFilter();
            columnFilter.add(8);
            columnFilter.add(10);
            columnFilter.add(7);
            RecordValueSink sink = RecordValueSinkFactory.getInstance(new BytecodeAssembler(), reader.getMetadata(), columnFilter);
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            int index = 0;
            while (cursor.hasNext()) {
                MapKey key = map.withKey();
                key.putInt(index++);
                MapValue value = key.createValue();
                sink.copy(record, value);
            }
            Assert.assertEquals(N, index);
            rnd.reset();
            StaticSymbolTable symbolTable = reader.getSymbolMapReader(6);
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(i);
                MapValue value = key.findValue();
                Assert.assertNotNull(value);
                // 0
                rnd.nextInt();
                // 1
                rnd.nextShort();
                // 2
                rnd.nextByte();
                // 3
                rnd.nextDouble();
                // 4
                rnd.nextFloat();
                // 5
                rnd.nextLong();
                // 6
                Assert.assertEquals(symbolTable.keyOf(rnd.nextChars(10)), value.getInt(2));
                // 7
                Assert.assertEquals(rnd.nextBoolean(), value.getBool(0));
                // 8
                rnd.nextLong();
                // 9
                Assert.assertEquals(rnd.nextLong(), value.getTimestamp(1));
            }
        }
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) BytecodeAssembler(io.questdb.std.BytecodeAssembler) StaticSymbolTable(io.questdb.cairo.sql.StaticSymbolTable) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 65 with RecordCursor

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

the class SampleByTest method testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable.

@Test
public void testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 300000000) k" + " from" + " long_sequence(100)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
        RecordCursorFactory factory = compiler.compile("select k, count() from x sample by 90m align to calendar time zone $1 with offset $2", sqlExecutionContext).getRecordCursorFactory();
        String expectedMoscow = "k\tcount\n" + "1970-01-02T22:45:00.000000Z\t3\n" + "1970-01-03T00:15:00.000000Z\t18\n" + "1970-01-03T01:45:00.000000Z\t18\n" + "1970-01-03T03:15:00.000000Z\t18\n" + "1970-01-03T04:45:00.000000Z\t18\n" + "1970-01-03T06:15:00.000000Z\t18\n" + "1970-01-03T07:45:00.000000Z\t7\n";
        String expectedPrague = "k\tcount\n" + "1970-01-02T23:10:00.000000Z\t8\n" + "1970-01-03T00:40:00.000000Z\t18\n" + "1970-01-03T02:10:00.000000Z\t18\n" + "1970-01-03T03:40:00.000000Z\t18\n" + "1970-01-03T05:10:00.000000Z\t18\n" + "1970-01-03T06:40:00.000000Z\t18\n" + "1970-01-03T08:10:00.000000Z\t2\n";
        sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Moscow");
        sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            assertCursor(expectedMoscow, cursor, factory.getMetadata(), true);
        }
        // invalid timezone
        sqlExecutionContext.getBindVariableService().setStr(0, "Oopsie");
        sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
        try {
            factory.getCursor(sqlExecutionContext);
            Assert.fail();
        } catch (SqlException e) {
            Assert.assertEquals(67, e.getPosition());
            TestUtils.assertContains(e.getFlyweightMessage(), "invalid timezone: Oopsie");
        }
        sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
        sqlExecutionContext.getBindVariableService().setStr(1, "uggs");
        try {
            factory.getCursor(sqlExecutionContext);
            Assert.fail();
        } catch (SqlException e) {
            Assert.assertEquals(82, e.getPosition());
            TestUtils.assertContains(e.getFlyweightMessage(), "invalid offset: uggs");
        }
        sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
        sqlExecutionContext.getBindVariableService().setStr(1, "00:10");
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            assertCursor(expectedPrague, cursor, factory.getMetadata(), true);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) SqlException(io.questdb.griffin.SqlException) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Aggregations

RecordCursor (io.questdb.cairo.sql.RecordCursor)174 Test (org.junit.Test)137 Record (io.questdb.cairo.sql.Record)123 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)108 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)87 TableWriter (io.questdb.cairo.TableWriter)71 Rnd (io.questdb.std.Rnd)29 LPSZ (io.questdb.std.str.LPSZ)10 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)7 SqlCompiler (io.questdb.griffin.SqlCompiler)6 DateFormat (io.questdb.std.datetime.DateFormat)6 Path (io.questdb.std.str.Path)6 StringSink (io.questdb.std.str.StringSink)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 SqlException (io.questdb.griffin.SqlException)4 BaseConnection (org.postgresql.core.BaseConnection)4 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)3 Instant (de.invesdwin.util.time.Instant)3