{"record":{"id":"3ad1830cb3b12351","repo":"t8y2/dbx","slug":"object-source-requires-database-context-for-hive-i","errorCode":null,"errorMessage":"Object source requires database context for Hive/Inceptor routines","messagePattern":"Object source requires database context for Hive/Inceptor routines","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java","lineNumber":3996,"sourceCode":"\n        if (isHive2RoutinesConnection(connection)) {\n            String routineName = stripRoutineSignature(name);\n            String normalizedType = normalizeObjectType(objectType);\n            if (\"VIEW\".equals(normalizedType) || \"TABLE\".equals(normalizedType) || \"MATERIALIZED_VIEW\".equals(normalizedType)) {\n                return hive2ShowCreateObjectSource(conn, database, schema, name, objectType);\n            }\n\n            LinkedHashSet<String> candidates = new LinkedHashSet<>();\n            String db = emptyToNull(database);\n            if (db != null) {\n                candidates.add(db);\n            }\n            String sc = emptyToNull(schema);\n            if (sc != null) {\n                candidates.add(sc);\n            }\n            if (candidates.isEmpty()) {\n                throw new SQLException(\"Object source requires database context for Hive/Inceptor routines\");\n            }\n\n            for (String candidateDb : candidates) {\n                String sql;\n                if (\"PROCEDURE\".equals(normalizedType)) {\n                    sql = \"SELECT full_text FROM system.procedures_v \" +\n                        \"WHERE lower(database_name) = lower(?) AND procedure_name = ?\";\n                } else if (\"FUNCTION\".equals(normalizedType)) {\n                    sql = \"SELECT full_text FROM system.functions_v \" +\n                        \"WHERE lower(database_name) = lower(?) AND function_name = ?\";\n                } else {\n                    throw new SQLException(\"Unsupported object_type for Hive/Inceptor routine source: \" + objectType);\n                }\n\n                try (PreparedStatement ps = conn.prepareStatement(sql)) {\n                    ps.setString(1, candidateDb);\n                    ps.setString(2, routineName);\n                    try (ResultSet rs = ps.executeQuery()) {","sourceCodeStart":3978,"sourceCodeEnd":4014,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java#L3978-L4014","documentation":"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.","triggerScenarios":"Requesting a PROCEDURE or FUNCTION source with neither database nor schema populated (both null or empty strings), so hive2DatabaseCandidates yields an empty candidate set.","commonSituations":"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.","solutions":["Pass the database (or schema) argument when requesting a routine's source","Run SHOW DATABASES / list RPCs to find the owning database and supply it","Set a default database on the connection if the routine lives in it and the API supports database inheritance"],"exampleFix":"// before\nobjectSource(connection, null, null, \"my_func\", \"FUNCTION\");\n// after\nobjectSource(connection, \"sales\", null, \"my_func\", \"FUNCTION\");","handlingStrategy":"validation","validationCode":"if ((database == null || database.isBlank()) && (schema == null || schema.isBlank())) {\n    throw new IllegalArgumentException(\"database or schema is required for Hive/Inceptor routine source\");\n}\nrpc.objectSource(database, schema, routineName, \"FUNCTION\");","typeGuard":"static boolean hasText(String s) { return s != null && !s.isBlank(); }\nboolean hasDbContext = hasText(database) || hasText(schema);","tryCatchPattern":"try {\n    JsonNode src = rpc.objectSource(db, schema, name, type);\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"requires database context\")) {\n        // prompt user / resolve db via SHOW DATABASES then retry\n    } else throw e;\n}","preventionTips":["Never omit database/schema when targeting Hive/Inceptor routines","Set a default database on the connection where supported","Resolve owning database from browse RPCs before requesting source","Validate required fields in client code before sending the request"],"tags":["jdbc","hive","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}