apache/beam · error · IllegalStateException

Unable to get current schema name from JdbcConnection. Assum

Error message

Unable to get current schema name from JdbcConnection. Assuming table names in the query are fully-qualified from the root.

What it means

TableResolutionUtils.getCurrentSchemaName asks the Calcite JdbcConnection for its current default schema so unqualified table names in a query can be resolved. If connection.getSchema() throws SQLException, the utility cannot determine the default schema and throws IllegalStateException, telling the user to assume table names must be fully qualified from the root schema.

Source

Thrown at sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/TableResolutionUtils.java:90

        checkStateNotNull(
            getCurrentSchemaName(connection),
            "When trying to set up custom table resolution: current schema is null");

    SchemaWithName defaultSchema = SchemaWithName.create(connection, currentSchemaName);

    if (defaultSchema.supportsCustomResolution()) {
      registerWithDefaultSchema(connection, tableNames, defaultSchema);
    }

    registerWithTopLevelSchemas(connection, tableNames);
  }

  /** Current (default) schema name in the JdbcConnection. */
  private static @Nullable String getCurrentSchemaName(JdbcConnection connection) {
    try {
      return connection.getSchema();
    } catch (SQLException e) {
      throw new IllegalStateException(
          "Unable to get current schema name from JdbcConnection. "
              + "Assuming table names in the query are fully-qualified from the root.",
          e);
    }
  }

  /**
   * Simple identifiers have to be resolved by the default schema, as well as compoung identifiers
   * that don't have a matching top-level schema (meaning that a user didn't specify a top-level
   * schema and expected it to be inferred).
   */
  private static void registerWithDefaultSchema(
      JdbcConnection connection, List<TableName> tableNames, SchemaWithName defaultSchema) {
    Set<String> topLevelSchemas = connection.getRootSchema().getSubSchemaNames();

    List<TableName> simpleIdentifiers =
        tableNames.stream().filter(TableName::isSimple).collect(toList());

View on GitHub (pinned to 12126d8942)

Solutions

  1. Fully qualify table names in the query (e.g. beam.default.mytable or schema-qualified per your resolver) so the current schema is irrelevant.
  2. Ensure the JdbcConnection is fully initialized (default schema set) before executing/resolving queries.
  3. Inspect the cause SQLException from getSchema() to find the underlying connection setup problem.
  4. If you control the caller, register tables explicitly via a custom TableResolver rather than relying on the default schema.

Example fix

// before
SELECT * FROM mytable -- relies on current schema lookup
// after
SELECT * FROM beam.default.mytable -- fully qualified
Defensive patterns

Strategy: try-catch

Try / catch

try {
  runQuery(connection, sql);
} catch (IllegalStateException e) {
  if (e.getMessage().contains("Unable to get current schema name")) {
    throw new IllegalStateException("Fully qualify table names (e.g. beam.default.t) in your query", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getCustomTopLevelResolvers/currentSchemaName (which invoke getCurrentSchemaName) during table resolution when the JdbcConnection's underlying schema lookup fails — e.g. the connection is not fully initialized or its Calcite schema state is broken.

Common situations: Querying Beam SQL before the connection's default schema is set; programmatic use of BeamSql with a mis-configured CalciteConnection; unusual table-resolution entry points that run before connection setup completes.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a054bad7aac588ee. Report an issue: GitHub.