{"record":{"id":"062e49b4d1e8d317","repo":"apache/beam","slug":"resultsetmetadata-is-null","errorCode":null,"errorMessage":"ResultSetMetaData is null","messagePattern":"ResultSetMetaData is null","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":803,"sourceCode":"      DataSourceConfiguration.populateDisplayData(getDataSourceConfiguration(), builder);\n      builder.addIfNotNull(DisplayData.item(\"query\", getQuery()));\n      builder.addIfNotNull(DisplayData.item(\"table\", getTable()));\n      builder.addIfNotNull(\n          DisplayData.item(\"rowMapper\", SingleStoreUtil.getClassNameOrNull(getRowMapper())));\n    }\n  }\n\n  private static ResultSetMetaData getResultSetMetadata(\n      DataSourceConfiguration dataSourceConfiguration, String query) throws Exception {\n    DataSource dataSource = dataSourceConfiguration.getDataSource();\n    Connection conn = dataSource.getConnection();\n    try {\n      PreparedStatement stmt =\n          conn.prepareStatement(String.format(\"SELECT * FROM (%s) LIMIT 0\", query));\n      try {\n        ResultSetMetaData md = stmt.getMetaData();\n        if (md == null) {\n          throw new Exception(\"ResultSetMetaData is null\");\n        }\n\n        return md;\n      } finally {\n        stmt.close();\n      }\n    } finally {\n      conn.close();\n    }\n  }\n\n  /**\n   * A {@link PTransform} for writing data to SingleStoreDB. It is used by {@link\n   * SingleStoreIO#write()}.\n   */\n  @AutoValue\n  public abstract static class Write<T> extends PTransform<PCollection<T>, PCollection<Integer>> {\n","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreIO.java#L785-L821","documentation":"When resolving the schema for a SingleStoreIO read, the connector prepares \"SELECT * FROM (<query>) LIMIT 0\" and reads the statement's ResultSetMetaData to derive the Beam schema. If getMetaData() returns null the driver produced no metadata, and the code throws \"ResultSetMetaData is null\" rather than building a schema from nothing.","triggerScenarios":"Calling SingleStoreIO schema inference (e.g. inferRowSchema/getMetaData path) with a query the driver cannot describe — empty/blank query, invalid SQL, or a driver/statement combination that returns null metadata before execution.","commonSituations":"Placeholder or malformed query strings in withQuery(); queries with parameters that were never bound; driver versions that return null metadata for prepared statements until execution; calling the schema-inference helper directly in tests with a dummy query.","solutions":["Verify the query passed to withQuery() is valid, non-empty, fully-bound SQL","Test the same query with a plain JDBC client to confirm the driver can prepare it","Upgrade the SingleStore JDBC driver if it returns null metadata for prepared SELECT statements","Provide an explicit schema/coder instead of relying on inference if the query cannot be described"],"exampleFix":"// before\nSingleStoreIO.<Row>read().withQuery(\"\") // blank query -> null metadata -> throws\n// after\nSingleStoreIO.<Row>read().withQuery(\"SELECT id, name FROM sales.orders\")","handlingStrategy":"validation","validationCode":"if (query == null || query.trim().isEmpty()) throw new IllegalArgumentException(\"withQuery requires non-empty SQL\"); // also verify it prepares: conn.prepareStatement(\"SELECT * FROM (\" + query + \") LIMIT 0\")","typeGuard":null,"tryCatchPattern":"try { Schema schema = SingleStoreIO.inferSchema(...); } catch (Exception e) { if (e.getMessage().contains(\"ResultSetMetaData is null\")) { /* supply explicit schema */ } throw e; }","preventionTips":["Ensure withQuery() receives fully-bound, valid SQL (no unbound '?')","Dry-run the query through a plain JDBC connection before pipeline launch","Keep the SingleStore JDBC driver up to date; prefer providing explicit schemas for complex queries"],"tags":["java","beam","singlestore","jdbc","metadata"],"backgroundTag":"unexpected-response-shape","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}