Search in sources :

Example 1 with MycatMySQLRowMetaData

use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateColumnDefPayload.

public static final byte[] generateColumnDefPayload(MycatRowMetaData metaData, int columnIndex) {
    try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
        ColumnDefPacketImpl columnDefPacket;
        if (metaData instanceof MycatMySQLRowMetaData) {
            columnDefPacket = (ColumnDefPacketImpl) ((MycatMySQLRowMetaData) metaData).getColumnDefPackets().get(columnIndex);
        } else {
            columnDefPacket = new ColumnDefPacketImpl(metaData, columnIndex);
        }
        columnDefPacket.writePayload(writer);
        return writer.toByteArray();
    }
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData)

Example 2 with MycatMySQLRowMetaData

use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.

the class NewVertxConnectionImpl method toColumnMetaData.

public static MycatRowMetaData toColumnMetaData(List<ColumnDefinition> event) {
    boolean isMysql = event.get(0) instanceof ColumnDefinition;
    if (isMysql) {
        List<ColumnDefinition> columnDefinitions = event;
        List<ColumnDefPacket> columnDefPackets = new ArrayList<>(event.size());
        for (ColumnDefinition columnDefinition : columnDefinitions) {
            final String catalog = columnDefinition.catalog();
            final String schema = columnDefinition.schema();
            final String table = columnDefinition.table();
            final String orgTable = columnDefinition.orgTable();
            final String name = columnDefinition.name();
            final String orgName = columnDefinition.orgName();
            final int characterSet = columnDefinition.characterSet();
            final long columnLength = columnDefinition.columnLength();
            final DataType type = columnDefinition.type();
            final int flags = columnDefinition.flags();
            byte decimals = columnDefinition.decimals();
            if (decimals == 31) {
                decimals = 0;
            }
            ColumnDefPacketImpl mySQLFieldInfo = new ColumnDefPacketImpl();
            mySQLFieldInfo.setColumnCatalog(catalog.getBytes());
            mySQLFieldInfo.setColumnSchema(schema.getBytes());
            mySQLFieldInfo.setColumnTable(table.getBytes());
            mySQLFieldInfo.setColumnOrgTable(orgTable.getBytes());
            mySQLFieldInfo.setColumnName(name.getBytes());
            mySQLFieldInfo.setColumnOrgName(orgName.getBytes());
            mySQLFieldInfo.setColumnCharsetSet(characterSet);
            mySQLFieldInfo.setColumnLength((int) columnLength);
            mySQLFieldInfo.setColumnType(type.id);
            mySQLFieldInfo.setColumnFlags(flags);
            mySQLFieldInfo.setColumnDecimals(decimals);
            columnDefPackets.add(mySQLFieldInfo);
        }
        return new MycatMySQLRowMetaData(columnDefPackets);
    } else {
        ResultSetBuilder resultSetBuilder = ResultSetBuilder.create();
        for (ColumnDefinition columnDescriptor : event) {
            resultSetBuilder.addColumnInfo(columnDescriptor.name(), columnDescriptor.jdbcType());
        }
        RowBaseIterator build = resultSetBuilder.build();
        return build.getMetaData();
    }
}
Also used : ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData) ColumnDefinition(io.vertx.mysqlclient.impl.protocol.ColumnDefinition) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) ColumnDefPacket(io.mycat.beans.mysql.packet.ColumnDefPacket) DataType(io.vertx.mysqlclient.impl.datatype.DataType) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) RowBaseIterator(io.mycat.api.collector.RowBaseIterator)

Example 3 with MycatMySQLRowMetaData

use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.

the class MySQLPacketUtil method generateAllColumnDefPayload.

// public static final byte[] generateColumnDefPayload(ResultSetMetaData metaData, int columnIndex) {
// try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
// ColumnDefPacketImpl columnDefPacket = new ColumnDefPacketImpl(metaData, columnIndex);
// columnDefPacket.writePayload(writer);
// return writer.toByteArray();
// }
// }
public static final Iterable<byte[]> generateAllColumnDefPayload(MycatRowMetaData metaData) {
    List<byte[]> list = new ArrayList<>(metaData.getColumnCount());
    final int count = metaData.getColumnCount();
    if (metaData instanceof MycatMySQLRowMetaData) {
        List<ColumnDefPacketImpl> columnDefPackets = (List) ((MycatMySQLRowMetaData) metaData).getColumnDefPackets();
        for (int index = 0; index < count; index++) {
            try (MySQLPayloadWriter writer = new MySQLPayloadWriter(128)) {
                columnDefPackets.get(index).writePayload(writer);
                list.add(writer.toByteArray());
            }
        }
    } else {
        for (int index = 0; index < count; index++) {
            list.add(MySQLPacketUtil.generateColumnDefPayload(metaData, index));
        }
    }
    return list;
}
Also used : MySQLPayloadWriter(io.mycat.beans.mysql.MySQLPayloadWriter) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with MycatMySQLRowMetaData

use of io.mycat.beans.mycat.MycatMySQLRowMetaData in project Mycat2 by MyCATApache.

the class VertxMycatConnectionPool method query.

@Override
public synchronized Future<RowSet> query(String sql, List<Object> params) {
    String psql = deparameterize(sql, params);
    Future<RowSet> rowSetFuture = queryCloseFuture.flatMap(unused -> {
        Promise<RowSet> promise = Promise.promise();
        ObjectArrayDecoder objectArrayDecoder = new ObjectArrayDecoder();
        Observable<Object[]> query = connection.query(psql, objectArrayDecoder);
        onSend();
        Single<RowSet> map = query.subscribeOn(Schedulers.computation()).toList().map(objects -> {
            MycatMySQLRowMetaData mycatMySQLRowMetaData = new MycatMySQLRowMetaData(Arrays.asList(objectArrayDecoder.getColumnDefPackets()));
            return new RowSet(mycatMySQLRowMetaData, objects);
        });
        map = map.doOnSuccess(objects -> promise.tryComplete(objects));
        map = map.doOnError(objects -> promise.tryFail(objects));
        map = map.doOnTerminate(() -> onRev());
        map.subscribe();
        return promise.future();
    });
    this.queryCloseFuture = rowSetFuture.mapEmpty();
    return rowSetFuture;
}
Also used : Single(io.reactivex.rxjava3.core.Single) Arrays(java.util.Arrays) RowSet(io.mycat.newquery.RowSet) PreparedStatement(io.mycat.PreparedStatement) Function(java.util.function.Function) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) MySqlASTVisitorAdapter(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter) ImmutableList(com.google.common.collect.ImmutableList) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData) Observable(io.reactivex.rxjava3.core.Observable) JdbcDatasourcePoolImpl(io.mycat.commands.JdbcDatasourcePoolImpl) ObjectArrayDecoder(io.mycat.mysqlclient.decoder.ObjectArrayDecoder) AsyncResult(io.vertx.core.AsyncResult) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) BufferAllocator(org.apache.arrow.memory.BufferAllocator) SQLUtils(com.alibaba.druid.sql.SQLUtils) NewMycatConnection(io.mycat.newquery.NewMycatConnection) ColumnDefPacket(io.mycat.beans.mysql.packet.ColumnDefPacket) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) SQLReplaceable(com.alibaba.druid.sql.ast.SQLReplaceable) Promise(io.vertx.core.Promise) MysqlCollector(io.mycat.newquery.MysqlCollector) SqlResult(io.mycat.newquery.SqlResult) Future(io.vertx.core.Future) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) Handler(io.vertx.core.Handler) MycatMySQLRowMetaData(io.mycat.beans.mycat.MycatMySQLRowMetaData) RowSet(io.mycat.newquery.RowSet) ObjectArrayDecoder(io.mycat.mysqlclient.decoder.ObjectArrayDecoder)

Aggregations

MycatMySQLRowMetaData (io.mycat.beans.mycat.MycatMySQLRowMetaData)4 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)2 MySQLPayloadWriter (io.mycat.beans.mysql.MySQLPayloadWriter)2 ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)2 List (java.util.List)2 SQLUtils (com.alibaba.druid.sql.SQLUtils)1 SQLReplaceable (com.alibaba.druid.sql.ast.SQLReplaceable)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1 MySqlASTVisitorAdapter (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter)1 ImmutableList (com.google.common.collect.ImmutableList)1 PreparedStatement (io.mycat.PreparedStatement)1 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)1 ColumnDefPacketImpl (io.mycat.beans.mysql.packet.ColumnDefPacketImpl)1 JdbcDatasourcePoolImpl (io.mycat.commands.JdbcDatasourcePoolImpl)1 ObjectArrayDecoder (io.mycat.mysqlclient.decoder.ObjectArrayDecoder)1 MysqlCollector (io.mycat.newquery.MysqlCollector)1 NewMycatConnection (io.mycat.newquery.NewMycatConnection)1 RowSet (io.mycat.newquery.RowSet)1