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;
}
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;
}
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();
}
};
}
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();
}
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());
}
Aggregations