Search in sources :

Example 21 with RecordSource

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();
        }
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record)

Example 22 with RecordSource

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();
        }
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) SymbolTable(com.questdb.common.SymbolTable) Record(com.questdb.common.Record)

Example 23 with RecordSource

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);
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 24 with RecordSource

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);
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 25 with RecordSource

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);
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

RecordSource (com.questdb.ql.RecordSource)30 Test (org.junit.Test)18 AbstractTest (com.questdb.test.tools.AbstractTest)12 RecordCursor (com.questdb.common.RecordCursor)11 Record (com.questdb.common.Record)10 QueryCompiler (com.questdb.parser.sql.QueryCompiler)7 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)7 StringSink (com.questdb.std.str.StringSink)5 JournalWriter (com.questdb.store.JournalWriter)5 JournalEntryWriter (com.questdb.store.JournalEntryWriter)4 Factory (com.questdb.store.factory.Factory)4 BootstrapEnv (com.questdb.BootstrapEnv)3 ServerConfiguration (com.questdb.ServerConfiguration)3 Quote (com.questdb.model.Quote)3 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)3 ImportHandler (com.questdb.net.http.handlers.ImportHandler)3 File (java.io.File)3 SymbolTable (com.questdb.common.SymbolTable)2 ClientConfig (com.questdb.net.ha.config.ClientConfig)2 ServerConfig (com.questdb.net.ha.config.ServerConfig)2