Search in sources :

Example 1 with NameMap

use of io.mycat.util.NameMap in project Mycat2 by MyCATApache.

the class PrototypeHandlerImpl method showTables.

@Override
public List<Object[]> showTables(SQLShowTablesStatement statement) {
    String schemaName = SQLUtils.normalize(statement.getDatabase().getSimpleName());
    MetadataManager metadataManager = MetaClusterCurrent.wrapper(MetadataManager.class);
    NameMap<SchemaHandler> schemaMap = metadataManager.getSchemaMap();
    SchemaHandler schemaHandler = schemaMap.get(schemaName);
    if (schemaHandler == null)
        return Collections.emptyList();
    Collection<String> strings = schemaHandler.logicTables().values().stream().map(i -> i.getTableName()).collect(Collectors.toList());
    ;
    SQLExpr like = statement.getLike();
    if (like == null) {
        NameMap<TableHandler> tables = schemaHandler.logicTables();
        strings = tables.keySet();
    } else if (like instanceof SQLTextLiteralExpr) {
        PatternMatcher matcher = PatternMatcher.createMysqlPattern(((SQLTextLiteralExpr) like).getText(), false);
        strings = strings.stream().filter(i -> matcher.match(i)).collect(Collectors.toList());
    }
    if (statement.isFull()) {
        return strings.stream().sorted().map(i -> new Object[] { i, "BASE TABLE" }).collect(Collectors.toList());
    } else {
        return strings.stream().sorted().map(i -> new Object[] { i }).collect(Collectors.toList());
    }
}
Also used : SchemaHandler(io.mycat.calcite.table.SchemaHandler) MetadataManager(io.mycat.MetadataManager) java.util(java.util) Connection(java.sql.Connection) TableHandler(io.mycat.TableHandler) MetaClusterCurrent(io.mycat.MetaClusterCurrent) LoggerFactory(org.slf4j.LoggerFactory) JdbcDataSource(io.mycat.datasource.jdbc.datasource.JdbcDataSource) SQLLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLLiteralExpr) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) Supplier(java.util.function.Supplier) SQLPropertyExpr(com.alibaba.druid.sql.ast.expr.SQLPropertyExpr) PrepareExecutor(io.mycat.calcite.PrepareExecutor) SchemaHandler(io.mycat.calcite.table.SchemaHandler) ResultSet(java.sql.ResultSet) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) DatasourceConfig(io.mycat.config.DatasourceConfig) com.alibaba.druid.sql.dialect.mysql.ast.statement(com.alibaba.druid.sql.dialect.mysql.ast.statement) SQLUtils(com.alibaba.druid.sql.SQLUtils) Logger(org.slf4j.Logger) PatternMatcher(org.apache.doris.common.PatternMatcher) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) Collectors(java.util.stream.Collectors) ReplicaSelectorManager(io.mycat.replica.ReplicaSelectorManager) NameMap(io.mycat.util.NameMap) Statement(java.sql.Statement) SQLTextLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLTextLiteralExpr) MysqlVariableService(io.mycat.MysqlVariableService) com.alibaba.druid.sql.ast.statement(com.alibaba.druid.sql.ast.statement) MetadataManager(io.mycat.MetadataManager) TableHandler(io.mycat.TableHandler) SQLTextLiteralExpr(com.alibaba.druid.sql.ast.expr.SQLTextLiteralExpr) PatternMatcher(org.apache.doris.common.PatternMatcher) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr)

Example 2 with NameMap

use of io.mycat.util.NameMap in project Mycat2 by MyCATApache.

the class PrototypeService method toNameMap.

@NotNull
private NameMap<NameMap<String>> toNameMap(Map<String, Map<String, String>> router) {
    HashMap<String, NameMap> map = new HashMap<>();
    for (Map.Entry<String, Map<String, String>> entry : router.entrySet()) {
        String key = entry.getKey();
        NameMap nameMap = NameMap.immutableCopyOf(entry.getValue());
        map.put(key, nameMap);
    }
    return (NameMap<NameMap<String>>) NameMap.immutableCopyOf(map);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NameMap(io.mycat.util.NameMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NameMap(io.mycat.util.NameMap) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with NameMap

use of io.mycat.util.NameMap in project Mycat2 by MyCATApache.

the class DrdsRunnerHelper method convertRoSchemaPlus.

public static SchemaPlus convertRoSchemaPlus(NameMap<SchemaHandler> schemaHandlers) {
    SchemaPlus plus = CalciteSchema.createRootSchema(false).plus();
    List<MycatSchema> schemas = new ArrayList<>();
    for (Map.Entry<String, SchemaHandler> entry : schemaHandlers.entrySet()) {
        String schemaName = entry.getKey();
        SchemaHandler schemaHandler = entry.getValue();
        Map<String, Table> logicTableMap = new HashMap<>();
        for (TableHandler tableHandler : schemaHandler.logicTables().values()) {
            MycatLogicTable logicTable = new MycatLogicTable(tableHandler);
            logicTableMap.put(logicTable.getTable().getTableName(), logicTable);
        }
        MycatSchema schema = MycatSchema.create(schemaName, logicTableMap);
        plus.add(schemaName, schema);
        schemas.add(schema);
    }
    return plus;
}
Also used : SchemaHandler(io.mycat.calcite.table.SchemaHandler) Table(org.apache.calcite.schema.Table) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) SchemaPlus(org.apache.calcite.schema.SchemaPlus) MycatLogicTable(io.mycat.calcite.table.MycatLogicTable) NameMap(io.mycat.util.NameMap)

Example 4 with NameMap

use of io.mycat.util.NameMap in project Mycat2 by MyCATApache.

the class BinlogUtil method observe.

public static Flowable<ParamSQL> observe(String targetName, List<Partition> partitions) {
    JdbcConnectionManager jdbcConnectionManager = MetaClusterCurrent.wrapper(JdbcConnectionManager.class);
    DatasourceConfig datasourceConfig = jdbcConnectionManager.getConfigAsMap().get(targetName);
    ConnectionUrlParser connectionUrlParser = ConnectionUrlParser.parseConnectionString(datasourceConfig.getUrl());
    HostInfo hostInfo = connectionUrlParser.getHosts().get(0);
    int port = hostInfo.getPort();
    String host = hostInfo.getHost();
    String username = datasourceConfig.getUser();
    String password = datasourceConfig.getPassword();
    BinaryLogClient client = new BinaryLogClient(datasourceConfig.getUrl(), port, username, password);
    NameMap<NameMap<Boolean>> filterMap = new NameMap<>();
    for (Partition partition : partitions) {
        String schema = partition.getSchema();
        String table = partition.getTable();
        NameMap<Boolean> map = filterMap.computeIfAbsent(SQLUtils.normalize(schema), s -> new NameMap<>());
        map.put(table, Boolean.TRUE);
    }
    return Flowable.create(new FlowableOnSubscribe<ParamSQL>() {

        @Override
        public void subscribe(@NonNull FlowableEmitter<ParamSQL> emitter) throws Throwable {
            client.registerEventListener(new BinaryLogClient.EventListener() {

                private final Map<Long, TableMapEventData> tablesById = new HashMap<Long, TableMapEventData>();

                private final Map<String, Map<Integer, Map<String, Object>>> tablesColumnMap = new HashMap<>();

                private String binlogFilename;

                private Charset charset = StandardCharsets.UTF_8;

                private Map<Integer, Map<String, Object>> loadColumn(String database, String table) {
                    Map<Integer, Map<String, Object>> res = new HashMap<>();
                    try (DefaultConnection defaultConnection = jdbcConnectionManager.getConnection(targetName)) {
                        List<Map<String, Object>> list = JdbcUtils.executeQuery(defaultConnection.getRawConnection(), "select  COLUMN_NAME, ORDINAL_POSITION, DATA_TYPE, CHARACTER_SET_NAME from INFORMATION_SCHEMA.COLUMNS where table_name='" + table + "' and TABLE_SCHEMA='" + database + "'", Collections.emptyList());
                        for (Map<String, Object> stringObjectMap : list) {
                            Number pos = (Number) stringObjectMap.get("ORDINAL_POSITION");
                            res.put(pos.intValue(), stringObjectMap);
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                    return res;
                }

                @Override
                public void onEvent(Event event) {
                    try {
                        EventHeader header = event.getHeader();
                        switch(header.getEventType()) {
                            case UNKNOWN:
                                break;
                            case START_V3:
                                break;
                            case QUERY:
                                QueryEventData queryEventData = event.getData();
                                String query = queryEventData.getSql();
                                if (!query.startsWith("S")) {
                                    handleDDL(queryEventData);
                                }
                                break;
                            case STOP:
                                emitter.onComplete();
                                break;
                            case ROTATE:
                                {
                                    RotateEventData data = event.getData();
                                    this.binlogFilename = data.getBinlogFilename();
                                    break;
                                }
                            case INTVAR:
                                break;
                            case LOAD:
                                break;
                            case SLAVE:
                                break;
                            case CREATE_FILE:
                                break;
                            case APPEND_BLOCK:
                                break;
                            case EXEC_LOAD:
                                break;
                            case DELETE_FILE:
                                break;
                            case NEW_LOAD:
                                break;
                            case RAND:
                                break;
                            case USER_VAR:
                                break;
                            case FORMAT_DESCRIPTION:
                                break;
                            case XID:
                                break;
                            case BEGIN_LOAD_QUERY:
                                break;
                            case EXECUTE_LOAD_QUERY:
                                break;
                            case TABLE_MAP:
                                {
                                    handleTableMap(event);
                                    break;
                                }
                            case PRE_GA_WRITE_ROWS:
                            case WRITE_ROWS:
                            case EXT_WRITE_ROWS:
                                handleWriteRowsEvent(event);
                                break;
                            case EXT_UPDATE_ROWS:
                            case PRE_GA_UPDATE_ROWS:
                            case UPDATE_ROWS:
                                handleUpdateRowsEvent(event);
                                break;
                            case PRE_GA_DELETE_ROWS:
                            case EXT_DELETE_ROWS:
                            case DELETE_ROWS:
                                handleDeleteRowsEvent(event);
                                break;
                            case INCIDENT:
                                break;
                            case HEARTBEAT:
                                break;
                            case IGNORABLE:
                                break;
                            case ROWS_QUERY:
                                break;
                            case GTID:
                                break;
                            case ANONYMOUS_GTID:
                                break;
                            case PREVIOUS_GTIDS:
                                break;
                            case TRANSACTION_CONTEXT:
                                break;
                            case VIEW_CHANGE:
                                break;
                            case XA_PREPARE:
                                break;
                        }
                    } catch (Exception e) {
                        emitter.tryOnError(e);
                    }
                }

                private void handleDDL(QueryEventData event) {
                    String sql = event.getSql();
                    String database = event.getDatabase();
                    SQLStatement sqlStatement = SQLUtils.parseSingleMysqlStatement(sql);
                    if (sqlStatement instanceof SQLDDLStatement) {
                        SQLDDLStatement sqlDdlStatement = (SQLDDLStatement) sqlStatement;
                        MySqlSchemaStatVisitor mySqlSchemaStatVisitor = new MySqlSchemaStatVisitor();
                        sqlDdlStatement.accept(mySqlSchemaStatVisitor);
                        Map<TableStat.Name, TableStat> tables = mySqlSchemaStatVisitor.getTables();
                        boolean meet = tables.keySet().stream().allMatch(i -> filter(database, i.getName()));
                    }
                }

                private void handleUpdateRowsEvent(Event event) {
                    UpdateRowsEventData eventData = event.getData();
                    BitSet includedColumnsBeforeUpdate = eventData.getIncludedColumnsBeforeUpdate();
                    BitSet includedColumns = eventData.getIncludedColumns();
                    List<Map.Entry<Serializable[], Serializable[]>> rows = eventData.getRows();
                    TableMapEventData tableMapEvent = tablesById.get(eventData.getTableId());
                    if (!filter(tableMapEvent.getDatabase(), tableMapEvent.getTable()))
                        return;
                    MySqlUpdateStatement mySqlUpdateStatement = new MySqlUpdateStatement();
                    SQLExprTableSource sqlTableSource = new SQLExprTableSource();
                    sqlTableSource.setExpr("`" + tableMapEvent.getTable() + "`");
                    sqlTableSource.setSchema("`" + tableMapEvent.getDatabase() + "`");
                    mySqlUpdateStatement.setTableSource(sqlTableSource);
                    Map<Integer, Map<String, Object>> xxx = tablesColumnMap.get(tableMapEvent.getDatabase() + "." + tableMapEvent.getTable());
                    SQLBinaryOpExprGroup sqlBinaryOpExprGroup = getCondition(includedColumnsBeforeUpdate, xxx);
                    for (int i = 0; i < includedColumns.length(); i++) {
                        int column = includedColumns.nextSetBit(i);
                        Map<String, Object> coumnMap = xxx.get(column + 1);
                        Object column_name = coumnMap.get("COLUMN_NAME");
                        SQLUpdateSetItem sqlUpdateSetItem = new SQLUpdateSetItem();
                        sqlUpdateSetItem.setColumn(new SQLIdentifierExpr("`" + column_name + "`"));
                        sqlUpdateSetItem.setValue(new SQLVariantRefExpr("?"));
                        mySqlUpdateStatement.getItems().add(sqlUpdateSetItem);
                    }
                    mySqlUpdateStatement.setWhere(sqlBinaryOpExprGroup);
                    mySqlUpdateStatement.setLimit(new SQLLimit(1));
                    sqlUpdate(mySqlUpdateStatement.toString(), rows);
                }

                private SQLBinaryOpExprGroup getCondition(BitSet includedColumnsBeforeUpdate, Map<Integer, Map<String, Object>> xxx) {
                    SQLBinaryOpExprGroup sqlBinaryOpExprGroup = new SQLBinaryOpExprGroup(SQLBinaryOperator.BooleanAnd);
                    for (int i = 0; i < includedColumnsBeforeUpdate.length(); i++) {
                        int column = includedColumnsBeforeUpdate.nextSetBit(i);
                        Map<String, Object> coumnMap = xxx.get(column + 1);
                        Object column_name = coumnMap.get("COLUMN_NAME");
                        SQLExpr sqlExpr = SQLUtils.toSQLExpr("`" + column_name + "` <=> ?");
                        sqlBinaryOpExprGroup.add(sqlExpr);
                    }
                    return sqlBinaryOpExprGroup;
                }

                private void sqlUpdate(String toString, List<Map.Entry<Serializable[], Serializable[]>> rows) {
                    for (Map.Entry<Serializable[], Serializable[]> row : rows) {
                        Serializable[] key = row.getKey();
                        Serializable[] value = row.getValue();
                        Object[] objects = new Object[key.length + value.length];
                        System.arraycopy(key, 0, objects, 0, key.length);
                        System.arraycopy(value, 0, objects, key.length, key.length + value.length);
                        emitter.onNext(ParamSQL.of(toString, objects));
                    }
                }

                private boolean filter(String database, String table) {
                    if (Strings.isNullOrEmpty(database)) {
                        return false;
                    }
                    if (Strings.isNullOrEmpty(table)) {
                        return false;
                    }
                    NameMap<Boolean> tableMap = filterMap.get(SQLUtils.normalize(database), false);
                    if (tableMap != null && !tableMap.map().isEmpty()) {
                        return Boolean.TRUE.equals(tableMap.get(SQLUtils.normalize(table)));
                    }
                    return false;
                }

                private void handleTableMap(Event event) {
                    TableMapEventData tableMapEventData = event.getData();
                    tablesById.put(tableMapEventData.getTableId(), tableMapEventData);
                    String tableName = tableMapEventData.getDatabase() + "." + tableMapEventData.getTable();
                    if (!tablesColumnMap.containsKey(tableName)) {
                        tablesColumnMap.put(tableName, loadColumn(tableMapEventData.getDatabase(), tableMapEventData.getTable()));
                    }
                }

                private void handleWriteRowsEvent(Event event) {
                    WriteRowsEventData eventData = event.getData();
                    TableMapEventData tableMapEvent = tablesById.get(eventData.getTableId());
                    if (!filter(tableMapEvent.getDatabase(), tableMapEvent.getTable()))
                        return;
                    Map<Integer, Map<String, Object>> xxx = tablesColumnMap.get(tableMapEvent.getDatabase() + "." + tableMapEvent.getTable());
                    BitSet inculudeColumn = eventData.getIncludedColumns();
                    MySqlInsertStatement mySqlInsertStatement = new MySqlInsertStatement();
                    mySqlInsertStatement.setTableName(new SQLIdentifierExpr("`" + tableMapEvent.getTable() + "`"));
                    mySqlInsertStatement.getTableSource().setSchema("`" + tableMapEvent.getDatabase() + "`");
                    SQLInsertStatement.ValuesClause values = new SQLInsertStatement.ValuesClause();
                    mySqlInsertStatement.setValues(values);
                    int size = inculudeColumn.length();
                    List<Serializable[]> rows = eventData.getRows();
                    for (int i = 0; i < size; i++) {
                        int column = inculudeColumn.nextSetBit(i);
                        Map<String, Object> coumnMap = xxx.get(column + 1);
                        Object column_name = coumnMap.get("COLUMN_NAME");
                        mySqlInsertStatement.addColumn(new SQLIdentifierExpr("`" + column_name + "`"));
                        values.addValue(new SQLVariantRefExpr("?"));
                    }
                    sqlInsert(mySqlInsertStatement.toString(), rows);
                }

                private void sqlInsert(String sql, List<Serializable[]> rows) {
                    for (Serializable[] row : rows) {
                        Object[] objects = new Object[row.length];
                        System.arraycopy(row, 0, objects, 0, row.length);
                        emitter.onNext(ParamSQL.of(sql, objects));
                    }
                }

                private void handleDeleteRowsEvent(Event event) {
                    DeleteRowsEventData eventData = event.getData();
                    EventHeader header = event.getHeader();
                    TableMapEventData tableMapEvent = tablesById.get(eventData.getTableId());
                    if (!filter(tableMapEvent.getDatabase(), tableMapEvent.getTable()))
                        return;
                    Map<Integer, Map<String, Object>> xxx = tablesColumnMap.get(tableMapEvent.getDatabase() + "." + tableMapEvent.getTable());
                    BitSet inculudeColumn = eventData.getIncludedColumns();
                    SQLBinaryOpExprGroup condition = getCondition(inculudeColumn, xxx);
                    int size = inculudeColumn.length();
                    List<Serializable[]> rows = eventData.getRows();
                    MySqlDeleteStatement mySqlDeleteStatement = new MySqlDeleteStatement();
                    mySqlDeleteStatement.setLimit(new SQLLimit(1));
                    SQLExprTableSource sqlExprTableSource = new SQLExprTableSource();
                    sqlExprTableSource.setExpr("`" + tableMapEvent.getTable() + "`");
                    sqlExprTableSource.setSchema("`" + tableMapEvent.getDatabase() + "`");
                    mySqlDeleteStatement.setTableSource(sqlExprTableSource);
                    mySqlDeleteStatement.addWhere(condition);
                    sqlDelete(mySqlDeleteStatement.toString(), rows);
                }

                private void sqlDelete(String mySqlDeleteStatement, List<Serializable[]> rows) {
                    for (Serializable[] row : rows) {
                        Object[] objects = new Object[row.length];
                        System.arraycopy(row, 0, objects, 0, row.length);
                        emitter.onNext(ParamSQL.of(mySqlDeleteStatement, objects));
                    }
                }
            });
            client.connect();
        }
    }, BackpressureStrategy.BUFFER);
}
Also used : Serializable(java.io.Serializable) ToString(groovy.transform.ToString) SQLStatement(com.alibaba.druid.sql.ast.SQLStatement) DatasourceConfig(io.mycat.config.DatasourceConfig) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SQLDDLStatement(com.alibaba.druid.sql.ast.statement.SQLDDLStatement) SQLUpdateSetItem(com.alibaba.druid.sql.ast.statement.SQLUpdateSetItem) MySqlSchemaStatVisitor(com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor) MySqlDeleteStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlDeleteStatement) SQLVariantRefExpr(com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr) NameMap(io.mycat.util.NameMap) SQLException(java.sql.SQLException) SQLLimit(com.alibaba.druid.sql.ast.SQLLimit) TableStat(com.alibaba.druid.stat.TableStat) BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient) MySqlUpdateStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlUpdateStatement) SQLInsertStatement(com.alibaba.druid.sql.ast.statement.SQLInsertStatement) SQLBinaryOpExprGroup(com.alibaba.druid.sql.ast.expr.SQLBinaryOpExprGroup) Partition(io.mycat.Partition) Charset(java.nio.charset.Charset) SQLIdentifierExpr(com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr) NameMap(io.mycat.util.NameMap) MySqlInsertStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement) ConnectionUrlParser(com.mysql.cj.conf.ConnectionUrlParser) SQLException(java.sql.SQLException) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) SQLExprTableSource(com.alibaba.druid.sql.ast.statement.SQLExprTableSource) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) HostInfo(com.mysql.cj.conf.HostInfo)

Example 5 with NameMap

use of io.mycat.util.NameMap in project Mycat2 by MyCATApache.

the class MycatRouterConfigOps method putHashTable.

@Override
public ShardingTableConfig putHashTable(String schemaName, String tableName, MySqlCreateTableStatement tableStatement, Map<String, Object> infos) {
    NameMap<SQLColumnDefinition> columnMap = NameMap.immutableCopyOf(tableStatement.getColumnDefinitions().stream().collect(Collectors.toMap(k -> SQLUtils.normalize(k.getColumnName()), v -> v)));
    Map<String, ShardingTableConfig> indexTableConfigs = new HashMap<>();
    MySqlPrimaryKey primaryKey = (MySqlPrimaryKey) tableStatement.getTableElementList().stream().filter(i -> i instanceof MySqlPrimaryKey).findFirst().orElse(null);
    for (SQLTableElement sqlTableElement : tableStatement.getTableElementList()) {
        if (sqlTableElement instanceof MySqlTableIndex) {
            MySqlTableIndex element = (MySqlTableIndex) sqlTableElement;
            if (!element.isGlobal()) {
                continue;
            }
            SQLIndexDefinition indexDefinition = element.getIndexDefinition();
            MySqlCreateTableStatement indexCreateTableStatement = new MySqlCreateTableStatement();
            indexCreateTableStatement.setIfNotExiists(true);
            String indexTableName = tableName + "_" + SQLUtils.normalize(indexDefinition.getName().getSimpleName());
            indexCreateTableStatement.setTableName(indexTableName);
            indexCreateTableStatement.setSchema(schemaName);
            for (SQLSelectOrderByItem indexColumn : indexDefinition.getColumns()) {
                indexCreateTableStatement.addColumn(columnMap.get(SQLUtils.normalize(indexColumn.getExpr().toString())));
            }
            for (SQLName sqlName : indexDefinition.getCovering()) {
                indexCreateTableStatement.addColumn(columnMap.get(SQLUtils.normalize(sqlName.toString())));
            }
            if (primaryKey != null) {
                indexCreateTableStatement.getTableElementList().add(primaryKey);
            }
            indexCreateTableStatement.setDbPartitionBy(indexDefinition.getDbPartitionBy());
            indexCreateTableStatement.setTablePartitionBy(indexDefinition.getTbPartitionBy());
            indexCreateTableStatement.setDbPartitions(indexCreateTableStatement.getDbPartitions());
            indexCreateTableStatement.setTablePartitions(indexDefinition.getTbPartitions());
            Map<String, Object> autoHashProperties = getAutoHashProperties(indexCreateTableStatement);
            ShardingTableConfig.ShardingTableConfigBuilder builder = ShardingTableConfig.builder();
            ShardingTableConfig config = builder.createTableSQL(MycatSQLUtils.toString(indexCreateTableStatement)).function(ShardingFunction.builder().properties(autoHashProperties).build()).build();
            indexTableConfigs.put(indexTableName, config);
        }
    }
    ShardingTableConfig.ShardingTableConfigBuilder builder = ShardingTableConfig.builder();
    ShardingTableConfig config = builder.createTableSQL(MycatSQLUtils.toString(tableStatement)).function(ShardingFunction.builder().properties((Map) infos).build()).shardingIndexTables(indexTableConfigs).build();
    return putShardingTable(schemaName, tableName, config);
}
Also used : TransactionType(io.mycat.beans.mycat.TransactionType) QueryPlanner(io.mycat.calcite.spm.QueryPlanner) MycatSQLUtils(com.alibaba.druid.sql.MycatSQLUtils) ScheduledFuture(java.util.concurrent.ScheduledFuture) io.mycat(io.mycat) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement) DruidDatasourceProvider(io.mycat.datasource.jdbc.DruidDatasourceProvider) LoggerFactory(org.slf4j.LoggerFactory) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition) DbPlanManagerPersistorImpl(io.mycat.calcite.spm.DbPlanManagerPersistorImpl) ReplicaSelectorRuntime(io.mycat.replica.ReplicaSelectorRuntime) KV(io.mycat.sqlhandler.config.KV) MySQLManager(cn.mycat.vertx.xa.MySQLManager) JsonUtil(io.mycat.util.JsonUtil) MemPlanCache(io.mycat.calcite.spm.MemPlanCache) XaLogImpl(cn.mycat.vertx.xa.impl.XaLogImpl) SQLExpr(com.alibaba.druid.sql.ast.SQLExpr) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) MycatMySQLManagerImpl(io.mycat.commands.MycatMySQLManagerImpl) Collectors(java.util.stream.Collectors) ReplicaType(io.mycat.replica.ReplicaType) MySqlTableIndex(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex) SequenceGenerator(io.mycat.plug.sequence.SequenceGenerator) ReplicaSelectorManager(io.mycat.replica.ReplicaSelectorManager) NotNull(org.jetbrains.annotations.NotNull) Json(io.vertx.core.json.Json) java.util(java.util) AuthenticatorImpl(io.mycat.proxy.session.AuthenticatorImpl) Getter(lombok.Getter) UpdatePlanCache(io.mycat.calcite.spm.UpdatePlanCache) XaLog(cn.mycat.vertx.xa.XaLog) UpdateSet(io.mycat.sqlhandler.config.UpdateSet) DefaultConnection(io.mycat.datasource.jdbc.datasource.DefaultConnection) SqlResultSetService(io.mycat.commands.SqlResultSetService) SQLTableElement(com.alibaba.druid.sql.ast.statement.SQLTableElement) MySqlPrimaryKey(com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey) MonitorReplicaSelectorManager(io.mycat.monitor.MonitorReplicaSelectorManager) SchemaHandler(io.mycat.calcite.table.SchemaHandler) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) SQLIndexDefinition(com.alibaba.druid.sql.ast.SQLIndexDefinition) SQLUtils(com.alibaba.druid.sql.SQLUtils) Logger(org.slf4j.Logger) DualCustomTableHandler(io.mycat.calcite.table.DualCustomTableHandler) LocalXaMemoryRepositoryImpl(cn.mycat.vertx.xa.impl.LocalXaMemoryRepositoryImpl) PrototypeService(io.mycat.prototypeserver.mysql.PrototypeService) StatisticCenter(io.mycat.statistic.StatisticCenter) ReplicaSwitchType(io.mycat.replica.ReplicaSwitchType) LoadBalanceManager(io.mycat.plug.loadBalance.LoadBalanceManager) NameMap(io.mycat.util.NameMap) StorageManager(io.mycat.sqlhandler.config.StorageManager) MySqlTableIndex(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex) SQLName(com.alibaba.druid.sql.ast.SQLName) SQLTableElement(com.alibaba.druid.sql.ast.statement.SQLTableElement) SQLColumnDefinition(com.alibaba.druid.sql.ast.statement.SQLColumnDefinition) MySqlPrimaryKey(com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey) SQLSelectOrderByItem(com.alibaba.druid.sql.ast.statement.SQLSelectOrderByItem) SQLIndexDefinition(com.alibaba.druid.sql.ast.SQLIndexDefinition) MySqlCreateTableStatement(com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement)

Aggregations

NameMap (io.mycat.util.NameMap)13 SchemaHandler (io.mycat.calcite.table.SchemaHandler)7 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)6 SQLUtils (com.alibaba.druid.sql.SQLUtils)5 ReplicaSelectorManager (io.mycat.replica.ReplicaSelectorManager)5 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)4 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)4 SQLExprTableSource (com.alibaba.druid.sql.ast.statement.SQLExprTableSource)4 DatasourceConfig (io.mycat.config.DatasourceConfig)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 NotNull (org.jetbrains.annotations.NotNull)4 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)3 DrdsRunnerHelper (io.mycat.calcite.DrdsRunnerHelper)3 DefaultConnection (io.mycat.datasource.jdbc.datasource.DefaultConnection)3 XaLog (cn.mycat.vertx.xa.XaLog)2 SQLIdentifierExpr (com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr)2 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)2 MySqlInsertStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement)2 io.mycat (io.mycat)2