apache/beam · error · java.lang.Exception

ResultSetMetaData is null

Error message

ResultSetMetaData is null

What it means

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.

Source

Thrown at sdks/java/io/singlestore/src/main/java/org/apache/beam/sdk/io/singlestore/SingleStoreIO.java:803

      DataSourceConfiguration.populateDisplayData(getDataSourceConfiguration(), builder);
      builder.addIfNotNull(DisplayData.item("query", getQuery()));
      builder.addIfNotNull(DisplayData.item("table", getTable()));
      builder.addIfNotNull(
          DisplayData.item("rowMapper", SingleStoreUtil.getClassNameOrNull(getRowMapper())));
    }
  }

  private static ResultSetMetaData getResultSetMetadata(
      DataSourceConfiguration dataSourceConfiguration, String query) throws Exception {
    DataSource dataSource = dataSourceConfiguration.getDataSource();
    Connection conn = dataSource.getConnection();
    try {
      PreparedStatement stmt =
          conn.prepareStatement(String.format("SELECT * FROM (%s) LIMIT 0", query));
      try {
        ResultSetMetaData md = stmt.getMetaData();
        if (md == null) {
          throw new Exception("ResultSetMetaData is null");
        }

        return md;
      } finally {
        stmt.close();
      }
    } finally {
      conn.close();
    }
  }

  /**
   * A {@link PTransform} for writing data to SingleStoreDB. It is used by {@link
   * SingleStoreIO#write()}.
   */
  @AutoValue
  public abstract static class Write<T> extends PTransform<PCollection<T>, PCollection<Integer>> {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Verify the query passed to withQuery() is valid, non-empty, fully-bound SQL
  2. Test the same query with a plain JDBC client to confirm the driver can prepare it
  3. Upgrade the SingleStore JDBC driver if it returns null metadata for prepared SELECT statements
  4. Provide an explicit schema/coder instead of relying on inference if the query cannot be described

Example fix

// before
SingleStoreIO.<Row>read().withQuery("") // blank query -> null metadata -> throws
// after
SingleStoreIO.<Row>read().withQuery("SELECT id, name FROM sales.orders")
Defensive patterns

Strategy: validation

Validate before calling

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")

Try / catch

try { Schema schema = SingleStoreIO.inferSchema(...); } catch (Exception e) { if (e.getMessage().contains("ResultSetMetaData is null")) { /* supply explicit schema */ } throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/062e49b4d1e8d317. Report an issue: GitHub.