{"record":{"id":"4124f5c4d0e2d7b0","repo":"apache/druid","slug":"unable-to-access-specific-metadata-from-result-set","errorCode":null,"errorMessage":"Unable to access specific metadata from result set metadata","messagePattern":"Unable to access specific metadata from result set metadata","errorType":"exception","errorClass":"ResultSetException","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/metadata/input/SqlEntity.java","lineNumber":150,"sourceCode":"                (index, r, ctx) -> {\n                  Map<String, Object> resultRow = foldCase ? new CaseFoldedMap() : new HashMap<>();\n                  ResultSetMetaData resultMetadata;\n                  try {\n                    resultMetadata = r.getMetaData();\n                  }\n                  catch (SQLException e) {\n                    throw new ResultSetException(\"Unable to obtain metadata from result set\", e, ctx);\n                  }\n                  try {\n                    for (int i = 1; i <= resultMetadata.getColumnCount(); i++) {\n                      String key = resultMetadata.getColumnName(i);\n                      String alias = resultMetadata.getColumnLabel(i);\n                      Object value = r.getObject(i);\n                      resultRow.put(alias != null ? alias : key, value);\n                    }\n                  }\n                  catch (SQLException e) {\n                    throw new ResultSetException(\"Unable to access specific metadata from \" +\n                                                 \"result set metadata\", e, ctx);\n                  }\n                  return resultRow;\n                }\n            ).iterator();\n            jg.writeStartArray();\n            while (resultIterator.hasNext()) {\n              JacksonUtils.writeObjectUsingSerializerProvider(jg, serializers, resultIterator.next());\n            }\n            jg.writeEndArray();\n            jg.close();\n            return null;\n          },\n          (exception) -> sqlInputSourceDatabaseConnector.isTransientException(exception)\n                         && !(SQLMetadataConnector.isStatementException(exception))\n      );\n      return new CleanableFile()\n      {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/metadata/input/SqlEntity.java#L132-L168","documentation":"After obtaining ResultSetMetaData, SqlEntity.openCleanableFile() reads each column's name, label, and value inside a loop. Any SQLException thrown while accessing per-column metadata or row values (getColumnName/getColumnLabel/getObject) is wrapped in a ResultSetException with the message 'Unable to access specific metadata from result set metadata'.","triggerScenarios":"A SQLException during row iteration: invalid column index, connection dropped mid-iteration, type conversion failure in getObject(i), or driver refusing column label/name access.","commonSituations":"Large result sets where the connection times out partway through streaming; column aliasing issues with certain drivers returning null labels; driver bugs with specific column types (e.g., complex/JSON types).","solutions":["Inspect the wrapped SQLException cause for the failing column index and fix the query or aliasing.","Check connection stability/timeouts for large result fetches; increase socket and query timeouts.","Avoid exotic column types in the SQL projection that the JDBC driver cannot map via getObject().","Upgrade the JDBC driver if column-label handling is known-buggy."],"exampleFix":"// before\nSELECT weird_json_col FROM table\n// after\nSELECT CAST(weird_json_col AS VARCHAR) AS weird_json_col FROM table","handlingStrategy":"try-catch","validationCode":"// check connection validity and statement state before streaming\nif (!connection.isValid(5)) { reconnect(); }","typeGuard":null,"tryCatchPattern":"try {\n  sqlEntity.fetch(tempDir, buffer);\n} catch (ResultSetException e) {\n  SQLException sql = (SQLException) e.getCause();\n  // log sql.getErrorCode()/getSQLState(); retry with backoff if transient\n}","preventionTips":["Avoid exotic column types in SQL projections","Increase timeouts for large result streams","Use stable column aliases to avoid null-label driver quirks"],"tags":["jdbc","sql","resultset"],"backgroundTag":"database-query-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}