Search in sources :

Example 76 with Record

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

the class MinIntGroupByFunctionFactoryTest method testAllNull.

@Test
public void testAllNull() throws SqlException {
    compiler.compile("create table tab (f int)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select min(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.INT_NaN, record.getInt(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 77 with Record

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

the class MinIntGroupByFunctionFactoryTest method testFirstNull.

@Test
public void testFirstNull() throws SqlException {
    compiler.compile("create table tab (f int)", sqlExecutionContext);
    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.putInt(0, i);
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select min(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(11, record.getInt(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 78 with Record

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

the class MinLongGroupByFunctionFactoryTest method testSomeNull.

@Test
public void testSomeNull() throws SqlException {
    compiler.compile("create table tab (f long)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            if (i % 4 == 0) {
                r.putLong(0, i);
            }
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select min(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(12, record.getLong(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 79 with Record

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

the class MinLongGroupByFunctionFactoryTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    compiler.compile("create table tab (f long)", 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 min(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(-8968886490993754893L, 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 80 with Record

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

the class SwitchFunctionFactory method getIfElseFunction.

private Function getIfElseFunction(ObjList<Function> args, IntList argPositions, int position, int n, Function keyFunction, int returnType, Function elseBranch) throws SqlException {
    final CaseFunctionPicker picker;
    final ObjList<Function> argsToPoke;
    if (n == 3) {
        // only one conditional branch
        boolean value = args.getQuick(1).getBool(null);
        final Function branch = args.getQuick(2);
        final Function elseB = getElseFunction(returnType, elseBranch);
        if (value) {
            picker = record -> keyFunction.getBool(record) ? branch : elseB;
        } else {
            picker = record -> keyFunction.getBool(record) ? elseB : branch;
        }
        argsToPoke = new ObjList<>();
        argsToPoke.add(keyFunction);
        argsToPoke.add(elseB);
        argsToPoke.add(branch);
    } else if (n == 5) {
        final boolean a = args.getQuick(1).getBool(null);
        final Function branchA = args.getQuick(2);
        final boolean b = args.getQuick(3).getBool(null);
        final Function branchB = args.getQuick(4);
        if (a && b || !a && !b) {
            throw SqlException.$(argPositions.getQuick(3), "duplicate branch");
        }
        if (a) {
            picker = record -> keyFunction.getBool(record) ? branchA : branchB;
        } else {
            picker = record -> keyFunction.getBool(record) ? branchB : branchA;
        }
        argsToPoke = new ObjList<>();
        argsToPoke.add(keyFunction);
        argsToPoke.add(branchA);
        argsToPoke.add(branchB);
    } else {
        throw SqlException.$(argPositions.getQuick(5), "too many branches");
    }
    return CaseCommon.getCaseFunction(position, returnType, picker, argsToPoke);
}
Also used : ColumnType(io.questdb.cairo.ColumnType) Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Constants(io.questdb.griffin.engine.functions.constants.Constants) Record(io.questdb.cairo.sql.Record) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) FunctionFactory(io.questdb.griffin.FunctionFactory) io.questdb.std(io.questdb.std) Function(io.questdb.cairo.sql.Function)

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