{"record":{"id":"331906e3a6e059e1","repo":"apache/beam","slug":"unable-to-partition-query-v","errorCode":null,"errorMessage":"unable to partition query: %v","messagePattern":"unable to partition query: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sdks/go/pkg/beam/io/spannerio/generate_partitions.go","lineNumber":92,"sourceCode":"\treturn &generatePartitionsFn{\n\t\tspannerFn: newSpannerFn(db),\n\t\tQuery:     query,\n\t\tOptions:   options,\n\t}\n}\n\nfunc (f *generatePartitionsFn) ProcessElement(ctx context.Context, _ []byte, emit func(partitionedRead)) error {\n\ttxn, err := f.client.BatchReadOnlyTransaction(ctx, f.Options.TimestampBound)\n\tif err != nil {\n\t\tpanic(\"unable to create batch read only transaction: \" + err.Error())\n\t}\n\tdefer txn.Close()\n\n\tmode := spannerpb.ExecuteSqlRequest_PROFILE\n\n\tpartitions, err := txn.PartitionQueryWithOptions(ctx, spanner.Statement{SQL: f.Query}, partitionOptions(f.Options), spanner.QueryOptions{Mode: &mode})\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"unable to partition query: %v\", err))\n\t}\n\n\tfor _, p := range partitions {\n\t\temit(newPartitionedRead(txn.ID, p))\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":74,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/spannerio/generate_partitions.go#L74-L101","documentation":"generatePartitionsFn panics when the Spanner PartitionQueryWithOptions call fails while trying to split the query into parallel partitions. The client error is formatted into the panic message. This typically indicates a bad SQL statement or a query that Spanner cannot partition.","triggerScenarios":"txn.PartitionQueryWithOptions returns an error: invalid SQL syntax, referencing a nonexistent table/column, query not partitionable (e.g. no suitable index / LIMIT without ORDER BY constraints), or permission issues.","commonSituations":"Typos in the query string; schema drift after the query was written; using a query with constructs Spanner disallows for partitioning; IAM restrictions on the worker.","solutions":["Inspect the formatted Spanner error in the panic message and fix the SQL.","Test the query directly with gcloud or the Spanner Studio to confirm it is valid and partitionable.","Simplify to a full-table scan or add an appropriate index for partitioned reads.","Verify the tables/columns exist in the target database (schema drift check)."],"exampleFix":"// before\nquery := \"SELECT * FROM userss\" // typo\n// after\nquery := \"SELECT * FROM users\"","handlingStrategy":"try-catch","validationCode":"// pre-flight: run the query outside Beam to confirm validity/partitionability\n_, err := client.Single().Query(ctx, spanner.Statement{SQL: query}).Next()\nif err != nil {\n    return fmt.Errorf(\"query invalid: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if s, ok := r.(string); ok && strings.Contains(s, \"unable to partition query\") {\n            // log s, fix SQL, restart pipeline\n        } else { panic(r) }\n    }\n}()","preventionTips":["Test the exact SQL against the target database before launching the pipeline.","Avoid LIMIT-without-ORDER-BY and other constructs Spanner cannot partition.","Watch for schema drift; validate table/column names in CI.","Keep the query simple (single-table scan) for best partitionability."],"tags":["go","apache-beam","spanner","panic","sql","gcp"],"backgroundTag":"sql-query-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"}