lmhmhl commented on issue #8883:
URL: https://github.com/apache/shardingsphere/issues/8883#issuecomment-757603795


   Hi @tristaZero.
   A1: When I read the source code of ShardingSphereStatement, I found there 
are some code in it can be used to create `executionContext`, and 
`calciteExecutor`, so I change the source code a little tiny bit to execute ` 
executeQueryByCalcite()` when execute query as the following code snippet, so 
`ExecutionContext ` is acquired by ShardingSphereStatement(see as figure 1).
   A2: I am not sure SQLUnit is logic sql, which variable should I check out? 
BTW, I did the debug deeper and found that this bug is maybe caused by 
`tableMap` is null, when Calcite compare the actual table with the table is SQL 
statement(see as figure 2, 3).
   ```
   private List<QueryResult> executeQuery() throws SQLException {
           if 
(metaDataContexts.getDefaultMetaData().getRuleMetaData().getRules().stream().anyMatch(each
 -> each instanceof RawExecutionRule)) {
               return rawExecutor.execute(createRawExecutionGroups(), new 
RawSQLExecutorCallback()).stream().map(each -> (QueryResult) 
each).collect(Collectors.toList());
           }
           if (executionContext.getRouteContext().isToCalcite()) {
               return executeQueryByCalcite();
           }
           Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups = 
createExecutionGroups();
           cacheStatements(executionGroups);
           StatementExecuteQueryCallback callback = new 
StatementExecuteQueryCallback(metaDataContexts.getDefaultMetaData().getResource().getDatabaseType(),
                   executionContext.getSqlStatementContext().getSqlStatement(), 
SQLExecutorExceptionHandler.isExceptionThrown());
           return driverJDBCExecutor.executeQuery(executionGroups, callback);
       }
   ```
   figure1
   <img width="1132" alt="Screen Shot 2021-01-11 at 11 00 04 AM" 
src="https://user-images.githubusercontent.com/24718258/104144412-14c22b00-53fe-11eb-8a45-59121d667926.png";>
   
   figure 2
   <img width="1020" alt="Screen Shot 2021-01-11 at 1 56 32 AM" 
src="https://user-images.githubusercontent.com/24718258/104144325-be54ec80-53fd-11eb-9689-57a5a2669162.png";>
   
   figure3
   <img width="1007" alt="Screen Shot 2021-01-11 at 2 23 29 AM" 
src="https://user-images.githubusercontent.com/24718258/104144361-dcbae800-53fd-11eb-85f8-af049e75ec10.png";>
   


----------------------------------------------------------------
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