Class QualifiedNameResolver

Object
gudusoft.gsqlparser.resolver2.model.QualifiedNameResolver

public class QualifiedNameResolver extends Object
Service for normalizing table names into fully qualified names.

This class handles the conversion of potentially partial table names (e.g., just "table", "schema.table", or "catalog.schema.table") into fully qualified QualifiedName objects by applying default catalog and schema from TSQLEnv.

Normalization Rules

InputRuleOutput
tableApply both defaults(defaultCatalog, defaultSchema, table)
schema.tableApply catalog default only(defaultCatalog, schema, table)
catalog.schema.tableNo defaults applied(catalog, schema, table)

Usage Example


 // Setup
 TSQLEnv env = new TSQLEnv(EDbVendor.dbvmssql);
 env.setDefaultCatalogName("mydb");
 env.setDefaultSchemaName("dbo");

 QualifiedNameResolver resolver = new QualifiedNameResolver(env, EDbVendor.dbvmssql);

 // Normalize a simple table name
 QualifiedName q1 = resolver.resolve(tableNode);
 // Result: (mydb, dbo, tableName)

 // Normalize a two-part name
 QualifiedName q2 = resolver.resolve("sales", "orders");
 // Result: (mydb, sales, orders)

 // Three-part name is unchanged
 QualifiedName q3 = resolver.resolve("otherdb", "hr", "employees");
 // Result: (otherdb, hr, employees)
 
See Also:
  • Constructor Details

    • QualifiedNameResolver

      public QualifiedNameResolver(TSQLEnv sqlEnv, EDbVendor vendor)
      Create a QualifiedNameResolver with the given SQL environment.
      Parameters:
      sqlEnv - The SQL environment containing default catalog/schema
      vendor - The database vendor
    • QualifiedNameResolver

      public QualifiedNameResolver(String defaultCatalog, String defaultSchema, EDbVendor vendor)
      Create a QualifiedNameResolver with explicit defaults.
      Parameters:
      defaultCatalog - The default catalog name
      defaultSchema - The default schema name
      vendor - The database vendor
  • Method Details

    • getDefaultCatalog

      Get the current default catalog.

      If sqlEnv was provided, returns the current value from sqlEnv (which may have changed since construction).

    • getDefaultSchema

      Get the current default schema.

      If sqlEnv was provided, returns the current value from sqlEnv (which may have changed since construction).

    • resolve

      public QualifiedName resolve(TTable table)
      Resolve a TTable's name to a fully qualified name.
      Parameters:
      table - The table node from the AST
      Returns:
      A normalized QualifiedName with defaults applied
    • resolve

      public QualifiedName resolve(TObjectName tableName)
      Resolve a TObjectName (table reference) to a fully qualified name.
      Parameters:
      tableName - The table name node from the AST
      Returns:
      A normalized QualifiedName with defaults applied
    • resolve

      public QualifiedName resolve(String tableName)
      Resolve a simple table name string to a fully qualified name.
      Parameters:
      tableName - The table name (may include dots)
      Returns:
      A normalized QualifiedName with defaults applied
    • resolve

      public QualifiedName resolve(String catalog, String schema, String name)
      Create a qualified name from explicit parts with defaults applied.
      Parameters:
      catalog - The catalog (null to use default)
      schema - The schema (null to use default)
      name - The table name (required)
      Returns:
      A normalized QualifiedName
    • isSameTable

      public boolean isSameTable(QualifiedName name1, QualifiedName name2)
      Check if two qualified names refer to the same table.

      Both names are first normalized using current defaults, then compared for equality.

      Parameters:
      name1 - First qualified name (may be partial)
      name2 - Second qualified name (may be partial)
      Returns:
      true if they refer to the same fully-qualified table
    • matches

      public boolean matches(QualifiedName reference, QualifiedName target)
      Check if a qualified name matches a target name, considering defaults.
      Parameters:
      reference - The reference being checked (may be partial)
      target - The target table name (should be fully qualified)
      Returns:
      true if the reference resolves to the target
    • toString

      public String toString()
      Overrides:
      toString in class Object