{"record":{"id":"a054bad7aac588ee","repo":"apache/beam","slug":"unable-to-get-current-schema-name-from-jdbcconnection","errorCode":null,"errorMessage":"Unable to get current schema name from JdbcConnection. Assuming table names in the query are fully-qualified from the root.","messagePattern":"Unable to get current schema name from JdbcConnection\\. Assuming table names in the query are fully-qualified from the root\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/TableResolutionUtils.java","lineNumber":90,"sourceCode":"        checkStateNotNull(\n            getCurrentSchemaName(connection),\n            \"When trying to set up custom table resolution: current schema is null\");\n\n    SchemaWithName defaultSchema = SchemaWithName.create(connection, currentSchemaName);\n\n    if (defaultSchema.supportsCustomResolution()) {\n      registerWithDefaultSchema(connection, tableNames, defaultSchema);\n    }\n\n    registerWithTopLevelSchemas(connection, tableNames);\n  }\n\n  /** Current (default) schema name in the JdbcConnection. */\n  private static @Nullable String getCurrentSchemaName(JdbcConnection connection) {\n    try {\n      return connection.getSchema();\n    } catch (SQLException e) {\n      throw new IllegalStateException(\n          \"Unable to get current schema name from JdbcConnection. \"\n              + \"Assuming table names in the query are fully-qualified from the root.\",\n          e);\n    }\n  }\n\n  /**\n   * Simple identifiers have to be resolved by the default schema, as well as compoung identifiers\n   * that don't have a matching top-level schema (meaning that a user didn't specify a top-level\n   * schema and expected it to be inferred).\n   */\n  private static void registerWithDefaultSchema(\n      JdbcConnection connection, List<TableName> tableNames, SchemaWithName defaultSchema) {\n    Set<String> topLevelSchemas = connection.getRootSchema().getSubSchemaNames();\n\n    List<TableName> simpleIdentifiers =\n        tableNames.stream().filter(TableName::isSimple).collect(toList());\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/TableResolutionUtils.java#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fully qualify table names in the query (e.g. beam.default.mytable or schema-qualified per your resolver) so the current schema is irrelevant.","Ensure the JdbcConnection is fully initialized (default schema set) before executing/resolving queries.","Inspect the cause SQLException from getSchema() to find the underlying connection setup problem.","If you control the caller, register tables explicitly via a custom TableResolver rather than relying on the default schema."],"exampleFix":"// before\nSELECT * FROM mytable -- relies on current schema lookup\n// after\nSELECT * FROM beam.default.mytable -- fully qualified","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  runQuery(connection, sql);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"Unable to get current schema name\")) {\n    throw new IllegalStateException(\"Fully qualify table names (e.g. beam.default.t) in your query\", e);\n  }\n  throw e;\n}","preventionTips":["Always fully qualify table names in Beam SQL queries.","Initialize the connection and default schema before query resolution.","Log the cause SQLException from getSchema() to diagnose connection setup issues."],"tags":["java","jdbc","calcite","schema-resolution","beam-sql"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}