Search in sources :

Example 41 with Record

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

the class FunctionParserTest method testByteToShortCast.

@Test
public void testByteToShortCast() throws SqlException {
    functions.add(new AddShortFunctionFactory());
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.BYTE));
    metadata.add(new TableColumnMetadata("b", 2, ColumnType.BYTE));
    FunctionParser functionParser = createFunctionParser();
    Function function = parseFunction("a+b", metadata, functionParser);
    Assert.assertEquals(ColumnType.SHORT, function.getType());
    Assert.assertEquals(131, function.getShort(new Record() {

        @Override
        public byte getByte(int col) {
            if (col == 0) {
                return 41;
            }
            return 90;
        }
    }));
}
Also used : Function(io.questdb.cairo.sql.Function) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 42 with Record

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

the class KeyedAggregationTest method testIntSymbolSumTimeRange.

@Test
public void testIntSymbolSumTimeRange() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table tab as (select rnd_symbol('s1','s2','s3', null) s1, rnd_double(2) val, timestamp_sequence(0, 1000000) t from long_sequence(1000000)) timestamp(t) partition by DAY", sqlExecutionContext);
        compiler.compile("alter table tab add column s2 symbol cache", sqlExecutionContext);
        compiler.compile("insert into tab select rnd_symbol('s1','s2','s3', null), rnd_double(2), timestamp_sequence(cast('1970-01-13T00:00:00.000000Z' as timestamp), 1000000), rnd_symbol('a1','a2','a3', null) s2 from long_sequence(1000000)", sqlExecutionContext);
        // test with key falling within null columns
        try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab order by s2", sqlExecutionContext).getRecordCursorFactory()) {
            Record[] expected = new Record[] { new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return null;
                }

                @Override
                public double getDouble(int col) {
                    return 520447.6629968692;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a1";
                }

                @Override
                public double getDouble(int col) {
                    return 104308.65839619662;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a2";
                }

                @Override
                public double getDouble(int col) {
                    return 104559.28674751727;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a3";
                }

                @Override
                public double getDouble(int col) {
                    return 104044.11326997768;
                }
            } };
            assertCursorRawRecords(expected, factory, false, true);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 43 with Record

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

the class O3Test method testAppendOrderStability.

private static void testAppendOrderStability(CairoEngine engine, SqlCompiler compiler, SqlExecutionContext sqlExecutionContext) throws SqlException {
    compiler.compile("create table x (" + "seq long, " + "sym symbol, " + "ts timestamp" + "), index(sym) timestamp (ts) partition by DAY", sqlExecutionContext);
    String[] symbols = { "AA", "BB" };
    long[] seq = new long[symbols.length];
    // insert some records in order
    final Rnd rnd = new Rnd();
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
        long t = 0;
        for (int i = 0; i < 1000; i++) {
            TableWriter.Row r = w.newRow(t++);
            int index = rnd.nextInt(1);
            r.putLong(0, seq[index]++);
            r.putSym(1, symbols[index]);
            r.append();
        }
        w.commitWithLag();
        // now do out of order
        for (int i = 0; i < 100_000; i++) {
            TableWriter.Row r;
            // symbol 0
            r = w.newRow(t + 1);
            r.putLong(0, seq[0]++);
            r.putSym(1, symbols[0]);
            r.append();
            r = w.newRow(t + 1);
            r.putLong(0, seq[0]++);
            r.putSym(1, symbols[0]);
            r.append();
            // symbol 1
            r = w.newRow(t);
            r.putLong(0, seq[1]++);
            r.putSym(1, symbols[1]);
            r.append();
            r = w.newRow(t);
            r.putLong(0, seq[1]++);
            r.putSym(1, symbols[1]);
            r.append();
            t += 2;
        }
        w.commit();
    }
    // now verify that sequence did not get mixed up in the table
    long[] actualSeq = new long[symbols.length];
    try (RecordCursorFactory f = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory();
        RecordCursor cursor = f.getCursor(sqlExecutionContext)) {
        final Record record = cursor.getRecord();
        while (cursor.hasNext()) {
            int index = record.getInt(1);
            Assert.assertEquals(record.getLong(0), actualSeq[index]++);
        }
    }
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record)

Example 44 with Record

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

the class FirstDateGroupByFunctionFactoryTest method testFirstNull.

@Test
public void testFirstNull() throws SqlException {
    compiler.compile("create table tab (f date)", sqlExecutionContext);
    final Rnd rnd = new Rnd();
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        TableWriter.Row r = w.newRow();
        r.append();
        for (int i = 100; i > 10; i--) {
            r = w.newRow();
            r.putLong(0, rnd.nextLong());
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(Numbers.LONG_NaN, record.getLong(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 45 with Record

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

the class FirstDateGroupByFunctionFactoryTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    compiler.compile("create table tab (f date)", sqlExecutionContext);
    final Rnd rnd = new Rnd();
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            r.putLong(0, rnd.nextLong());
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(4689592037643856L, record.getLong(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

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