Search in sources :

Example 1 with SimpleColumnInfo

use of io.mycat.SimpleColumnInfo in project Mycat2 by MyCATApache.

the class ShardingIndexTable method hasFactColumn.

public boolean hasFactColumn(int i) {
    ShardingTable factTable = getFactTable();
    SimpleColumnInfo column = this.getColumnByName(factTable.getColumns().get(i).getColumnName());
    return column != null;
}
Also used : SimpleColumnInfo(io.mycat.SimpleColumnInfo)

Example 2 with SimpleColumnInfo

use of io.mycat.SimpleColumnInfo in project Mycat2 by MyCATApache.

the class Statistics method getUniqueKeys.

public static List<ImmutableBitSet> getUniqueKeys(List<SimpleColumnInfo> columns) {
    List<ImmutableBitSet> immutableBitSets = Collections.emptyList();
    ImmutableList.Builder<ImmutableBitSet> indexes = ImmutableList.builder();
    try {
        int index = 0;
        for (SimpleColumnInfo column : columns) {
            if (column.isUnique()) {
                indexes.add(ImmutableBitSet.of(index));
            }
            index++;
        }
        immutableBitSets = indexes.build();
    } catch (Throwable e) {
        LOGGER.error("", e);
    }
    return immutableBitSets;
}
Also used : SimpleColumnInfo(io.mycat.SimpleColumnInfo) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) ImmutableList(com.google.common.collect.ImmutableList) RelReferentialConstraint(org.apache.calcite.rel.RelReferentialConstraint)

Example 3 with SimpleColumnInfo

use of io.mycat.SimpleColumnInfo in project Mycat2 by MyCATApache.

the class VisualTableHandler method createByMySQL.

public static VisualTableHandler createByMySQL(String sql, Supplier<Observable<Object[]>> rowsProvider) {
    SQLStatement sqlStatement1 = SQLUtils.parseSingleMysqlStatement(sql);
    MySqlCreateTableStatement sqlStatement = (MySqlCreateTableStatement) sqlStatement1;
    String schema = SQLUtils.normalize(sqlStatement.getSchema()).toLowerCase();
    String tableName = SQLUtils.normalize(sqlStatement.getTableName()).toLowerCase();
    MycatRowMetaData mycatRowMetaData = SQL2ResultSetUtil.getMycatRowMetaData((MySqlCreateTableStatement) sqlStatement);
    List<SimpleColumnInfo> columnInfo = CalciteConvertors.getColumnInfo(Objects.requireNonNull(mycatRowMetaData));
    LogicTable logicTable = new LogicTable(LogicTableType.NORMAL, schema, tableName, columnInfo, Collections.emptyMap(), sql);
    return new VisualTableHandler(logicTable) {

        @Override
        public Observable<Object[]> scanAll() {
            return rowsProvider.get();
        }
    };
}
Also used : SimpleColumnInfo(io.mycat.SimpleColumnInfo) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) LogicTable(io.mycat.calcite.table.LogicTable) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData)

Example 4 with SimpleColumnInfo

use of io.mycat.SimpleColumnInfo in project Mycat2 by MyCATApache.

the class CalciteConvertors method getRelDataType.

public static RelDataType getRelDataType(final List<SimpleColumnInfo> columnInfos, final RelDataTypeFactory factory) {
    final RelDataTypeFactory.Builder builder = new RelDataTypeFactory.Builder(factory);
    for (SimpleColumnInfo columnInfo : columnInfos) {
        final JDBCType columnType = columnInfo.getJdbcType();
        final RelDataType type;
        if (columnType == JDBCType.VARCHAR) {
            type = factory.createTypeWithCharsetAndCollation(factory.createSqlType(SqlTypeName.VARCHAR), StandardCharsets.UTF_8, SqlCollation.IMPLICIT);
        } else if (columnType == JDBCType.LONGVARBINARY) {
            type = factory.createSqlType(SqlTypeName.VARBINARY);
        } else {
            SqlTypeName sqlTypeName = SqlTypeName.getNameForJdbcType(columnType.getVendorTypeNumber());
            if (sqlTypeName == null) {
                sqlTypeName = SqlTypeName.VARCHAR;
            }
            type = factory.createSqlType(sqlTypeName);
        }
        builder.add(columnInfo.getColumnName(), factory.createTypeWithNullability(type, columnInfo.isNullable()));
    }
    return builder.build();
}
Also used : SimpleColumnInfo(io.mycat.SimpleColumnInfo) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName)

Example 5 with SimpleColumnInfo

use of io.mycat.SimpleColumnInfo in project Mycat2 by MyCATApache.

the class CalciteConvertors method relDataType.

public static RelProtoDataType relDataType(List<SimpleColumnInfo> infos) {
    Objects.requireNonNull(infos);
    final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
    final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder();
    for (SimpleColumnInfo info : infos) {
        RelDataType relDataType = sqlType(typeFactory, info.getJdbcType().ordinal(), info.getPrecision(), info.getScale(), info.getJdbcType().getName());
        fieldInfo.add(info.getColumnName(), relDataType).nullable(info.isNullable());
    }
    return RelDataTypeImpl.proto(fieldInfo.build());
}
Also used : SqlTypeFactoryImpl(org.apache.calcite.sql.type.SqlTypeFactoryImpl) SimpleColumnInfo(io.mycat.SimpleColumnInfo)

Aggregations

SimpleColumnInfo (io.mycat.SimpleColumnInfo)11 SQLUtils (com.alibaba.druid.sql.SQLUtils)3 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 SQLObject (com.alibaba.druid.sql.ast.SQLObject)2 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)2 com.alibaba.druid.sql.ast.statement (com.alibaba.druid.sql.ast.statement)2 MySqlDeleteStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement)2 MySqlSelectQueryBlock (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlSelectQueryBlock)2 MySqlUpdateStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement)2 ImmutableList (com.google.common.collect.ImmutableList)2 MycatException (io.mycat.MycatException)2 MycatPreparedStatementUtil (io.mycat.calcite.executor.MycatPreparedStatementUtil)2 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 AllArgsConstructor (lombok.AllArgsConstructor)2 Getter (lombok.Getter)2