t8y2/dbx · error · SQLException

Object source requires database context for Hive/Inceptor ro

Error message

Object source requires database context for Hive/Inceptor routines

What it means

For Hive/Inceptor routine sources the plugin resolves the containing database by trying a candidate list built from the database and schema arguments; if both are empty/null there is no database context, and since Hive catalog queries are database-qualified, the lookup cannot proceed and is aborted up front. This is a fail-fast guard before any SQL is issued.

Source

Thrown at plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java:3996

        if (isHive2RoutinesConnection(connection)) {
            String routineName = stripRoutineSignature(name);
            String normalizedType = normalizeObjectType(objectType);
            if ("VIEW".equals(normalizedType) || "TABLE".equals(normalizedType) || "MATERIALIZED_VIEW".equals(normalizedType)) {
                return hive2ShowCreateObjectSource(conn, database, schema, name, objectType);
            }

            LinkedHashSet<String> candidates = new LinkedHashSet<>();
            String db = emptyToNull(database);
            if (db != null) {
                candidates.add(db);
            }
            String sc = emptyToNull(schema);
            if (sc != null) {
                candidates.add(sc);
            }
            if (candidates.isEmpty()) {
                throw new SQLException("Object source requires database context for Hive/Inceptor routines");
            }

            for (String candidateDb : candidates) {
                String sql;
                if ("PROCEDURE".equals(normalizedType)) {
                    sql = "SELECT full_text FROM system.procedures_v " +
                        "WHERE lower(database_name) = lower(?) AND procedure_name = ?";
                } else if ("FUNCTION".equals(normalizedType)) {
                    sql = "SELECT full_text FROM system.functions_v " +
                        "WHERE lower(database_name) = lower(?) AND function_name = ?";
                } else {
                    throw new SQLException("Unsupported object_type for Hive/Inceptor routine source: " + objectType);
                }

                try (PreparedStatement ps = conn.prepareStatement(sql)) {
                    ps.setString(1, candidateDb);
                    ps.setString(2, routineName);
                    try (ResultSet rs = ps.executeQuery()) {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Pass the database (or schema) argument when requesting a routine's source
  2. Run SHOW DATABASES / list RPCs to find the owning database and supply it
  3. Set a default database on the connection if the routine lives in it and the API supports database inheritance

Example fix

// before
objectSource(connection, null, null, "my_func", "FUNCTION");
// after
objectSource(connection, "sales", null, "my_func", "FUNCTION");
Defensive patterns

Strategy: validation

Validate before calling

if ((database == null || database.isBlank()) && (schema == null || schema.isBlank())) {
    throw new IllegalArgumentException("database or schema is required for Hive/Inceptor routine source");
}
rpc.objectSource(database, schema, routineName, "FUNCTION");

Type guard

static boolean hasText(String s) { return s != null && !s.isBlank(); }
boolean hasDbContext = hasText(database) || hasText(schema);

Try / catch

try {
    JsonNode src = rpc.objectSource(db, schema, name, type);
} catch (SQLException e) {
    if (e.getMessage().contains("requires database context")) {
        // prompt user / resolve db via SHOW DATABASES then retry
    } else throw e;
}

Prevention

When it happens

Trigger: Requesting a PROCEDURE or FUNCTION source with neither database nor schema populated (both null or empty strings), so hive2DatabaseCandidates yields an empty candidate set.

Common situations: Client omits the database field because the routine name looked globally unique; older API clients that only send a name; connection configured without a default database.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/3ad1830cb3b12351. Report an issue: GitHub.