{"record":{"id":"47464bb122ca6f40","repo":"apache/beam","slug":"failed-to-get-number-of-partitions-in-the-database","errorCode":null,"errorMessage":"Failed to get number of partitions in the database","messagePattern":"Failed to get number of partitions in the database","errorType":"exception","errorClass":"java.lang.Exception","httpStatus":null,"severity":"error","filePath":"sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreIO.java","lineNumber":765,"sourceCode":"        for (long i = range.getFrom(); i < range.getTo(); i++) {\n          receiver.output(new OffsetRange(i, i + 1));\n        }\n      }\n\n      private int getNumPartitions() throws Exception {\n        DataSource dataSource = dataSourceConfiguration.getDataSource();\n        Connection conn = dataSource.getConnection();\n        try {\n          Statement stmt = conn.createStatement();\n          try {\n            ResultSet res =\n                stmt.executeQuery(\n                    String.format(\n                        \"SELECT num_partitions FROM information_schema.DISTRIBUTED_DATABASES WHERE database_name = %s\",\n                        SingleStoreUtil.escapeString(database)));\n            try {\n              if (!res.next()) {\n                throw new Exception(\"Failed to get number of partitions in the database\");\n              }\n\n              return res.getInt(1);\n            } finally {\n              res.close();\n            }\n          } finally {\n            stmt.close();\n          }\n        } finally {\n          conn.close();\n        }\n      }\n    }\n\n    @Override\n    public void populateDisplayData(DisplayData.Builder builder) {\n      super.populateDisplayData(builder);","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreIO.java#L747-L783","documentation":"SingleStoreIO's partitioned read resolves the number of store partitions by querying information_schema.DISTRIBUTED_DATABASES for the target database. If the query returns no rows, the code cannot determine partition count and throws \"Failed to get number of partitions in the database\", aborting split planning.","triggerScenarios":"SingleStoreIO.read().withPartitions() (partition discovery) against a database that has no row in information_schema.DISTRIBUTED_DATABASES — typically when the configured database name doesn't exist, is misspelled, or points to a single-node/non-distributed database.","commonSituations":"Typos in the database name in SingleStoreIO.Read config; connecting to a single-store (non-distributed) deployment; running against a different cluster than intended via connection URL; insufficient privileges make the view appear empty.","solutions":["Verify the database name in the read configuration matches an existing distributed database","Run SELECT num_partitions FROM information_schema.DISTRIBUTED_DATABASES manually with the same credentials to confirm a row exists","Check the JDBC URL points at the intended SingleStore cluster","If the DB is genuinely not distributed, use a non-partitioned read instead of withPartitions()"],"exampleFix":"// before\nSingleStoreIO.<Row>read().withDataSourceConfiguration(cfg)\n    .withQuery(\"SELECT * FROM mydb.t\")\n    .withPartitions() // database 'mydb' misnamed -> throws\n// after\nSingleStoreIO.<Row>read().withDataSourceConfiguration(cfg)\n    .withQuery(\"SELECT * FROM sales.t\") // 'sales' exists in DISTRIBUTED_DATABASES\n    .withPartitions()","handlingStrategy":"validation","validationCode":"try (Connection c = DriverManager.getConnection(url, user, pass); Statement s = c.createStatement(); ResultSet r = s.executeQuery(\"SELECT num_partitions FROM information_schema.DISTRIBUTED_DATABASES WHERE database_name = '\" + db + \"'\")) { if (!r.next()) throw new IllegalStateException(\"DB not distributed or missing: \" + db); }","typeGuard":null,"tryCatchPattern":"try { pipeline.apply(SingleStoreIO.read().withPartitions()...); } catch (Exception e) { if (e.getMessage().contains(\"Failed to get number of partitions\")) { /* fall back to non-partitioned read */ } throw e; }","preventionTips":["Confirm the database appears in information_schema.DISTRIBUTED_DATABASES before using withPartitions()","Validate config database names against the live cluster, not hardcoded values","Grant the connector user SELECT on information_schema"],"tags":["java","beam","singlestore","database","partitions"],"backgroundTag":"database-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"}