Search in sources :

Example 1 with NumericException

use of io.questdb.std.NumericException in project questdb by bluestreak01.

the class FunctionParserTest method testNoArgFunction.

@Test
public void testNoArgFunction() throws SqlException {
    functions.add(new SysdateFunctionFactory());
    functions.add(new ToStrDateFunctionFactory());
    FunctionParser functionParser = new FunctionParser(new DefaultCairoConfiguration(root) {

        @Override
        public MillisecondClock getMillisecondClock() {
            return () -> {
                try {
                    return DateFormatUtils.parseUTCDate("2018-03-04T21:40:00.000Z");
                } catch (NumericException e) {
                    Assert.fail();
                }
                return 0;
            };
        }
    }, new FunctionFactoryCache(configuration, functions));
    Function function = parseFunction("to_str(sysdate(), 'EE, dd-MMM-yyyy HH:mm:ss')", new GenericRecordMetadata(), functionParser);
    TestUtils.assertEquals("Sunday, 04-Mar-2018 21:40:00", function.getStr(null));
}
Also used : Function(io.questdb.cairo.sql.Function) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) NumericException(io.questdb.std.NumericException) MillisecondClock(io.questdb.std.datetime.millitime.MillisecondClock) Test(org.junit.Test)

Example 2 with NumericException

use of io.questdb.std.NumericException in project questdb by bluestreak01.

the class TextQueryProcessor method parseUrl.

private boolean parseUrl(HttpChunkedResponseSocket socket, HttpRequestHeader request, TextQueryProcessorState state) throws PeerDisconnectedException, PeerIsSlowToReadException {
    // Query text.
    final DirectByteCharSequence query = request.getUrlParam("query");
    if (query == null || query.length() == 0) {
        info(state).$("Empty query request received. Sending empty reply.").$();
        sendException(socket, 0, "No query text", state);
        return false;
    }
    // Url Params.
    long skip = 0;
    long stop = Long.MAX_VALUE;
    CharSequence limit = request.getUrlParam("limit");
    if (limit != null) {
        int sepPos = Chars.indexOf(limit, ',');
        try {
            if (sepPos > 0) {
                skip = Numbers.parseLong(limit, 0, sepPos);
                if (sepPos + 1 < limit.length()) {
                    stop = Numbers.parseLong(limit, sepPos + 1, limit.length());
                }
            } else {
                stop = Numbers.parseLong(limit);
            }
        } catch (NumericException ex) {
        // Skip or stop will have default value.
        }
    }
    if (stop < 0) {
        stop = 0;
    }
    if (skip < 0) {
        skip = 0;
    }
    if ((stop - skip) > configuration.getMaxQueryResponseRowLimit()) {
        stop = skip + configuration.getMaxQueryResponseRowLimit();
    }
    state.query.clear();
    try {
        TextUtil.utf8Decode(query.getLo(), query.getHi(), state.query);
    } catch (Utf8Exception e) {
        info(state).$("Bad UTF8 encoding").$();
        sendException(socket, 0, "Bad UTF8 encoding in query text", state);
        return false;
    }
    CharSequence fileName = request.getUrlParam("filename");
    state.fileName = null;
    if (fileName != null && fileName.length() > 0) {
        state.fileName = fileName.toString();
    }
    state.skip = skip;
    state.count = 0L;
    state.stop = stop;
    state.noMeta = Chars.equalsNc("true", request.getUrlParam("nm"));
    state.countRows = Chars.equalsNc("true", request.getUrlParam("count"));
    return true;
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) NumericException(io.questdb.std.NumericException) Utf8Exception(io.questdb.cutlass.text.Utf8Exception)

Aggregations

NumericException (io.questdb.std.NumericException)2 Function (io.questdb.cairo.sql.Function)1 Utf8Exception (io.questdb.cutlass.text.Utf8Exception)1 SysdateFunctionFactory (io.questdb.griffin.engine.functions.date.SysdateFunctionFactory)1 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)1 MillisecondClock (io.questdb.std.datetime.millitime.MillisecondClock)1 DirectByteCharSequence (io.questdb.std.str.DirectByteCharSequence)1 Test (org.junit.Test)1