Hi,

I was looking at the validation code and at some point I saw that piece of
code in DelegatingScope#fullyQualify:
https://github.com/apache/calcite/blob/571731b80a58eb095ebac7123285c375e7afff90/core/src/main/java/org/apache/calcite/sql/validate/DelegatingScope.java#L309

      for (; i > 0; i--) {
        final SqlIdentifier prefix = identifier.getComponent(0, i);
        resolved.clear();
        resolve(prefix.names, nameMatcher, false, resolved);
        if (resolved.count() == 1) {
          final Resolve resolve = resolved.only();
          fromNs = resolve.namespace;
          fromPath = resolve.path;
          fromRowType = resolve.rowType();
          break;
        }
        // Look for a table alias that is the wrong case.
        if (nameMatcher.isCaseSensitive()) {
          final SqlNameMatcher liberalMatcher = SqlNameMatchers.liberal();
          resolved.clear();
          resolve(prefix.names, liberalMatcher, false, resolved);
          if (resolved.count() == 1) {
            final Step lastStep = Util.last(resolved.only().path.steps());
            throw validator.newValidationError(prefix,
                RESOURCE.tableNameNotFoundDidYouMean(prefix.toString(),
                    lastStep.name));
          }
        }
      }

This code looks buggy to me: the check for an alias with the wrong case
should happen after the loop is completed and no prefix has been resolved.
Can someone tell me if I'm correct about it? Unfortunately I was not able
to come up with a test case to demonstrate it.

Reply via email to