{"record":{"id":"e3310a718818396a","repo":"t8y2/dbx","slug":"object-source-requires-database-context-for-hive-i-e3310a","errorCode":null,"errorMessage":"Object source requires database context for Hive/Inceptor objects","messagePattern":"Object source requires database context for Hive/Inceptor objects","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java","lineNumber":4110,"sourceCode":"                item.put(\"ref_column\", refColumn);\n                result.add(item);\n            }\n        } catch (SQLException | AbstractMethodError | UnsupportedOperationException ignored) {\n            // Foreign keys are optional detail; generic DDL must still succeed.\n        }\n        return result;\n    }\n\n    private static JsonNode hive2ShowCreateObjectSource(\n        Connection conn,\n        String database,\n        String schema,\n        String name,\n        String objectType\n    ) throws SQLException {\n        LinkedHashSet<String> candidates = hive2DatabaseCandidates(database, schema);\n        if (candidates.isEmpty()) {\n            throw new SQLException(\"Object source requires database context for Hive/Inceptor objects\");\n        }\n\n        SQLException lastError = null;\n        for (String candidateSchema : candidates) {\n            String sql = \"SHOW CREATE TABLE \" + qualifiedHiveName(candidateSchema, name);\n            try (Statement statement = conn.createStatement();\n                 ResultSet rs = statement.executeQuery(sql)) {\n                StringBuilder source = new StringBuilder();\n                while (rs.next()) {\n                    String line = rs.getString(1);\n                    if (line == null || line.isBlank()) {\n                        continue;\n                    }\n                    if (!source.isEmpty()) {\n                        source.append('\\n');\n                    }\n                    source.append(line);\n                }","sourceCodeStart":4092,"sourceCodeEnd":4128,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/plugins/jdbc/src/main/java/app/dbx/jdbc/DbxJdbcPlugin.java#L4092-L4128","documentation":"For Hive/Inceptor table/view objects the source is obtained with SHOW CREATE TABLE <db>.<name>; the qualified name requires a database, built from the database/schema arguments. If both are empty the candidate set is empty and the plugin throws before issuing any SQL, because an unqualified SHOW CREATE TABLE would resolve against an arbitrary default database.","triggerScenarios":"Requesting a Hive table or view source with both database and schema empty/null.","commonSituations":"Client UI omitted the database field; connection has no USE <db> default; API caller assumed name alone is unique across the metastore.","solutions":["Supply the database (or schema) argument identifying the table's database","Find the owning database via SHOW TABLES across candidate databases","Configure a default database on the connection if supported"],"exampleFix":"// before\nobjectSource(conn, null, null, \"events\", \"TABLE\");\n// after\nobjectSource(conn, \"tracking\", null, \"events\", \"TABLE\");","handlingStrategy":"validation","validationCode":"if ((database == null || database.isBlank()) && (schema == null || schema.isBlank())) {\n    throw new IllegalArgumentException(\"database or schema is required for Hive/Inceptor object source\");\n}","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, \"TABLE\");\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"requires database context\")) {\n        // resolve db via SHOW TABLES across databases, then retry\n    } else throw e;\n}","preventionTips":["Always pass the Hive database for table/view source requests","Set a connection default database when users work in one db","Derive database from browse RPC listings, not free text","Validate non-empty database/schema client-side before RPC"],"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-14T00:17:10.932Z"}