apache/druid · error · UnsupportedOperationException

Please use fetch() instead

Error message

Please use fetch() instead

What it means

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.

Solutions

  1. Call fetch(temporaryDirectory, fetchBuffer) instead of openRaw() to obtain a CleanableFile.
  2. Check whether the entity supports raw access before calling openRaw() and branch to fetch() for SqlEntity.
  3. If you control the interface usage, use instanceof SqlEntity to route to the fetch path.

Example fix

// before
InputStream in = sqlEntity.openRaw();
// after
CleanableFile file = sqlEntity.fetch(tempDir, new byte[DEFAULT_FETCH_BUFFER]);
Defensive patterns

Strategy: type-guard

Validate before calling

if (entity instanceof SqlEntity) {
  CleanableFile f = ((SqlEntity) entity).fetch(tempDir, buf);
} else {
  InputStream in = entity.openRaw();
}

Type guard

boolean supportsRaw(Object e) { return !(e instanceof SqlEntity); }

Try / catch

try {
  return entity.openRaw();
} catch (UnsupportedOperationException e) {
  return entity.fetch(temporaryDirectory, fetchBuffer).getFile();
}

Prevention

When it happens

Trigger: Calling openRaw() on a SqlEntity instance — e.g., generic entity-handling code or input-source plumbing that assumes all entities support raw stream access.

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

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/e0dbae08774056c5. Report an issue: GitHub.

Appendix: source

Thrown at server/src/main/java/org/apache/druid/metadata/input/SqlEntity.java:89

    this.objectMapper = objectMapper;
  }

  public String getSql()
  {
    return sql;
  }

  @Nullable
  @Override
  public URI getUri()
  {
    return null;
  }

  @Override
  public InputStream openRaw()
  {
    throw new UnsupportedOperationException("Please use fetch() instead");
  }

  @Override
  public CleanableFile fetch(File temporaryDirectory, byte[] fetchBuffer) throws IOException
  {
    final File tempFile = File.createTempFile("druid-sql-entity", ".tmp", temporaryDirectory);
    return openCleanableFile(sql, sqlInputSourceDatabaseConnector, objectMapper, foldCase, tempFile);

  }

  /**
   * Executes a SQL query on the specified database and fetches the result into the given file.
   * The result file is deleted if the query execution or the file write fails.
   *
   * @param sql                          The SQL query to be executed
   * @param sqlInputSourceDatabaseConnector The database connector
   * @param objectMapper                 An object mapper, used for deserialization
   * @param foldCase                     A boolean flag used to enable or disabling case sensitivity while handling database column names

View on GitHub (pinned to 9b90983fd2)