Search in sources :

Example 1 with ColumnDefinition

use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project vertx-sql-client by eclipse-vertx.

the class CommandCodec method decodeColumnDefinitionPacketPayload.

ColumnDefinition decodeColumnDefinitionPacketPayload(ByteBuf payload) {
    String catalog = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
    String schema = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
    String table = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
    String orgTable = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
    String name = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
    String orgName = BufferUtils.readLengthEncodedString(payload, StandardCharsets.UTF_8);
    long lengthOfFixedLengthFields = BufferUtils.readLengthEncodedInteger(payload);
    int characterSet = payload.readUnsignedShortLE();
    long columnLength = payload.readUnsignedIntLE();
    DataType type = DataType.valueOf(payload.readUnsignedByte());
    int flags = payload.readUnsignedShortLE();
    byte decimals = payload.readByte();
    return new ColumnDefinition(catalog, schema, table, orgTable, name, orgName, characterSet, columnLength, type, flags, decimals);
}
Also used : DataType(io.vertx.mysqlclient.impl.datatype.DataType) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Example 2 with ColumnDefinition

use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project vertx-sql-client by eclipse-vertx.

the class QueryCommandBaseCodec method handleResultsetColumnDefinitions.

protected void handleResultsetColumnDefinitions(ByteBuf payload) {
    ColumnDefinition def = decodeColumnDefinitionPacketPayload(payload);
    columnDefinitions[currentColumn++] = def;
    if (currentColumn == columnDefinitions.length) {
        // all column definitions have been decoded, switch to column definitions decoding completed state
        if (isDeprecatingEofFlagEnabled()) {
            // we enabled the DEPRECATED_EOF flag and don't need to accept an EOF_Packet
            handleResultsetColumnDefinitionsDecodingCompleted();
        } else {
            // we need to decode an EOF_Packet before handling rows, to be compatible with MySQL version below 5.7.5
            commandHandlerState = CommandHandlerState.COLUMN_DEFINITIONS_DECODING_COMPLETED;
        }
    }
}
Also used : ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Example 3 with ColumnDefinition

use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project vertx-sql-client by eclipse-vertx.

the class RowResultDecoder method decodeRow.

@Override
protected Row decodeRow(int len, ByteBuf in) {
    Row row = new MySQLRowImpl(rowDesc);
    if (rowDesc.dataFormat() == DataFormat.BINARY) {
        // BINARY row decoding
        // 0x00 packet header
        // null_bitmap
        int nullBitmapLength = (len + 7 + 2) >> 3;
        int nullBitmapIdx = 1 + in.readerIndex();
        in.skipBytes(1 + nullBitmapLength);
        // values
        for (int c = 0; c < len; c++) {
            int val = c + 2;
            int bytePos = val >> 3;
            int bitPos = val & 7;
            byte mask = (byte) (1 << bitPos);
            byte nullByte = (byte) (in.getByte(nullBitmapIdx + bytePos) & mask);
            Object decoded = null;
            if (nullByte == 0) {
                // non-null
                ColumnDefinition columnDef = rowDesc.columnDefinitions()[c];
                DataType dataType = columnDef.type();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                int columnDefinitionFlags = columnDef.flags();
                decoded = DataTypeCodec.decodeBinary(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    } else {
        // TEXT row decoding
        for (int c = 0; c < len; c++) {
            Object decoded = null;
            if (in.getUnsignedByte(in.readerIndex()) == NULL) {
                in.skipBytes(1);
            } else {
                DataType dataType = rowDesc.columnDefinitions()[c].type();
                int columnDefinitionFlags = rowDesc.columnDefinitions()[c].flags();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                decoded = DataTypeCodec.decodeText(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    }
    return row;
}
Also used : MySQLRowImpl(io.vertx.mysqlclient.impl.MySQLRowImpl) DataType(io.vertx.mysqlclient.impl.datatype.DataType) Row(io.vertx.sqlclient.Row) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Example 4 with ColumnDefinition

use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project Mycat2 by MyCATApache.

the class VertxMycatTextCollector method onColumnDef.

@Override
public void onColumnDef(MySQLPacket mySQLPacket, int startPos, int endPos) {
    ColumnDefPacketImpl packet = new ColumnDefPacketImpl();
    packet.read(mySQLPacket, startPos, endPos);
    String catalog = new String(packet.getColumnCatalog());
    String schema = new String(packet.getColumnSchema());
    String table = new String(packet.getColumnTable());
    String orgTable = new String(packet.getColumnOrgTable());
    String name = new String(packet.getColumnName());
    String orgName = new String(packet.getColumnOrgName());
    int characterSet = packet.getColumnCharsetSet();
    long columnLength = packet.getColumnLength();
    DataType type = DataType.valueOf(packet.getColumnType());
    int flags = packet.getColumnFlags();
    byte decimals = packet.getColumnDecimals();
    ColumnDefinition columnDefinition = new ColumnDefinition(catalog, schema, table, orgTable, name, orgName, characterSet, columnLength, type, flags, decimals);
    this.currentColumnDefList[this.columnCount++] = columnDefinition;
}
Also used : DataType(io.vertx.mysqlclient.impl.datatype.DataType) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Example 5 with ColumnDefinition

use of io.vertx.mysqlclient.impl.protocol.ColumnDefinition in project Mycat2 by MyCATApache.

the class MycatVertxRowResultDecoder method decodeRow.

@Override
protected Row decodeRow(int len, ByteBuf in) {
    Row row = new MySQLRowImpl(rowDesc);
    if (rowDesc.dataFormat() == DataFormat.BINARY) {
        // BINARY row decoding
        // 0x00 packet header
        // null_bitmap
        int nullBitmapLength = (len + 7 + 2) >> 3;
        int nullBitmapIdx = 1 + in.readerIndex();
        in.skipBytes(1 + nullBitmapLength);
        // values
        for (int c = 0; c < len; c++) {
            int val = c + 2;
            int bytePos = val >> 3;
            int bitPos = val & 7;
            byte mask = (byte) (1 << bitPos);
            byte nullByte = (byte) (in.getByte(nullBitmapIdx + bytePos) & mask);
            Object decoded = null;
            if (nullByte == 0) {
                // non-null
                ColumnDefinition columnDef = rowDesc.columnDefinitions()[c];
                DataType dataType = columnDef.type();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                int columnDefinitionFlags = columnDef.flags();
                decoded = DataTypeCodec.decodeBinary(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    } else {
        // TEXT row decoding
        for (int c = 0; c < len; c++) {
            Object decoded = null;
            if (in.getUnsignedByte(in.readerIndex()) == NULL) {
                in.skipBytes(1);
            } else {
                DataType dataType = rowDesc.columnDefinitions()[c].type();
                int columnDefinitionFlags = rowDesc.columnDefinitions()[c].flags();
                int collationId = rowDesc.columnDefinitions()[c].characterSet();
                decoded = DataTypeCodec.decodeText(dataType, collationId, columnDefinitionFlags, in);
            }
            row.addValue(decoded);
        }
    }
    return row;
}
Also used : MySQLRowImpl(io.vertx.mysqlclient.impl.MySQLRowImpl) DataType(io.vertx.mysqlclient.impl.datatype.DataType) Row(io.vertx.sqlclient.Row) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition)

Aggregations

ColumnDefinition (io.vertx.mysqlclient.impl.protocol.ColumnDefinition)13 DataType (io.vertx.mysqlclient.impl.datatype.DataType)7 ColumnDefPacketImpl (io.mycat.beans.mysql.packet.ColumnDefPacketImpl)4 ImmutableList (com.google.common.collect.ImmutableList)3 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)3 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)3 ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)3 ColumnDescriptor (io.vertx.sqlclient.desc.ColumnDescriptor)3 MycatMySQLRowMetaData (io.mycat.beans.mycat.MycatMySQLRowMetaData)2 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)2 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)2 MySQLRowImpl (io.vertx.mysqlclient.impl.MySQLRowImpl)2 io.vertx.sqlclient (io.vertx.sqlclient)2 Row (io.vertx.sqlclient.Row)2 Duration (java.time.Duration)2 Function (java.util.function.Function)2 JdbcFieldInfo (org.apache.arrow.adapter.jdbc.JdbcFieldInfo)2 JdbcToArrowConfig (org.apache.arrow.adapter.jdbc.JdbcToArrowConfig)2 JdbcToArrowConfigBuilder (org.apache.arrow.adapter.jdbc.JdbcToArrowConfigBuilder)2 org.apache.arrow.vector (org.apache.arrow.vector)2