Search in sources :

Example 11 with ObjList

use of io.questdb.std.ObjList in project questdb by bluestreak01.

the class EqDoubleFunctionFactoryTest method testLeftNaNDate.

@Test
public void testLeftNaNDate() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(new DoubleConstant(Double.NaN));
    args.add(new DateConstant(10000L));
    IntList argPositions = new IntList();
    argPositions.add(2);
    argPositions.add(1);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(null));
}
Also used : Function(io.questdb.cairo.sql.Function) DoubleConstant(io.questdb.griffin.engine.functions.constants.DoubleConstant) DateConstant(io.questdb.griffin.engine.functions.constants.DateConstant) ObjList(io.questdb.std.ObjList) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 12 with ObjList

use of io.questdb.std.ObjList in project questdb by bluestreak01.

the class EqDoubleFunctionFactoryTest method testRightNaNTimestampNaN.

@Test
public void testRightNaNTimestampNaN() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(new TimestampConstant(Numbers.LONG_NaN) {

        @Override
        public boolean isConstant() {
            return false;
        }
    });
    args.add(new DoubleConstant(Double.NaN));
    IntList argPositions = new IntList();
    argPositions.add(1);
    argPositions.add(2);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertTrue(function.getBool(null));
    Assert.assertFalse(function.isConstant());
}
Also used : Function(io.questdb.cairo.sql.Function) DoubleConstant(io.questdb.griffin.engine.functions.constants.DoubleConstant) TimestampConstant(io.questdb.griffin.engine.functions.constants.TimestampConstant) ObjList(io.questdb.std.ObjList) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 13 with ObjList

use of io.questdb.std.ObjList in project questdb by bluestreak01.

the class SampleByTest method testSampleByFirstLastRecordCursorFactoryInvalidNotFirstLast.

@Test
public void testSampleByFirstLastRecordCursorFactoryInvalidNotFirstLast() {
    try {
        GenericRecordMetadata groupByMeta = new GenericRecordMetadata();
        TableColumnMetadata column = new TableColumnMetadata("col1", 1, ColumnType.LONG, false, 0, false, null);
        groupByMeta.add(column);
        GenericRecordMetadata meta = new GenericRecordMetadata();
        meta.add(column);
        ObjList<QueryColumn> columns = new ObjList<>();
        ExpressionNode first = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "min", 0, 0);
        first.rhs = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "col1", 0, 0);
        QueryColumn col = QueryColumn.FACTORY.newInstance().of("col1", first);
        columns.add(col);
        new SampleByFirstLastRecordCursorFactory(null, new MicroTimestampSampler(100L), groupByMeta, columns, meta, null, 0, null, 0, 0, getSymbolFilter(), -1);
        Assert.fail();
    } catch (SqlException e) {
        TestUtils.assertContains(e.getFlyweightMessage(), "expected first() or last() functions but got min");
    }
}
Also used : ObjList(io.questdb.std.ObjList) QueryColumn(io.questdb.griffin.model.QueryColumn) ExpressionNode(io.questdb.griffin.model.ExpressionNode) SqlException(io.questdb.griffin.SqlException) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 14 with ObjList

use of io.questdb.std.ObjList in project questdb by bluestreak01.

the class SampleByTest method testSampleByFirstLastRecordCursorFactoryInvalidColumns.

@Test
public void testSampleByFirstLastRecordCursorFactoryInvalidColumns() {
    try {
        GenericRecordMetadata groupByMeta = new GenericRecordMetadata();
        groupByMeta.add(new TableColumnMetadata("col1", 1, ColumnType.STRING, false, 0, false, null));
        GenericRecordMetadata meta = new GenericRecordMetadata();
        meta.add(new TableColumnMetadata("col1", 2, ColumnType.LONG, false, 0, false, null));
        ObjList<QueryColumn> columns = new ObjList<>();
        ExpressionNode first = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "first", 0, 0);
        first.rhs = ExpressionNode.FACTORY.newInstance().of(ColumnType.LONG, "col1", 0, 0);
        QueryColumn col = QueryColumn.FACTORY.newInstance().of("col1", first);
        columns.add(col);
        new SampleByFirstLastRecordCursorFactory(null, new MicroTimestampSampler(100L), groupByMeta, columns, meta, null, 0, null, 0, 0, getSymbolFilter(), -1);
        Assert.fail();
    } catch (SqlException e) {
        TestUtils.assertContains(e.getFlyweightMessage(), "first(), last() is not supported on data type");
    }
}
Also used : ObjList(io.questdb.std.ObjList) QueryColumn(io.questdb.griffin.model.QueryColumn) ExpressionNode(io.questdb.griffin.model.ExpressionNode) SqlException(io.questdb.griffin.SqlException) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 15 with ObjList

use of io.questdb.std.ObjList in project questdb by bluestreak01.

the class LongChainTest method testAll.

@Test
public void testAll() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (LongChain chain = new LongChain(1024 * 1024, Integer.MAX_VALUE)) {
            final int N = 1000;
            final int nChains = 10;
            final Rnd rnd = new Rnd();
            final LongList heads = new LongList(nChains);
            final ObjList<LongList> expectedValues = new ObjList<>();
            for (int i = 0; i < nChains; i++) {
                LongList expected = new LongList(N);
                heads.add(populateChain(chain, rnd, expected));
                expectedValues.add(expected);
                Assert.assertEquals(N, expected.size());
            }
            Assert.assertEquals(nChains, expectedValues.size());
            // values are be in reverse order
            for (int i = 0; i < nChains; i++) {
                LongChain.TreeCursor cursor = chain.getCursor(heads.getQuick(i));
                LongList expected = expectedValues.get(i);
                int count = 0;
                while (cursor.hasNext()) {
                    Assert.assertEquals(expected.getQuick(count), cursor.next());
                    count++;
                }
                Assert.assertEquals(N, count);
            }
        }
    });
}
Also used : ObjList(io.questdb.std.ObjList) Rnd(io.questdb.std.Rnd) LongList(io.questdb.std.LongList) Test(org.junit.Test)

Aggregations

ObjList (io.questdb.std.ObjList)16 Test (org.junit.Test)14 Function (io.questdb.cairo.sql.Function)12 FunctionFactory (io.questdb.griffin.FunctionFactory)11 IntList (io.questdb.std.IntList)11 AbstractFunctionFactoryTest (io.questdb.griffin.engine.AbstractFunctionFactoryTest)10 DoubleConstant (io.questdb.griffin.engine.functions.constants.DoubleConstant)7 SqlException (io.questdb.griffin.SqlException)3 DateConstant (io.questdb.griffin.engine.functions.constants.DateConstant)3 FloatConstant (io.questdb.griffin.engine.functions.constants.FloatConstant)3 TimestampConstant (io.questdb.griffin.engine.functions.constants.TimestampConstant)3 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)2 ExpressionNode (io.questdb.griffin.model.ExpressionNode)2 QueryColumn (io.questdb.griffin.model.QueryColumn)2 Rnd (io.questdb.std.Rnd)2 CairoConfiguration (io.questdb.cairo.CairoConfiguration)1 ColumnType (io.questdb.cairo.ColumnType)1 Record (io.questdb.cairo.sql.Record)1 VirtualRecord (io.questdb.cairo.sql.VirtualRecord)1 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)1