{"record":{"id":"1c0a7cfee2bdd393","repo":"apache/seatunnel","slug":"template-must-contain-database-and-table-var","errorCode":null,"errorMessage":"Template must contain ${database} and ${table} variables","messagePattern":"Template must contain (.+?) and (.+?) variables","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveTableTemplateUtils.java","lineNumber":164,"sourceCode":"        }\n\n        return java.util.Collections.emptyList();\n    }\n\n    /** Validate template syntax (basic validation) */\n    public static void validateTemplate(String template) {\n        if (template == null || template.trim().isEmpty()) {\n            throw new IllegalArgumentException(\"Template cannot be null or empty\");\n        }\n\n        // Check for required CREATE TABLE statement\n        if (!template.toUpperCase().contains(\"CREATE TABLE\")) {\n            throw new IllegalArgumentException(\"Template must contain CREATE TABLE statement\");\n        }\n\n        // Check for required variables\n        if (!template.contains(\"${database}\") || !template.contains(\"${table}\")) {\n            throw new IllegalArgumentException(\n                    \"Template must contain ${database} and ${table} variables\");\n        }\n    }\n\n    /** Extract LOCATION path from template. If it contains ${table_location}, replace it. */\n    public static String extractLocationFromTemplate(\n            String template, String database, String table) {\n        if (template == null) {\n            return null;\n        }\n        String patternStr = \"LOCATION\\\\s+'([^']+)'\";\n        java.util.regex.Pattern pattern =\n                java.util.regex.Pattern.compile(\n                        patternStr, java.util.regex.Pattern.CASE_INSENSITIVE);\n        java.util.regex.Matcher matcher = pattern.matcher(template);\n        if (matcher.find()) {\n            String raw = matcher.group(1);\n            String defaultLocation = getDefaultTableLocation(database, table);","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-hive/src/main/java/org/apache/seatunnel/connectors/seatunnel/hive/utils/HiveTableTemplateUtils.java#L146-L182","documentation":"IllegalArgumentException thrown by HiveTableTemplateUtils.validateTemplate when the template lacks the required ${database} and/or ${table} placeholder variables. These placeholders are substituted at runtime to build the fully qualified table name in the generated CREATE TABLE SQL.","triggerScenarios":"Template hardcodes a table name instead of using ${database}/${table}; typos like {database} or $database without braces; template that only contains CREATE TABLE but no variables.","commonSituations":"Users writing a fixed table name in a copied DDL; brace-stripping by config templating systems (e.g. envsubst, HOCON substitution consuming ${...}); editing the default template and deleting placeholders.","solutions":["Add both ${database} and ${table} placeholders to the template","Escape/protect ${...} if your config layer performs its own variable substitution","Compare against the built-in default template and restore missing placeholders","Run validateTemplate during startup to catch this before job execution"],"exampleFix":"// before\nhive.table-create-template = \"CREATE TABLE my_db.my_table (id int)\"\n// after\nhive.table-create-template = \"CREATE TABLE ${database}.${table} (id int)\"","handlingStrategy":"validation","validationCode":"if (!template.contains(\"${database}\") || !template.contains(\"${table}\")) { throw new IllegalArgumentException(\"template must contain ${database} and ${table}\"); }","typeGuard":"boolean hasPlaceholders = template != null && template.contains(\"${database}\") && template.contains(\"${table}\");","tryCatchPattern":"try { validateTemplate(template); } catch (IllegalArgumentException e) { /* add ${database}/${table} placeholders */ }","preventionTips":["Never hardcode table names; always use ${database}.${table}","Escape ${...} if the config layer does its own substitution","Keep placeholders intact when editing default templates","Run validateTemplate in unit tests for shipped templates"],"tags":["hive","template","placeholders"],"backgroundTag":"schema-validation-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}