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