Search in sources :

Example 1 with MycatField

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

the class LocalTableScan method getMycatRelDataType.

@Override
public MycatRelDataType getMycatRelDataType() {
    MycatLogicTable mycatTable = getTable().unwrap(MycatLogicTable.class);
    TableHandler tableTable = mycatTable.getTable();
    List<MycatField> mycatFields = tableTable.getColumns().stream().map(c -> c.toMycatField()).collect(Collectors.toList());
    return MycatRelDataType.of(mycatFields);
}
Also used : RelInput(org.apache.calcite.rel.RelInput) TableScan(org.apache.calcite.rel.core.TableScan) TableHandler(io.mycat.TableHandler) RelFactories(org.apache.calcite.rel.core.RelFactories) MycatField(io.mycat.beans.mycat.MycatField) Collectors(java.util.stream.Collectors) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) RelWriter(org.apache.calcite.rel.RelWriter) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RelMetadataQuery(org.apache.calcite.rel.metadata.RelMetadataQuery) RelHint(org.apache.calcite.rel.hint.RelHint) Map(java.util.Map) AbstractMycatTable(io.mycat.calcite.table.AbstractMycatTable) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) org.apache.calcite.plan(org.apache.calcite.plan) TableHandler(io.mycat.TableHandler) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) MycatField(io.mycat.beans.mycat.MycatField)

Example 2 with MycatField

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

the class FactoryUtil method toArrowSchema.

public static Schema toArrowSchema(MycatRelDataType mycatRelDataTypeByCalcite) {
    List<MycatField> fieldList = mycatRelDataTypeByCalcite.getFieldList();
    int columnCount = fieldList.size();
    ImmutableList.Builder<org.apache.arrow.vector.types.pojo.Field> builder = ImmutableList.builder();
    for (int i = 0; i < columnCount; i++) {
        MycatField mycatField = fieldList.get(i);
        String columnName = mycatField.getName();
        MycatDataType columnType = mycatField.getMycatDataType();
        boolean nullable = mycatField.isNullable();
        InnerType innerType;
        switch(columnType) {
            case BOOLEAN:
                innerType = InnerType.BOOLEAN_TYPE;
                break;
            case BIT:
            case UNSIGNED_LONG:
                innerType = InnerType.UINT64_TYPE;
                break;
            case TINYINT:
                innerType = InnerType.INT8_TYPE;
                break;
            case UNSIGNED_TINYINT:
                innerType = InnerType.UINT8_TYPE;
                break;
            case SHORT:
                innerType = InnerType.INT16_TYPE;
                break;
            case UNSIGNED_SHORT:
            case YEAR:
                innerType = InnerType.UINT16_TYPE;
                break;
            case INT:
                innerType = InnerType.INT32_TYPE;
                break;
            case UNSIGNED_INT:
                innerType = InnerType.UINT32_TYPE;
                break;
            case LONG:
                innerType = InnerType.INT64_TYPE;
                break;
            case DOUBLE:
                innerType = InnerType.DOUBLE_TYPE;
                break;
            case DECIMAL:
                innerType = InnerType.DECIMAL_TYPE;
                break;
            case DATE:
                innerType = InnerType.DATE_TYPE;
                break;
            case DATETIME:
                innerType = InnerType.DATETIME_MILLI_TYPE;
                break;
            case TIME:
                innerType = InnerType.TIME_MILLI_TYPE;
                break;
            case CHAR:
            case VARCHAR:
                innerType = InnerType.STRING_TYPE;
                break;
            case BINARY:
                innerType = InnerType.BINARY_TYPE;
                break;
            case FLOAT:
                innerType = InnerType.FLOAT_TYPE;
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + columnType);
        }
        org.apache.arrow.vector.types.pojo.Field field = FieldBuilder.of(columnName, innerType.getArrowType(), nullable).toArrow();
        builder.add(field);
    }
    return new Schema(builder.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Schema(org.apache.arrow.vector.types.pojo.Schema) MycatDataType(io.mycat.beans.mycat.MycatDataType) InnerType(io.ordinate.engine.schema.InnerType) MycatField(io.mycat.beans.mycat.MycatField) MycatField(io.mycat.beans.mycat.MycatField)

Example 3 with MycatField

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

the class MycatRelDataTypeUtil method getMycatRelDataType.

public static MycatRelDataType getMycatRelDataType(RelDataType relDataType) {
    List<RelDataTypeField> fieldList = relDataType.getFieldList();
    ImmutableList.Builder<MycatField> builder = ImmutableList.builder();
    for (RelDataTypeField relDataTypeField : fieldList) {
        SqlTypeName sqlTypeName = relDataTypeField.getType().getSqlTypeName();
        int jdbcOrdinal = sqlTypeName.getJdbcOrdinal();
        MycatDataType mycatDataType = MycatDataType.fromJdbc(JDBCType.valueOf(jdbcOrdinal), true);
        MycatField mycatField = MycatField.of(relDataTypeField.getName(), mycatDataType, relDataTypeField.getType().isNullable());
        builder.add(mycatField);
    }
    return MycatRelDataType.of(builder.build());
}
Also used : RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) ImmutableList(com.google.common.collect.ImmutableList) MycatDataType(io.mycat.beans.mycat.MycatDataType) MycatField(io.mycat.beans.mycat.MycatField)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 MycatField (io.mycat.beans.mycat.MycatField)3 MycatDataType (io.mycat.beans.mycat.MycatDataType)2 TableHandler (io.mycat.TableHandler)1 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)1 AbstractMycatTable (io.mycat.calcite.table.AbstractMycatTable)1 MycatLogicTable (io.mycat.calcite.table.MycatLogicTable)1 InnerType (io.ordinate.engine.schema.InnerType)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Schema (org.apache.arrow.vector.types.pojo.Schema)1 org.apache.calcite.plan (org.apache.calcite.plan)1 RelInput (org.apache.calcite.rel.RelInput)1 RelWriter (org.apache.calcite.rel.RelWriter)1 RelFactories (org.apache.calcite.rel.core.RelFactories)1 TableScan (org.apache.calcite.rel.core.TableScan)1 RelHint (org.apache.calcite.rel.hint.RelHint)1 RelMetadataQuery (org.apache.calcite.rel.metadata.RelMetadataQuery)1 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)1