Search in sources :

Example 6 with SqlException

use of io.questdb.griffin.SqlException in project questdb by bluestreak01.

the class SampleByTest method testSampleFillLinearConstructorFail.

@Test
public void testSampleFillLinearConstructorFail() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
        FilesFacade ff = new FilesFacadeImpl() {

            int count = 4;

            @Override
            public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
                if (count-- > 0) {
                    return super.mmap(fd, len, offset, flags, memoryTag);
                }
                return -1;
            }
        };
        CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        try (CairoEngine engine = new CairoEngine(configuration)) {
            try (SqlCompiler compiler = new SqlCompiler(engine)) {
                try {
                    compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext);
                    Assert.fail();
                } catch (SqlException e) {
                    Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
                }
                Assert.assertEquals(0, engine.getBusyReaderCount());
                Assert.assertEquals(0, engine.getBusyWriterCount());
            }
        }
    });
}
Also used : FilesFacade(io.questdb.std.FilesFacade) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlException(io.questdb.griffin.SqlException) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 7 with SqlException

use of io.questdb.griffin.SqlException in project questdb by bluestreak01.

the class SwitchFunctionFactory method getIfElseFunction.

private Function getIfElseFunction(ObjList<Function> args, IntList argPositions, int position, int n, Function keyFunction, int returnType, Function elseBranch) throws SqlException {
    final CaseFunctionPicker picker;
    final ObjList<Function> argsToPoke;
    if (n == 3) {
        // only one conditional branch
        boolean value = args.getQuick(1).getBool(null);
        final Function branch = args.getQuick(2);
        final Function elseB = getElseFunction(returnType, elseBranch);
        if (value) {
            picker = record -> keyFunction.getBool(record) ? branch : elseB;
        } else {
            picker = record -> keyFunction.getBool(record) ? elseB : branch;
        }
        argsToPoke = new ObjList<>();
        argsToPoke.add(keyFunction);
        argsToPoke.add(elseB);
        argsToPoke.add(branch);
    } else if (n == 5) {
        final boolean a = args.getQuick(1).getBool(null);
        final Function branchA = args.getQuick(2);
        final boolean b = args.getQuick(3).getBool(null);
        final Function branchB = args.getQuick(4);
        if (a && b || !a && !b) {
            throw SqlException.$(argPositions.getQuick(3), "duplicate branch");
        }
        if (a) {
            picker = record -> keyFunction.getBool(record) ? branchA : branchB;
        } else {
            picker = record -> keyFunction.getBool(record) ? branchB : branchA;
        }
        argsToPoke = new ObjList<>();
        argsToPoke.add(keyFunction);
        argsToPoke.add(branchA);
        argsToPoke.add(branchB);
    } else {
        throw SqlException.$(argPositions.getQuick(5), "too many branches");
    }
    return CaseCommon.getCaseFunction(position, returnType, picker, argsToPoke);
}
Also used : ColumnType(io.questdb.cairo.ColumnType) Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Constants(io.questdb.griffin.engine.functions.constants.Constants) Record(io.questdb.cairo.sql.Record) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) FunctionFactory(io.questdb.griffin.FunctionFactory) io.questdb.std(io.questdb.std) Function(io.questdb.cairo.sql.Function)

Example 8 with SqlException

use of io.questdb.griffin.SqlException in project questdb by bluestreak01.

the class SwitchFunctionFactory method getIntKeyedFunction.

private Function getIntKeyedFunction(ObjList<Function> args, IntList argPositions, int position, int n, Function keyFunction, int valueType, Function elseBranch, IntMethod intMethod) throws SqlException {
    final IntObjHashMap<Function> map = new IntObjHashMap<>();
    final ObjList<Function> argsToPoke = new ObjList<>();
    for (int i = 1; i < n; i += 2) {
        final Function fun = args.getQuick(i);
        final int key = intMethod.getKey(fun, null);
        final int index = map.keyIndex(key);
        if (index < 0) {
            throw SqlException.$(argPositions.getQuick(i), "duplicate branch");
        }
        map.putAt(index, key, args.getQuick(i + 1));
        argsToPoke.add(args.getQuick(i + 1));
    }
    final Function elseB = getElseFunction(valueType, elseBranch);
    final CaseFunctionPicker picker = record -> {
        final int index = map.keyIndex(intMethod.getKey(keyFunction, record));
        if (index < 0) {
            return map.valueAtQuick(index);
        }
        return elseB;
    };
    argsToPoke.add(elseB);
    argsToPoke.add(keyFunction);
    return CaseCommon.getCaseFunction(position, valueType, picker, argsToPoke);
}
Also used : ColumnType(io.questdb.cairo.ColumnType) Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Constants(io.questdb.griffin.engine.functions.constants.Constants) Record(io.questdb.cairo.sql.Record) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) FunctionFactory(io.questdb.griffin.FunctionFactory) io.questdb.std(io.questdb.std) Function(io.questdb.cairo.sql.Function)

Example 9 with SqlException

use of io.questdb.griffin.SqlException in project questdb by bluestreak01.

the class IODispatcherTest method testJsonQueryMultiThreaded.

@Test
public void testJsonQueryMultiThreaded() throws Exception {
    final int threadCount = 4;
    final int requestsPerThread = 500;
    final String[][] requests = { { "GET /exec?query=xyz%20where%20sym%20%3D%20%27UDEYY%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "d9\r\n" + "{\"query\":\"xyz where sym = 'UDEYY'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"UDEYY\",0.15786635599554755],[\"UDEYY\",0.8445258177211064],[\"UDEYY\",0.5778947915182423]],\"count\":3}\r\n" + "00\r\n" + "\r\n" }, { "GET /exec?query=xyz%20where%20sym%20%3D%20%27QEHBH%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "0114\r\n" + "{\"query\":\"xyz where sym = 'QEHBH'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"QEHBH\",0.4022810626779558],[\"QEHBH\",0.9038068796506872],[\"QEHBH\",0.05048190020054388],[\"QEHBH\",0.4149517697653501],[\"QEHBH\",0.44804689668613573]],\"count\":5}\r\n" + "00\r\n" + "\r\n" }, { "GET /exec?query=xyz%20where%20sym%20%3D%20%27SXUXI%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "da\r\n" + "{\"query\":\"xyz where sym = 'SXUXI'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"SXUXI\",0.6761934857077543],[\"SXUXI\",0.38642336707855873],[\"SXUXI\",0.48558682958070665]],\"count\":3}\r\n" + "00\r\n" + "\r\n" }, { "GET /exec?query=xyz%20where%20sym%20%3D%20%27VTJWC%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "f4\r\n" + "{\"query\":\"xyz where sym = 'VTJWC'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"VTJWC\",0.3435685332942956],[\"VTJWC\",0.8258367614088108],[\"VTJWC\",0.437176959518218],[\"VTJWC\",0.7176053468281931]],\"count\":4}\r\n" + "00\r\n" + "\r\n" } };
    new HttpQueryTestBuilder().withTempFolder(temp).withWorkerCount(threadCount).withHttpServerConfigBuilder(new HttpServerConfigurationBuilder()).withTelemetry(false).run((engine) -> {
        final SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1);
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            compiler.compile("create table xyz as (select rnd_symbol(10, 5, 5, 0) sym, rnd_double() d from long_sequence(30)), index(sym)", sqlExecutionContext);
            final CyclicBarrier barrier = new CyclicBarrier(threadCount);
            final CountDownLatch latch = new CountDownLatch(threadCount);
            final AtomicInteger errorCount = new AtomicInteger(0);
            for (int i = 0; i < threadCount; i++) {
                new QueryThread(requests, requestsPerThread, barrier, latch, errorCount).start();
            }
            latch.await();
            Assert.assertEquals(0, errorCount.get());
        } catch (SqlException e) {
            Assert.fail(e.getMessage());
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SqlException(io.questdb.griffin.SqlException) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 10 with SqlException

use of io.questdb.griffin.SqlException in project questdb by bluestreak01.

the class SwitchFunctionFactory method getLongKeyedFunction.

private Function getLongKeyedFunction(ObjList<Function> args, IntList argPositions, int position, int n, Function keyFunction, int valueType, Function elseBranch, LongMethod longMethod) throws SqlException {
    final LongObjHashMap<Function> map = new LongObjHashMap<>();
    final ObjList<Function> argsToPoke = new ObjList<>();
    for (int i = 1; i < n; i += 2) {
        final Function fun = args.getQuick(i);
        final long key = longMethod.getKey(fun, null);
        final int index = map.keyIndex(key);
        if (index < 0) {
            throw SqlException.$(argPositions.getQuick(i), "duplicate branch");
        }
        map.putAt(index, key, args.getQuick(i + 1));
        argsToPoke.add(args.getQuick(i + 1));
    }
    final Function elseB = getElseFunction(valueType, elseBranch);
    final CaseFunctionPicker picker = record -> {
        final int index = map.keyIndex(longMethod.getKey(keyFunction, record));
        if (index < 0) {
            return map.valueAtQuick(index);
        }
        return elseB;
    };
    argsToPoke.add(elseB);
    argsToPoke.add(keyFunction);
    return CaseCommon.getCaseFunction(position, valueType, picker, argsToPoke);
}
Also used : ColumnType(io.questdb.cairo.ColumnType) Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Constants(io.questdb.griffin.engine.functions.constants.Constants) Record(io.questdb.cairo.sql.Record) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) FunctionFactory(io.questdb.griffin.FunctionFactory) io.questdb.std(io.questdb.std) Function(io.questdb.cairo.sql.Function)

Aggregations

SqlException (io.questdb.griffin.SqlException)17 SqlCompiler (io.questdb.griffin.SqlCompiler)9 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)9 Test (org.junit.Test)9 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)7 CairoConfiguration (io.questdb.cairo.CairoConfiguration)5 Function (io.questdb.cairo.sql.Function)5 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)5 ColumnType (io.questdb.cairo.ColumnType)4 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)4 FunctionFactory (io.questdb.griffin.FunctionFactory)4 Constants (io.questdb.griffin.engine.functions.constants.Constants)4 Record (io.questdb.cairo.sql.Record)3 io.questdb.std (io.questdb.std)3 ObjList (io.questdb.std.ObjList)3 ExpressionNode (io.questdb.griffin.model.ExpressionNode)2 QueryColumn (io.questdb.griffin.model.QueryColumn)2 Runner (org.openjdk.jmh.runner.Runner)2 Options (org.openjdk.jmh.runner.options.Options)2