{"record":{"id":"46009f16580caa84","repo":"OtterMind/Chat2DB","slug":"hive-index-requires-at-least-one-named-column","errorCode":null,"errorMessage":"Hive index requires at least one named column","messagePattern":"Hive index requires at least one named column","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-hive/src/main/java/ai/chat2db/plugin/hive/enums/type/HiveIndexTypeEnum.java","lineNumber":98,"sourceCode":"\n        return script.toString();\n    }\n\n    private String buildIndexComment(TableIndex tableIndex) {\n        if(StringUtils.isBlank(tableIndex.getComment())){\n            return \"\";\n        }else {\n            return StringUtils.join(SQL_COMMENT, HiveIdentifierProcessor.INSTANCE.escapeString(tableIndex.getComment()),\"'\");\n        }\n\n    }\n\n    private String buildIndexColumn(TableIndex tableIndex) {\n        StringBuilder script = new StringBuilder();\n        script.append(\"(\");\n        boolean appended = false;\n        if (tableIndex.getColumnList() == null) {\n            throw new IllegalArgumentException(\"Hive index requires at least one named column\");\n        }\n        for (TableIndexColumn column : tableIndex.getColumnList()) {\n            if(StringUtils.isNotBlank(column.getColumnName())) {\n                script.append(HiveIdentifierProcessor.INSTANCE.quoteIdentifierAlways(column.getColumnName()));\n                if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {\n                    script.append(\" \").append(HiveSqlGuards.requireAscOrDesc(column.getAscOrDesc()));\n                }\n                script.append(\",\");\n                appended = true;\n            }\n        }\n        if (!appended) {\n            throw new IllegalArgumentException(\"Hive index requires at least one named column\");\n        }\n        script.deleteCharAt(script.length() - 1);\n        script.append(\")\");\n        return script.toString();\n    }","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-hive/src/main/java/ai/chat2db/plugin/hive/enums/type/HiveIndexTypeEnum.java#L80-L116","documentation":"Thrown in HiveIndexTypeEnum.buildIndexColumn when tableIndex.getColumnList() is null. The builder cannot construct an index with no column list at all, so it fails fast rather than producing malformed SQL.","triggerScenarios":"Calling buildIndexScript/buildModifyIndex on a Hive TableIndex whose columnList was never set (null). Common when constructing an index object programmatically without initializing its columns.","commonSituations":"A new TableIndex created via constructor/default with no setColumnList(...); deserialization producing a null columnList; copying an index shell for templating.","solutions":["Always initialize TableIndex.columnList (even to an empty list) before building Hive index DDL.","Guard callers: skip indexes whose columnList is null.","In the model factory, default columnList to Collections.emptyList()."],"exampleFix":"// before\nTableIndex idx = new TableIndex();\nidx.setColumnList(null);\nhiveIndexTypeEnum.buildIndexScript(idx);\n\n// after\nTableIndex idx = new TableIndex();\nidx.setColumnList(new ArrayList<>()); // non-null, then ensure at least one named column\nidx.getColumnList().add(namedColumn);","handlingStrategy":"validation","validationCode":"static boolean hasColumnList(TableIndex idx) {\n    return idx != null && idx.getColumnList() != null;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always initialize TableIndex.columnList (even to an empty list).","Skip indexes with null columnList at the caller boundary.","Default columnList to Collections.emptyList() in the model factory."],"tags":["hive","ddl","index","null-check","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}