Search in sources :

Example 1 with FieldType

use of io.mycat.hbt.ast.base.FieldType in project Mycat2 by MyCATApache.

the class FieldTypes method getFieldTypes.

@SneakyThrows
public static List<FieldType> getFieldTypes(MycatRowMetaData metaData) {
    int columnCount = metaData.getColumnCount();
    ArrayList<FieldType> fieldTypes = new ArrayList<>(columnCount);
    for (int i = 0; i < columnCount; i++) {
        final String columnName = metaData.getColumnName(i);
        SqlTypeName sqlTypeName = Objects.requireNonNull(HBTCalciteSupport.INSTANCE.getSqlTypeByJdbcValue(metaData.getColumnType(i)), "type is not existed,类型不存在");
        final String columnType = sqlTypeName.getName();
        final boolean nullable = metaData.isNullable(i);
        final Integer precision = metaData.getPrecision(i);
        final Integer scale = metaData.getScale(i);
        fieldTypes.add(new FieldType(columnName, columnType, nullable, precision, scale));
    }
    return fieldTypes;
}
Also used : SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) ArrayList(java.util.ArrayList) FieldType(io.mycat.hbt.ast.base.FieldType) SneakyThrows(lombok.SneakyThrows)

Aggregations

FieldType (io.mycat.hbt.ast.base.FieldType)1 ArrayList (java.util.ArrayList)1 SneakyThrows (lombok.SneakyThrows)1 SqlTypeName (org.apache.calcite.sql.type.SqlTypeName)1