Search in sources :

Example 1 with Field

use of com.mysql.cj.result.Field in project Mycat2 by MyCATApache.

the class NewMycatConnectionImpl method getJdbcRowMetaData.

@NotNull
private MycatRowMetaData getJdbcRowMetaData(ResultSetMetaData jdbcMetaData) throws SQLException {
    MycatRowMetaData mycatRowMetaData;
    if (isMySQLDriver || "com.mysql.cj.jdbc.result.ResultSetMetaData".equals(jdbcMetaData.getClass().getCanonicalName())) {
        isMySQLDriver = true;
        com.mysql.cj.jdbc.result.ResultSetMetaData mysqlJdbcMetaData = (com.mysql.cj.jdbc.result.ResultSetMetaData) jdbcMetaData;
        int columnCount = mysqlJdbcMetaData.getColumnCount();
        Field[] fields = mysqlJdbcMetaData.getFields();
        List<ColumnDefPacket> columnDefPackets = new ArrayList<>(columnCount);
        for (int i = 0; i < columnCount; i++) {
            ColumnDefPacketImpl columnDefPacket = new ColumnDefPacketImpl();
            Field field = fields[i];
            columnDefPacket.setColumnSchema(ColumnDefPacketImpl.getBytes(field.getDatabaseName()));
            columnDefPacket.setColumnTable(ColumnDefPacketImpl.getBytes(field.getTableName()));
            columnDefPacket.setColumnOrgTable(ColumnDefPacketImpl.getBytes(field.getOriginalTableName()));
            columnDefPacket.setColumnName(ColumnDefPacketImpl.getBytes(field.getName()));
            columnDefPacket.setColumnOrgName(ColumnDefPacketImpl.getBytes(field.getOriginalName()));
            columnDefPacket.setColumnCharsetSet((field.getCollationIndex()));
            columnDefPacket.setColumnLength((int) field.getLength());
            columnDefPacket.setColumnType((int) field.getMysqlTypeId());
            columnDefPacket.setColumnFlags((int) field.getFlags());
            columnDefPacket.setColumnDecimals((byte) field.getDecimals());
            columnDefPackets.add(columnDefPacket);
        }
        mycatRowMetaData = new MycatMySQLRowMetaData(columnDefPackets);
    } else {
        mycatRowMetaData = new CopyMycatRowMetaData(new JdbcRowMetaData(jdbcMetaData));
    }
    return mycatRowMetaData;
}
Also used : ArrayList(java.util.ArrayList) ColumnDefPacketImpl(io.mycat.beans.mysql.packet.ColumnDefPacketImpl) Field(com.mysql.cj.result.Field) ColumnDefPacket(io.mycat.beans.mysql.packet.ColumnDefPacket) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Field

use of com.mysql.cj.result.Field in project Mycat2 by MyCATApache.

the class NewMycatConnectionImpl method getFieldVectors.

@NotNull
private FieldVector[] getFieldVectors(MycatField[] mycatFields, BufferAllocator allocator) {
    FieldVector[] fieldVectors = new FieldVector[mycatFields.length];
    int i = 0;
    for (MycatField mycatField : mycatFields) {
        String name = mycatField.getName();
        boolean nullable = mycatField.isNullable();
        ArrowType arrowType = mycatField.getMycatDataType().getArrowType();
        FieldType fieldType = new FieldType(nullable, arrowType, null);
        org.apache.arrow.vector.types.pojo.Field field = new org.apache.arrow.vector.types.pojo.Field(name, fieldType, Collections.emptyList());
        FieldVector fieldVector = mycatField.getMycatDataType().createFieldVector(field, allocator);
        fieldVectors[i] = fieldVector;
        i++;
    }
    return fieldVectors;
}
Also used : ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) FieldVector(org.apache.arrow.vector.FieldVector) FieldType(org.apache.arrow.vector.types.pojo.FieldType) Field(com.mysql.cj.result.Field) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Field (com.mysql.cj.result.Field)2 NotNull (org.jetbrains.annotations.NotNull)2 ColumnDefPacket (io.mycat.beans.mysql.packet.ColumnDefPacket)1 ColumnDefPacketImpl (io.mycat.beans.mysql.packet.ColumnDefPacketImpl)1 ArrayList (java.util.ArrayList)1 FieldVector (org.apache.arrow.vector.FieldVector)1 ArrowType (org.apache.arrow.vector.types.pojo.ArrowType)1 FieldType (org.apache.arrow.vector.types.pojo.FieldType)1