Search in sources :

Example 36 with IntList

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

the class FunctionParserTest method testPassVarToConstArg.

@Test
public void testPassVarToConstArg() {
    functions.add(new FunctionFactory() {

        @Override
        public String getSignature() {
            return "x(i)";
        }

        @Override
        public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
            return null;
        }
    });
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.INT));
    try {
        parseFunction("x(a)", metadata, createFunctionParser());
        Assert.fail();
    } catch (SqlException e) {
        Assert.assertEquals(0, e.getPosition());
        TestUtils.assertContains(e.getFlyweightMessage(), "unexpected argument");
        TestUtils.assertContains(e.getFlyweightMessage(), "constant");
    }
}
Also used : Function(io.questdb.cairo.sql.Function) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) EqLongFunctionFactory(io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) SwitchFunctionFactory(io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory) EqIntFunctionFactory(io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory) LengthSymbolFunctionFactory(io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory) OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) LengthStrFunctionFactory(io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory) EqDoubleFunctionFactory(io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) CursorDereferenceFunctionFactory(io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory) ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) ToCharBinFunctionFactory(io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory) CastStrToGeoHashFunctionFactory(io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test)

Example 37 with IntList

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

the class O3CommitLagTest method testContinuousBatchedCommit0.

private void testContinuousBatchedCommit0(CairoEngine engine, SqlCompiler compiler, SqlExecutionContext sqlExecutionContext) throws SqlException {
    int nTotalRows = 50000;
    int nInitialStateRows = 150;
    long microsBetweenRows = 100000000;
    int maxBatchedRows = 10;
    int maxConcurrentBatches = 4;
    int nRowsPerCommit = 100;
    long commitLag = microsBetweenRows * (nRowsPerCommit / 2);
    String sql = "create table x as (" + "select" + " cast(x as int) i," + " rnd_symbol('msft','ibm', 'googl') sym," + " round(rnd_double(0)*100, 3) amt," + " to_timestamp('2018-01', 'yyyy-MM') + x * 720000000 timestamp," + " rnd_boolean() b," + " rnd_str('ABC', 'CDE', null, 'XYZ') c," + " rnd_double(2) d," + " rnd_float(2) e," + " rnd_short(10,1024) f," + " rnd_date(to_date('2015', 'yyyy'), to_date('2016', 'yyyy'), 2) g," + " rnd_symbol(4,4,4,2) ik," + " rnd_long() j," + " timestamp_sequence(0L," + microsBetweenRows + "L) ts," + " rnd_byte(2,50) l," + " rnd_bin(10, 20, 2) m," + " rnd_str(5,16,2) n," + " rnd_char() t" + " from long_sequence(" + nTotalRows + ")" + "), index(sym) timestamp (ts) partition by DAY";
    compiler.compile(sql, sqlExecutionContext);
    sql = "create table y as (select * from x where  i<=" + nInitialStateRows + ") partition by DAY";
    compiler.compile(sql, sqlExecutionContext);
    LOG.info().$("committed initial state").$();
    TestUtils.printSql(compiler, sqlExecutionContext, "select * from x where i<=" + nInitialStateRows, sink);
    TestUtils.printSql(compiler, sqlExecutionContext, "select * from y", sink2);
    TestUtils.assertEquals(sink, sink2);
    Random rand = new Random(0);
    IntList batchRowEnd = new IntList((int) ((nTotalRows - nInitialStateRows) * 0.6 * maxBatchedRows));
    int atRow = nInitialStateRows;
    // negative row means this has been commited
    batchRowEnd.add(-atRow);
    while (atRow < nTotalRows) {
        int nRows = rand.nextInt(maxBatchedRows) + 1;
        atRow += nRows;
        batchRowEnd.add(atRow);
    }
    int nCommitsWithLag = 0;
    try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "y", "testing")) {
        int nHeadBatch = 1;
        int nRowsAppended = 0;
        while (nHeadBatch < batchRowEnd.size()) {
            int nBatch = nHeadBatch + rand.nextInt(maxConcurrentBatches);
            while (nBatch >= batchRowEnd.size() || batchRowEnd.get(nBatch) < 0) {
                nBatch--;
            }
            assert nBatch >= nHeadBatch;
            if (nBatch == nHeadBatch) {
                do {
                    nHeadBatch++;
                } while (nHeadBatch < batchRowEnd.size() && batchRowEnd.get(nHeadBatch) < 0);
            }
            int fromRow = Math.abs(batchRowEnd.get(nBatch - 1));
            int toRow = batchRowEnd.get(nBatch);
            batchRowEnd.set(nBatch, -toRow);
            LOG.info().$("inserting rows from ").$(fromRow).$(" to ").$(toRow).$();
            sql = "select * from x where ts>=cast(" + fromRow * microsBetweenRows + " as timestamp) and ts<cast(" + toRow * microsBetweenRows + " as timestamp)";
            insertUncommitted(compiler, sqlExecutionContext, sql, writer);
            nRowsAppended += toRow - fromRow;
            if (nRowsAppended >= nRowsPerCommit) {
                LOG.info().$("committing with lag").$();
                nRowsAppended = 0;
                writer.commitWithLag(commitLag);
                nCommitsWithLag++;
            }
        }
        writer.commit();
    }
    LOG.info().$("committed final state with ").$(nCommitsWithLag).$(" commits with lag").$();
    assertXY(compiler, sqlExecutionContext);
}
Also used : Random(java.util.Random) IntList(io.questdb.std.IntList)

Aggregations

IntList (io.questdb.std.IntList)37 Function (io.questdb.cairo.sql.Function)33 Test (org.junit.Test)31 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)22 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)22 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)22 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)22 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)22 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)22 SysdateFunctionFactory (io.questdb.griffin.engine.functions.date.SysdateFunctionFactory)22 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)22 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)22 EqDoubleFunctionFactory (io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory)22 EqIntFunctionFactory (io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory)22 EqLongFunctionFactory (io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory)22 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)22 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)22 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)22 Record (io.questdb.cairo.sql.Record)15 FunctionFactory (io.questdb.griffin.FunctionFactory)11