`
gaojingsong
  • 浏览: 1153113 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

Mycat源码解读--错误之【can't find table define in schema 】

阅读更多

Mycat之String msg = "can't find table define in schema "+ tableName + " schema:" + schema.getName();

错误位置如下:RouterUtil 类中的tryRouteForTables方法

1、正常情况可以查询数据


 2、别名查询出现错误


 Mycat 怎么就通过不了呢


 

 

2017-03-01 20:13:19,812 [WARN ][$_NIOREACTOR-2-RW] ServerConnection [id=4, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]SELECT address as address  FROM `t_gaojs` err:java.sql.SQLNonTransientException: can't find table define in schema ADDRESS schema:TESTDB java.sql.SQLNonTransientException: can't find table define in schema ADDRESS schema:TESTDB    

at io.mycat.route.util.RouterUtil.tryRouteForTables(RouterUtil.java:1002)

at io.mycat.route.parser.druid.impl.DruidSelectParser.tryRoute(DruidSelectParser.java:412)

at io.mycat.route.parser.druid.impl.DruidSelectParser.changeSql(DruidSelectParser.java:287)

at io.mycat.route.parser.druid.impl.DefaultDruidParser.parser(DefaultDruidParser.java:67)

找到报错原因 ---》 表名字解析错误


 错误位置:

RouterUtil 类中的tryRouteForTables方法

 

      /**

          * 多表路由

         */

       public static RouteResultset tryRouteForTables(SchemaConfig schema, DruidShardingParseInfo ctx,

                    RouteCalculateUnit routeUnit, RouteResultset rrs, boolean isSelect, 

                        LayerCachePool cachePool)

                   throws SQLNonTransientException {

 

              List<String> tables = ctx.getTables();

 

          if(schema.isNoSharding()||(tables.size() >= 1&&isNoSharding(schema,tables.get(0)))) {

              return routeToSingleNode(rrs, schema.getDataNode(), ctx.getSql());

         }

 

        //只有一个表的

        if(tables.size() == 1) {

                return RouterUtil.tryRouteForOneTable(schema, ctx, routeUnit, 

                        tables.get(0), rrs, isSelect, cachePool);

          }

 

         Set<String> retNodesSet = new HashSet<String>();

         //每个表对应的路由映射

         Map<String,Set<String>> tablesRouteMap = new HashMap<String,Set<String>>();

 

        //分库解析信息不为空

          Map<String, Map<String, Set<ColumnRoutePair>>> tablesAndConditions =                       routeUnit.getTablesAndConditions();

       if(tablesAndConditions != null && tablesAndConditions.size() > 0) {

             //为分库表找路由

            RouterUtil.findRouteWithcConditionsForTables(schema, rrs, tablesAndConditions, 

                                         tablesRouteMap, ctx.getSql(), cachePool, isSelect);

          if(rrs.isFinishedRoute()) {

                  return rrs;

          }

   }

 

//为全局表和单库表找路由

      for(String tableName : tables) {

            TableConfig tableConfig = schema.getTables().get(tableName.toUpperCase());

          if(tableConfig == null) {

String msg = "can't find table define in schema "+ tableName + " schema:" + schema.getName();

          LOGGER.warn(msg);

         throw new SQLNonTransientException(msg);

     }

        if(tableConfig.isGlobalTable()) {//全局表

            if(tablesRouteMap.get(tableName) == null) {

                  tablesRouteMap.put(tableName, new HashSet<String>());

              }

           tablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());

     } else if(tablesRouteMap.get(tableName) == null) { //余下的表都是单库表

             tablesRouteMap.put(tableName, new HashSet<String>());

            tablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());

       }

}

             //此处省略如下代码

               

}

 

 

  • 大小: 39.9 KB
  • 大小: 40.5 KB
  • 大小: 40.7 KB
  • 大小: 113.4 KB
0
0
分享到:
评论
1 楼 hdd901002 2018-05-17  
光说明错误在哪里有什么用,解决方法啊。。。
我也碰到了,一条join语句,后来两张表JOIN先后调换位置就好了

相关推荐

Global site tag (gtag.js) - Google Analytics