strongduanmu commented on a change in pull request #7150:
URL: https://github.com/apache/shardingsphere/pull/7150#discussion_r479769938



##########
File path: 
shardingsphere-sql-parser/shardingsphere-sql-parser-binder/src/main/java/org/apache/shardingsphere/sql/parser/binder/metadata/schema/SchemaMetaDataLoader.java
##########
@@ -105,7 +107,7 @@ public static SchemaMetaData load(final DataSource 
dataSource, final int maxConn
     
     private static List<String> loadAllTableNames(final Connection connection, 
final String databaseType) throws SQLException {
         List<String> result = new LinkedList<>();
-        try (ResultSet resultSet = 
connection.getMetaData().getTables(connection.getCatalog(), 
JdbcUtil.getSchema(connection, databaseType), null, new String[]{TABLE_TYPE})) {
+        try (ResultSet resultSet = 
connection.getMetaData().getTables(connection.getCatalog(), 
JdbcUtil.getSchema(connection, databaseType), null, new String[]{TABLE_TYPE, 
VIEW_TYPE})) {

Review comment:
       > Hi, why do we need to load `VIEW_TYPE `?
   
   @tristaZero The table sharding strategy will not be configured when 
executing the `select * from view`, so 
`ShardingUnconfiguredTablesRoutingEngine` will be used for routing. When the 
`ShardingUnconfiguredTablesRoutingEngine` performs routing, it will determine 
the routing result of the table based on the loaded metadata table information. 
In order to support the routing of the `select * from view` statement, the view 
information needs to be loaded in the metadata.
   
   The routing logic is as follows:
   
   ```java
   @Override
   public RouteResult route(final ShardingRule shardingRule) {
       Optional<String> dataSourceName = findDataSourceName();
       if (!dataSourceName.isPresent()) {
           throw new ShardingSphereException("Can not route tables for `%s`, 
please make sure the tables are in same schema.", logicTables);
       }
       RouteResult result = new RouteResult();
       List<RouteMapper> routingTables = new ArrayList<>(logicTables.size());
       for (String each : logicTables) {
           routingTables.add(new RouteMapper(each, each));
       }
       result.getRouteUnits().add(new RouteUnit(new 
RouteMapper(dataSourceName.get(), dataSourceName.get()), routingTables));
       return result;
   }
   
   private Optional<String> findDataSourceName() {
       for (Entry<String, SchemaMetaData> entry : 
unconfiguredSchemaMetaDataMap.entrySet()) {
           if (entry.getValue().getAllTableNames().containsAll(logicTables)) {
               return Optional.of(entry.getKey());
           }
       }
       return Optional.empty();
   }
   ```
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to