Search in sources :

Example 1 with Utf8Exception

use of io.questdb.cutlass.text.Utf8Exception in project questdb by bluestreak01.

the class JsonQueryProcessor method parseUrl.

private boolean parseUrl(JsonQueryProcessorState state, CharSequence keepAliveHeader) throws PeerDisconnectedException, PeerIsSlowToReadException {
    // Query text.
    final HttpRequestHeader header = state.getHttpConnectionContext().getRequestHeader();
    final DirectByteCharSequence query = header.getUrlParam("query");
    if (query == null || query.length() == 0) {
        state.info().$("Empty query header received. Sending empty reply.").$();
        sendException(state.getHttpConnectionContext().getChunkedResponseSocket(), 0, "No query text", query, keepAliveHeader);
        return false;
    }
    // Url Params.
    long skip = 0;
    long stop = Long.MAX_VALUE;
    CharSequence limit = header.getUrlParam("limit");
    if (limit != null) {
        int sepPos = Chars.indexOf(limit, ',');
        try {
            if (sepPos > 0) {
                skip = Numbers.parseLong(limit, 0, sepPos) - 1;
                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();
    }
    try {
        state.configure(header, query, skip, stop);
    } catch (Utf8Exception e) {
        state.info().$("Bad UTF8 encoding").$();
        sendException(state.getHttpConnectionContext().getChunkedResponseSocket(), 0, "Bad UTF8 encoding in query text", query, keepAliveHeader);
        return false;
    }
    return true;
}
Also used : DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) Utf8Exception(io.questdb.cutlass.text.Utf8Exception)

Example 2 with Utf8Exception

use of io.questdb.cutlass.text.Utf8Exception in project questdb by bluestreak01.

the class JsonQueryProcessorState method of.

boolean of(RecordCursorFactory factory, SqlExecutionContextImpl sqlExecutionContext) throws PeerDisconnectedException, PeerIsSlowToReadException, SqlException {
    this.recordCursorFactory = factory;
    queryCacheable = true;
    this.cursor = factory.getCursor(sqlExecutionContext);
    final RecordMetadata metadata = factory.getMetadata();
    HttpRequestHeader header = httpConnectionContext.getRequestHeader();
    DirectByteCharSequence columnNames = header.getUrlParam("cols");
    int columnCount;
    columnSkewList.clear();
    if (columnNames != null) {
        columnsQueryParameter.clear();
        try {
            TextUtil.utf8Decode(columnNames.getLo(), columnNames.getHi(), columnsQueryParameter);
        } catch (Utf8Exception e) {
            info().$("utf8 error when decoding column list '").$(columnNames).$('\'').$();
            HttpChunkedResponseSocket socket = getHttpConnectionContext().getChunkedResponseSocket();
            JsonQueryProcessor.header(socket, "");
            socket.put('{').putQuoted("error").put(':').putQuoted("utf8 error in column list");
            socket.put('}');
            socket.sendChunk(true);
            return false;
        }
        columnCount = 1;
        int start = 0;
        int comma = 0;
        while (comma > -1) {
            comma = Chars.indexOf(columnsQueryParameter, start, ',');
            if (comma > -1) {
                if (addColumnToOutput(metadata, columnsQueryParameter, start, comma)) {
                    return false;
                }
                start = comma + 1;
                columnCount++;
            } else {
                int hi = columnsQueryParameter.length();
                if (addColumnToOutput(metadata, columnsQueryParameter, start, hi)) {
                    return false;
                }
            }
        }
    } else {
        columnCount = metadata.getColumnCount();
        for (int i = 0; i < columnCount; i++) {
            addColumnTypeAndName(metadata, i);
        }
    }
    this.columnCount = columnCount;
    return true;
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) HttpChunkedResponseSocket(io.questdb.cutlass.http.HttpChunkedResponseSocket) DirectByteCharSequence(io.questdb.std.str.DirectByteCharSequence) HttpRequestHeader(io.questdb.cutlass.http.HttpRequestHeader) Utf8Exception(io.questdb.cutlass.text.Utf8Exception)

Example 3 with Utf8Exception

use of io.questdb.cutlass.text.Utf8Exception 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

Utf8Exception (io.questdb.cutlass.text.Utf8Exception)3 DirectByteCharSequence (io.questdb.std.str.DirectByteCharSequence)3 RecordMetadata (io.questdb.cairo.sql.RecordMetadata)1 HttpChunkedResponseSocket (io.questdb.cutlass.http.HttpChunkedResponseSocket)1 HttpRequestHeader (io.questdb.cutlass.http.HttpRequestHeader)1 NumericException (io.questdb.std.NumericException)1