{"record":{"id":"e0dbae08774056c5","repo":"apache/druid","slug":"please-use-fetch-instead","errorCode":null,"errorMessage":"Please use fetch() instead","messagePattern":"Please use fetch\\(\\) instead","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"server/src/main/java/org/apache/druid/metadata/input/SqlEntity.java","lineNumber":89,"sourceCode":"    this.objectMapper = objectMapper;\n  }\n\n  public String getSql()\n  {\n    return sql;\n  }\n\n  @Nullable\n  @Override\n  public URI getUri()\n  {\n    return null;\n  }\n\n  @Override\n  public InputStream openRaw()\n  {\n    throw new UnsupportedOperationException(\"Please use fetch() instead\");\n  }\n\n  @Override\n  public CleanableFile fetch(File temporaryDirectory, byte[] fetchBuffer) throws IOException\n  {\n    final File tempFile = File.createTempFile(\"druid-sql-entity\", \".tmp\", temporaryDirectory);\n    return openCleanableFile(sql, sqlInputSourceDatabaseConnector, objectMapper, foldCase, tempFile);\n\n  }\n\n  /**\n   * Executes a SQL query on the specified database and fetches the result into the given file.\n   * The result file is deleted if the query execution or the file write fails.\n   *\n   * @param sql                          The SQL query to be executed\n   * @param sqlInputSourceDatabaseConnector The database connector\n   * @param objectMapper                 An object mapper, used for deserialization\n   * @param foldCase                     A boolean flag used to enable or disabling case sensitivity while handling database column names","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/server/src/main/java/org/apache/druid/metadata/input/SqlEntity.java#L71-L107","documentation":"SqlEntity implements Druid's Entity/OpenRawFileSupplier interface, but its data comes from a JDBC ResultSet, so there is no InputStream-backed raw representation. openRaw() therefore unconditionally throws UnsupportedOperationException directing callers to fetch(), which materializes the rows into a temporary file.","triggerScenarios":"Calling openRaw() on a SqlEntity instance — e.g., generic entity-handling code or input-source plumbing that assumes all entities support raw stream access.","commonSituations":"Ingestion framework code written for FileEntity/HttpEntity reused against SQL-based input; custom extensions that call openRaw() without first checking whether the entity supports it.","solutions":["Call fetch(temporaryDirectory, fetchBuffer) instead of openRaw() to obtain a CleanableFile.","Check whether the entity supports raw access before calling openRaw() and branch to fetch() for SqlEntity.","If you control the interface usage, use instanceof SqlEntity to route to the fetch path."],"exampleFix":"// before\nInputStream in = sqlEntity.openRaw();\n// after\nCleanableFile file = sqlEntity.fetch(tempDir, new byte[DEFAULT_FETCH_BUFFER]);","handlingStrategy":"type-guard","validationCode":"if (entity instanceof SqlEntity) {\n  CleanableFile f = ((SqlEntity) entity).fetch(tempDir, buf);\n} else {\n  InputStream in = entity.openRaw();\n}","typeGuard":"boolean supportsRaw(Object e) { return !(e instanceof SqlEntity); }","tryCatchPattern":"try {\n  return entity.openRaw();\n} catch (UnsupportedOperationException e) {\n  return entity.fetch(temporaryDirectory, fetchBuffer).getFile();\n}","preventionTips":["Check the Entity implementation before choosing openRaw vs fetch","Prefer fetch() for SqlEntity always","Document raw-stream support per Entity type in extension code"],"tags":["unsupported-operation","jdbc","input-source"],"backgroundTag":"unsupported-operation","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"}