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");
}
}
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);
}
Aggregations