{"record":{"id":"f59b935c35f7b1ee","repo":"apache/beam","slug":"cannot-find-spanner-table","errorCode":null,"errorMessage":"Cannot find Spanner table.","messagePattern":"Cannot find Spanner table\\.","errorType":"exception","errorClass":"SpannerSchemaRetrievalException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerTableSourceDef.java","lineNumber":55,"sourceCode":"  }\n\n  private SpannerTableSourceDef(SpannerConfig config, String table, Iterable<String> columns) {\n    this.table = table;\n    this.config = config;\n    this.columns = columns;\n  }\n\n  /** {@inheritDoc} */\n  @Override\n  public Schema getBeamSchema() {\n    Schema beamSchema;\n    try (SpannerAccessor spannerAccessor = SpannerAccessor.getOrCreate(config)) {\n      try (ReadContext readContext = spannerAccessor.getDatabaseClient().singleUse()) {\n        ResultSet result = readContext.read(table, KeySet.all(), columns, Options.limit(1));\n        if (result.next()) {\n          beamSchema = structTypeToBeamRowSchema(result.getMetadata().getRowType(), true);\n        } else {\n          throw new SpannerSchemaRetrievalException(\"Cannot find Spanner table.\");\n        }\n      }\n    } catch (Exception e) {\n      throw new SpannerSchemaRetrievalException(\"Exception while trying to retrieve schema\", e);\n    }\n    return beamSchema;\n  }\n}\n","sourceCodeStart":37,"sourceCodeEnd":64,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/SpannerTableSourceDef.java#L37-L64","documentation":"SpannerTableSourceDef.getBeamSchema() does a single-use read of the table with limit 1 to capture the row metadata; if the read returns no rows it throws SpannerSchemaRetrievalException(\"Cannot find Spanner table.\"). It treats an empty first read as evidence the table (or the requested columns) doesn't exist as expected.","triggerScenarios":"Resolving a Spanner table as a Beam SQL source when read(table, KeySet.all(), columns, limit 1) returns zero rows — table is empty, table doesn't exist (read yields no rows), or the column list matches nothing readable.","commonSituations":"Pointing the pipeline at a wrong database/instance where the table is absent; building the schema against an empty table in a fresh environment; IAM/network conditions silently returning empty results; typo in table name.","solutions":["Verify the table name and that instanceId/databaseId in SpannerConfig point to the right database.","Insert at least one row into the table before schema resolution, or pre-seed test data.","Check IAM permissions and error logs for a suppressed SpannerException wrapped in the outer catch.","Confirm with gcloud spanner databases execute-sql 'SELECT 1 FROM <table> LIMIT 1'."],"exampleFix":"// before\nSpannerConfig config = SpannerConfig.create().withInstanceId(\"staging\").withDatabaseId(\"app\"); // wrong db\n// after\nSpannerConfig config = SpannerConfig.create().withInstanceId(\"prod\").withDatabaseId(\"app\");","handlingStrategy":"validation","validationCode":"// Pre-check table has rows before schema resolution\ntry (ResultSet rs = dbClient.singleUse().read(table, KeySet.all(), List.of(keyCol), Options.limit(1))) {\n  if (!rs.next()) throw new IllegalStateException(\"Table \" + table + \" is empty; seed data first\");\n}","typeGuard":null,"tryCatchPattern":"try { rows = p.apply(SpannerRead.of(config).withTable(table)); } catch (SpannerSchemaRetrievalException e) { if (\"Cannot find Spanner table.\".equals(e.getMessage())) { /* fix table name/db or seed a row */ } throw e; }","preventionTips":["Verify instanceId/databaseId/table name against the target environment.","Seed at least one row in dev/test databases before pipeline runs.","Confirm with a gcloud spanner execute-sql LIMIT 1 probe."],"tags":["java","beam","spanner","schema","table"],"backgroundTag":"empty-result-set","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"}