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


   Hi @tristaZero , thanks for your comment and patience, I debugged the 
related classes, and found that the error is caused in 
`org.apache.calcite.sql.validate.IdentifierNamespace`, which has a method 
called `resolveImpl`,  there has a line of code `            
this.parentScope.resolveTable(names, nameMatcher, Path.EMPTY, resolved);`  
`resolved` has a variable called `resolves`, resolves is 0 after this method 
has been invoked, so it won't execute the branch of `return`, but throws an 
execution. I am not very familiar the source code of Calcite, so I don't why 
the `resolves ` is 0 after the `resolveTable` method called. 
   
   ```
   private SqlValidatorNamespace resolveImpl(SqlIdentifier id) {
           SqlNameMatcher nameMatcher = 
this.validator.catalogReader.nameMatcher();
           ResolvedImpl resolved = new ResolvedImpl();
           List names = SqlIdentifier.toStar(id.names);
   
           try {
               this.parentScope.resolveTable(names, nameMatcher, Path.EMPTY, 
resolved);
           } catch (CyclicDefinitionException var12) {
               if (var12.depth == 1) {
                   throw this.validator.newValidationError(id, 
Static.RESOURCE.cyclicDefinition(id.toString(), 
SqlIdentifier.getString(var12.path)));
               }
   
               throw new CyclicDefinitionException(var12.depth - 1, var12.path);
           }
   
           Resolve previousResolve = null;
           if (resolved.count() == 1) {
               Resolve resolve = previousResolve = resolved.only();
               if (resolve.remainingNames.isEmpty()) {
                   return resolve.namespace;
               }
   
               if (!nameMatcher.isCaseSensitive()) {
                   throw this.validator.newValidationError(id, 
Static.RESOURCE.objectNotFoundWithin((String)resolve.remainingNames.get(0), 
SqlIdentifier.getString(resolve.path.stepNames())));
               }
           }
   
           if (nameMatcher.isCaseSensitive()) {
               SqlNameMatcher liberalMatcher = SqlNameMatchers.liberal();
               resolved.clear();
               this.parentScope.resolveTable(names, liberalMatcher, Path.EMPTY, 
resolved);
               if (resolved.count() == 1) {
                   Resolve resolve = resolved.only();
                   if (!resolve.remainingNames.isEmpty() && previousResolve != 
null) {
                       throw this.validator.newValidationError(id, 
Static.RESOURCE.objectNotFoundWithin((String)resolve.remainingNames.get(0), 
SqlIdentifier.getString(resolve.path.stepNames())));
                   }
   
                   int i = previousResolve == null ? 0 : 
previousResolve.path.stepCount();
                   int offset = resolve.path.stepCount() + 
resolve.remainingNames.size() - names.size();
                   List<String> prefix = resolve.path.stepNames().subList(0, 
offset + i);
                   String next = (String)resolve.path.stepNames().get(i + 
offset);
                   if (prefix.isEmpty()) {
                       throw this.validator.newValidationError(id, 
Static.RESOURCE.objectNotFoundDidYouMean((String)names.get(i), next));
                   }
   
                   throw this.validator.newValidationError(id, 
Static.RESOURCE.objectNotFoundWithinDidYouMean((String)names.get(i), 
SqlIdentifier.getString(prefix), next));
               }
           }
   
           throw this.validator.newValidationError(id, 
Static.RESOURCE.objectNotFound(id.getComponent(0).toString()));
       }
   
   ```
   
   <img width="875" alt="Screen Shot 2021-01-09 at 1 15 49 AM" 
src="https://user-images.githubusercontent.com/24718258/104048601-75930d00-521e-11eb-98bf-70bbb3feabc4.png";>
   
   BTW,  the content of ExecutionContext of CalciteRowExecutor is as follows:
   <img width="1241" alt="Screen Shot 2021-01-08 at 8 32 01 PM" 
src="https://user-images.githubusercontent.com/24718258/104048677-9ce9da00-521e-11eb-9384-fa73ee1f574c.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