Search in sources :

Example 6 with RecordMetadata

use of io.questdb.cairo.sql.RecordMetadata 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 7 with RecordMetadata

use of io.questdb.cairo.sql.RecordMetadata in project questdb by bluestreak01.

the class CursorDereferenceFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function cursorFunction = args.getQuick(0);
    Function columnNameFunction = args.getQuick(1);
    RecordMetadata metadata = cursorFunction.getMetadata();
    // name is always constant
    final CharSequence columnName = columnNameFunction.getStr(null);
    final int columnIndex = metadata.getColumnIndexQuiet(columnName);
    if (columnIndex == -1) {
        throw SqlException.invalidColumn(argPositions.getQuick(1), columnName);
    }
    final int columnType = metadata.getColumnType(columnIndex);
    if (ColumnType.isInt(columnType)) {
        return new IntColumnFunction(cursorFunction, columnNameFunction, columnIndex);
    }
    throw SqlException.$(argPositions.getQuick(1), "unsupported column type: ").put(ColumnType.nameOf(columnType));
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) BinaryFunction(io.questdb.griffin.engine.functions.BinaryFunction) Function(io.questdb.cairo.sql.Function) IntFunction(io.questdb.griffin.engine.functions.IntFunction)

Example 8 with RecordMetadata

use of io.questdb.cairo.sql.RecordMetadata in project questdb by bluestreak01.

the class AbstractSqlParserTest method assertColumnNames.

private void assertColumnNames(SqlCompiler compiler, String query, String... columns) throws SqlException {
    CompiledQuery cc = compiler.compile(query, sqlExecutionContext);
    RecordMetadata metadata = cc.getRecordCursorFactory().getMetadata();
    for (int idx = 0; idx < columns.length; idx++) {
        TestUtils.assertEquals(metadata.getColumnName(idx), columns[idx]);
    }
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata)

Example 9 with RecordMetadata

use of io.questdb.cairo.sql.RecordMetadata in project questdb by bluestreak01.

the class TextImportProcessor method resumeJson.

private static void resumeJson(TextImportProcessorState state, HttpChunkedResponseSocket socket) throws PeerDisconnectedException, PeerIsSlowToReadException {
    final TextLoaderCompletedState completeState = state.completeState;
    final RecordMetadata metadata = completeState.getMetadata();
    final LongList errors = completeState.getColumnErrorCounts();
    switch(state.responseState) {
        case RESPONSE_PREFIX:
            long totalRows = completeState.getParsedLineCount();
            long importedRows = completeState.getWrittenLineCount();
            socket.put('{').putQuoted("status").put(':').putQuoted("OK").put(',').putQuoted("location").put(':').encodeUtf8AndQuote(completeState.getTableName()).put(',').putQuoted("rowsRejected").put(':').put(totalRows - importedRows + completeState.getErrorLineCount()).put(',').putQuoted("rowsImported").put(':').put(importedRows).put(',').putQuoted("header").put(':').put(completeState.isForceHeaders()).put(',');
            if (completeState.getWarnings() != TextLoadWarning.NONE) {
                final int warningFlags = completeState.getWarnings();
                socket.putQuoted("warnings").put(':').put('[');
                boolean isFirst = true;
                if ((warningFlags & TextLoadWarning.TIMESTAMP_MISMATCH) != TextLoadWarning.NONE) {
                    isFirst = false;
                    socket.putQuoted("Existing table timestamp column is used");
                }
                if ((warningFlags & PARTITION_TYPE_MISMATCH) != TextLoadWarning.NONE) {
                    if (!isFirst)
                        socket.put(',');
                    socket.putQuoted("Existing table PartitionBy is used");
                }
                socket.put(']').put(',');
            }
            socket.putQuoted("columns").put(':').put('[');
            state.responseState = RESPONSE_COLUMN;
        // fall through
        case RESPONSE_COLUMN:
            if (metadata != null) {
                final int columnCount = metadata.getColumnCount();
                for (; state.columnIndex < columnCount; state.columnIndex++) {
                    socket.bookmark();
                    if (state.columnIndex > 0) {
                        socket.put(',');
                    }
                    socket.put('{').putQuoted("name").put(':').putQuoted(metadata.getColumnName(state.columnIndex)).put(',').putQuoted("type").put(':').putQuoted(ColumnType.nameOf(metadata.getColumnType(state.columnIndex))).put(',').putQuoted("size").put(':').put(ColumnType.sizeOf(metadata.getColumnType(state.columnIndex))).put(',').putQuoted("errors").put(':').put(errors.getQuick(state.columnIndex));
                    socket.put('}');
                }
            }
            state.responseState = RESPONSE_SUFFIX;
        // fall through
        case RESPONSE_SUFFIX:
            socket.bookmark();
            socket.put(']').put('}');
            state.responseState = RESPONSE_COMPLETE;
            socket.sendChunk(true);
            break;
        case RESPONSE_DONE:
            state.responseState = RESPONSE_COMPLETE;
            socket.done();
            break;
        default:
            break;
    }
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata)

Example 10 with RecordMetadata

use of io.questdb.cairo.sql.RecordMetadata in project questdb by bluestreak01.

the class TextImportProcessor method resumeText.

private static void resumeText(TextImportProcessorState state, HttpChunkedResponseSocket socket) throws PeerDisconnectedException, PeerIsSlowToReadException {
    final TextLoaderCompletedState textLoaderCompletedState = state.completeState;
    final RecordMetadata metadata = textLoaderCompletedState.getMetadata();
    LongList errors = textLoaderCompletedState.getColumnErrorCounts();
    switch(state.responseState) {
        case RESPONSE_PREFIX:
            sep(socket);
            socket.put('|');
            pad(socket, TO_STRING_COL1_PAD, "Location:");
            pad(socket, TO_STRING_COL2_PAD, textLoaderCompletedState.getTableName());
            pad(socket, TO_STRING_COL3_PAD, "Pattern");
            pad(socket, TO_STRING_COL4_PAD, "Locale");
            pad(socket, TO_STRING_COL5_PAD, "Errors").put(Misc.EOL);
            socket.put('|');
            pad(socket, TO_STRING_COL1_PAD, "Partition by");
            pad(socket, TO_STRING_COL2_PAD, PartitionBy.toString(textLoaderCompletedState.getPartitionBy()));
            pad(socket, TO_STRING_COL3_PAD, "");
            pad(socket, TO_STRING_COL4_PAD, "");
            if (hasFlag(textLoaderCompletedState.getWarnings(), PARTITION_TYPE_MISMATCH)) {
                pad(socket, TO_STRING_COL5_PAD, OVERRIDDEN_FROM_TABLE);
            } else {
                pad(socket, TO_STRING_COL5_PAD, "");
            }
            socket.put(Misc.EOL);
            socket.put('|');
            pad(socket, TO_STRING_COL1_PAD, "Timestamp");
            pad(socket, TO_STRING_COL2_PAD, textLoaderCompletedState.getTimestampCol() == null ? "NONE" : textLoaderCompletedState.getTimestampCol());
            pad(socket, TO_STRING_COL3_PAD, "");
            pad(socket, TO_STRING_COL4_PAD, "");
            if (hasFlag(textLoaderCompletedState.getWarnings(), TIMESTAMP_MISMATCH)) {
                pad(socket, TO_STRING_COL5_PAD, OVERRIDDEN_FROM_TABLE);
            } else {
                pad(socket, TO_STRING_COL5_PAD, "");
            }
            socket.put(Misc.EOL);
            sep(socket);
            socket.put('|');
            pad(socket, TO_STRING_COL1_PAD, "Rows handled");
            pad(socket, TO_STRING_COL2_PAD, textLoaderCompletedState.getParsedLineCount() + textLoaderCompletedState.getErrorLineCount());
            pad(socket, TO_STRING_COL3_PAD, "");
            pad(socket, TO_STRING_COL4_PAD, "");
            pad(socket, TO_STRING_COL5_PAD, "").put(Misc.EOL);
            socket.put('|');
            pad(socket, TO_STRING_COL1_PAD, "Rows imported");
            pad(socket, TO_STRING_COL2_PAD, textLoaderCompletedState.getWrittenLineCount());
            pad(socket, TO_STRING_COL3_PAD, "");
            pad(socket, TO_STRING_COL4_PAD, "");
            pad(socket, TO_STRING_COL5_PAD, "").put(Misc.EOL);
            sep(socket);
            state.responseState = RESPONSE_COLUMN;
        // fall through
        case RESPONSE_COLUMN:
            if (metadata != null) {
                final int columnCount = metadata.getColumnCount();
                for (; state.columnIndex < columnCount; state.columnIndex++) {
                    socket.bookmark();
                    socket.put('|');
                    pad(socket, TO_STRING_COL1_PAD, state.columnIndex);
                    pad(socket, TO_STRING_COL2_PAD, metadata.getColumnName(state.columnIndex));
                    if (!metadata.isColumnIndexed(state.columnIndex)) {
                        pad(socket, TO_STRING_COL3_PAD + TO_STRING_COL4_PAD + 3, ColumnType.nameOf(metadata.getColumnType(state.columnIndex)));
                    } else {
                        StringSink sink = Misc.getThreadLocalBuilder();
                        sink.put("(idx/").put(metadata.getIndexValueBlockCapacity(state.columnIndex)).put(") ");
                        sink.put(ColumnType.nameOf(metadata.getColumnType(state.columnIndex)));
                        pad(socket, TO_STRING_COL3_PAD + TO_STRING_COL4_PAD + 3, sink);
                    }
                    pad(socket, TO_STRING_COL5_PAD, errors.getQuick(state.columnIndex));
                    socket.put(Misc.EOL);
                }
            }
            state.responseState = RESPONSE_SUFFIX;
        // fall through
        case RESPONSE_SUFFIX:
            socket.bookmark();
            sep(socket);
            state.responseState = RESPONSE_COMPLETE;
            socket.sendChunk(true);
            break;
        case RESPONSE_DONE:
            state.responseState = RESPONSE_COMPLETE;
            socket.done();
            break;
        default:
            break;
    }
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) StringSink(io.questdb.std.str.StringSink)

Aggregations

RecordMetadata (io.questdb.cairo.sql.RecordMetadata)10 Record (io.questdb.cairo.sql.Record)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 Row (io.questdb.cairo.TableWriter.Row)1 Function (io.questdb.cairo.sql.Function)1 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)1 MemoryMA (io.questdb.cairo.vm.api.MemoryMA)1 HttpChunkedResponseSocket (io.questdb.cutlass.http.HttpChunkedResponseSocket)1 HttpRequestHeader (io.questdb.cutlass.http.HttpRequestHeader)1 Utf8Exception (io.questdb.cutlass.text.Utf8Exception)1 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)1 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)1 BinaryFunction (io.questdb.griffin.engine.functions.BinaryFunction)1 IntFunction (io.questdb.griffin.engine.functions.IntFunction)1 BytecodeAssembler (io.questdb.std.BytecodeAssembler)1 IntList (io.questdb.std.IntList)1 Rnd (io.questdb.std.Rnd)1 DirectByteCharSequence (io.questdb.std.str.DirectByteCharSequence)1 Path (io.questdb.std.str.Path)1