Class Scope

java.lang.Object
io.trino.sql.analyzer.Scope

@Immutable public class Scope extends Object
  • Method Details

    • create

      public static Scope create()
    • builder

      public static Scope.Builder builder()
    • withRelationType

      public Scope withRelationType(RelationType relationType)
    • getQueryBoundaryScope

      public Scope getQueryBoundaryScope()
    • getOuterQueryParent

      public Optional<Scope> getOuterQueryParent()
    • hasOuterParent

      public boolean hasOuterParent(Scope parent)
    • getLocalParent

      public Optional<Scope> getLocalParent()
    • getLocalScopeFieldCount

      public int getLocalScopeFieldCount()
    • getRelationId

      public RelationId getRelationId()
    • getRelationType

      public RelationType getRelationType()
    • resolveAsteriskedIdentifierChainBasis

      public Optional<Scope.AsteriskedIdentifierChainBasis> resolveAsteriskedIdentifierChainBasis(QualifiedName identifierChain, AllColumns selectItem)
      This method analyzes asterisked identifier chain in 'all fields reference', according to SQL standard. The following rules are applied: 1. if the identifier chain's length is lower than 4, it is attempted to resolve it as a table reference, either in the local scope or in outer scope. 2. if the identifier chain's length is greater than 1, it is attempted to match the chain's prefix of length 2 to a field of type Row, either in the local scope or in outer scope. Any available match in the innermost scope is picked and the 'identifier chain basis' is defined. If more than one basis is defined, it results in a failure (ambiguous identifier chain).

      NOTE: only ambiguity between table reference and field reference is currently detected. If two or more tables in the same scope match the identifier chain, they are indistinguishable in current Scope implementation, and such query results in returning fields from all of those tables. If two or more fields in the same scope match the identifier chain, such query will fail later during analysis.

      NOTE: Although references to outer scope tables are found, referencing all fields from outer scope tables is not yet supported.

    • isLocalScope

      public boolean isLocalScope(Scope other)
    • resolveField

      public ResolvedField resolveField(Expression expression, QualifiedName name)
    • tryResolveField

      public Optional<ResolvedField> tryResolveField(Expression expression)
    • tryResolveField

      public Optional<ResolvedField> tryResolveField(Expression node, QualifiedName name)
    • getField

      public ResolvedField getField(int index)
    • isColumnReference

      public boolean isColumnReference(QualifiedName name)
    • getNamedQuery

      public Optional<WithQuery> getNamedQuery(String name)
    • toString

      public String toString()
      Overrides:
      toString in class Object