use of com.questdb.ql.RecordSource in project questdb by bluestreak01.
the class AbstractOptimiserTest method assertString.
protected void assertString(String query, int columnIndex) throws ParserException {
try (RecordSource rs = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
RecordCursor cursor = rs.prepareCursor(FACTORY_CONTAINER.getFactory());
try {
while (cursor.hasNext()) {
Record r = cursor.next();
int len = r.getStrLen(columnIndex);
CharSequence s = r.getFlyweightStr(columnIndex);
if (s != null) {
CharSequence csB = r.getFlyweightStrB(columnIndex);
TestUtils.assertEquals(s, csB);
Assert.assertEquals(len, s.length());
Assert.assertFalse(s == csB);
} else {
Assert.assertEquals(-1, len);
Assert.assertNull(r.getFlyweightStr(columnIndex));
Assert.assertNull(r.getFlyweightStrB(columnIndex));
}
}
} finally {
cursor.releaseCursor();
}
}
}
use of com.questdb.ql.RecordSource in project questdb by bluestreak01.
the class AbstractOptimiserTest method assertSymbol.
public static void assertSymbol(String query, int columnIndex) throws ParserException {
try (RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory());
try {
SymbolTable tab = cursor.getStorageFacade().getSymbolTable(columnIndex);
while (cursor.hasNext()) {
Record r = cursor.next();
TestUtils.assertEquals(r.getSym(columnIndex), tab.value(r.getInt(columnIndex)));
}
} finally {
cursor.releaseCursor();
}
}
}
use of com.questdb.ql.RecordSource in project questdb by bluestreak01.
the class SingleJournalQueryTest method testParamNotSet.
@Test(expected = UndefinedParameterException.class)
public void testParamNotSet() throws Exception {
createTabWithNaNs2();
sink.clear();
try (RecordSource src = compile("select id, z from tab where z > :min limit :lim")) {
printer.print(src, getFactory(), false);
}
}
use of com.questdb.ql.RecordSource in project questdb by bluestreak01.
the class SingleJournalQueryTest method testParamInQuery.
@Test
public void testParamInQuery() throws Exception {
createTabWithNaNs2();
final String expected = "NDESHYUMEUKVZIE\t485\n" + "LLEYMIWTCWLFORG\t456\n" + "EOCVFFKMEKPFOYM\t481\n" + "NZVDJIGSYLXGYTE\t489\n" + "KIWIHBROKZKUTIQ\t498\n" + "IWEODDBHEVGXYHJ\t463\n" + "WCCNGTNLEGPUHHI\t452\n" + "EENNEBQQEMXDKXE\t492\n" + "BSQCNSFFLTRYZUZ\t494\n" + "QBUYZVQQHSQSPZP\t452\n";
sink.clear();
try (RecordSource src = compile("select id, z from tab where z > :min limit :lim")) {
src.getParam(":min").set(450);
src.getParam(":lim").set(10L);
printer.print(src, getFactory(), false);
}
sink.clear();
try (RecordSource src = compile("select id, z from tab where :min < z limit :lim")) {
src.getParam(":min").set(450);
src.getParam(":lim").set(10L);
printer.print(src, getFactory(), false);
TestUtils.assertEquals(expected, sink);
}
}
use of com.questdb.ql.RecordSource in project questdb by bluestreak01.
the class SingleJournalQueryTest method testParamInLimit.
@Test
public void testParamInLimit() throws Exception {
createTabWithNaNs2();
final String expected = "YDVRVNGSTEQODRZ\t-99\n" + "RIIYMHOWKCDNZNL\t-397\n" + "XZOUICWEKGHVUVS\t367\n" + "FDTNPHFLPBNHGZW\t356\n" + "MQMUDDCIHCNPUGJ\t304\n" + "HYBTVZNCLNXFSUW\t-276\n" + "UMKUBKXPMSXQSTV\t-100\n" + "KJSMSSUQSRLTKVV\t345\n" + "HOLNVTIQBZXIOVI\t112\n" + "ZSFXUNYQXTGNJJI\t-162\n";
sink.clear();
try (RecordSource src = compile("select id, z from tab limit :xyz")) {
src.getParam(":xyz").set(10L);
printer.print(src, getFactory(), false);
TestUtils.assertEquals(expected, sink);
}
// and one more time
sink.clear();
try (RecordSource src = compile("select id, z from tab limit :xyz")) {
src.getParam(":xyz").set(10L);
printer.print(src, getFactory(), false);
TestUtils.assertEquals(expected, sink);
}
// and now change parameter
sink.clear();
try (RecordSource src = compile("select id, z from tab limit :xyz")) {
src.getParam(":xyz").set(5L);
printer.print(src, getFactory(), false);
final String expected2 = "YDVRVNGSTEQODRZ\t-99\n" + "RIIYMHOWKCDNZNL\t-397\n" + "XZOUICWEKGHVUVS\t367\n" + "FDTNPHFLPBNHGZW\t356\n" + "MQMUDDCIHCNPUGJ\t304\n";
TestUtils.assertEquals(expected2, sink);
}
}
Aggregations