{"record":{"id":"16b7d07613c21442","repo":"apache/seatunnel","slug":"template-must-contain-create-table-statement","errorCode":null,"errorMessage":"Template must contain CREATE TABLE statement","messagePattern":"Template must contain CREATE TABLE statement","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":159,"sourceCode":"            String partitionClause = matcher.group(1);\n            // Extract field names (basic parsing)\n            return java.util.Arrays.stream(partitionClause.split(\",\"))\n                    .map(field -> field.trim().split(\"\\\\s+\")[0].replaceAll(\"`\", \"\"))\n                    .collect(Collectors.toList());\n        }\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(","sourceCodeStart":141,"sourceCodeEnd":177,"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#L141-L177","documentation":"IllegalArgumentException thrown by HiveTableTemplateUtils.validateTemplate when the template does not contain the required \"CREATE TABLE\" statement (case-insensitive check). The template must be a full DDL that creates a Hive table.","triggerScenarios":"Passing a partial DDL (e.g. only column list or INSERT statement), a SELECT query, or a DDL with different casing/wording like \"CREATE EXTERNAL TABLE\" is fine but \"CREATE VIEW\" or missing statement fails.","commonSituations":"Users copying only the column definitions into the template; using a wrong doc example; template accidentally truncated when embedded in a HOCON config (unescaped quotes/newlines).","solutions":["Ensure the template is a complete DDL starting with CREATE TABLE (EXTERNAL allowed)","Verify the template survived config parsing intact (quotes/escaping)","Use the built-in default template as a starting point and modify columns/LOCATION","Call validateTemplate(template) during config parsing to fail early with this clear message"],"exampleFix":"// before\nhive.table-create-template = \"${database}.${table} (id int)\"\n// after\nhive.table-create-template = \"CREATE TABLE ${database}.${table} (id int) WITH ('format'='json')\"","handlingStrategy":"validation","validationCode":"if (!template.toUpperCase().contains(\"CREATE TABLE\")) { throw new IllegalArgumentException(\"template must be a CREATE TABLE DDL\"); }","typeGuard":"boolean isCreateTableDdl = template != null && template.toUpperCase(Locale.ROOT).contains(\"CREATE TABLE\");","tryCatchPattern":"try { validateTemplate(template); } catch (IllegalArgumentException e) { /* fix template to include CREATE TABLE */ }","preventionTips":["Start from the built-in default template","Beware HOCON escaping of quotes/newlines in DDL","Test template rendering once in a local job","Keep full DDL, not just column lists"],"tags":["hive","template","ddl"],"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"}