{"record":{"id":"64ee1af4dec08190","repo":"OtterMind/Chat2DB","slug":"snowflake-index-requires-at-least-one-named-column","errorCode":null,"errorMessage":"Snowflake index requires at least one named column","messagePattern":"Snowflake index requires at least one named column","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-snowflake/src/main/java/ai/chat2db/plugin/snowflake/enums/type/SnowflakeIndexTypeEnum.java","lineNumber":108,"sourceCode":"\n    }\n\n    private String buildIndexColumn(TableIndex tableIndex) {\n        StringBuilder script = new StringBuilder();\n        script.append(\"(\");\n        boolean appended = false;\n        for (TableIndexColumn column : tableIndex.getColumnList()) {\n            if(StringUtils.isNotBlank(column.getColumnName())) {\n                script.append(SnowflakeIdentifierProcessor.INSTANCE.quoteIdentifierAlways(column.getColumnName()));\n                if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {\n                    script.append(\" \").append(SnowflakeSqlGuards.requireAscOrDesc(column.getAscOrDesc()));\n                }\n                script.append(\",\");\n                appended = true;\n            }\n        }\n        if (!appended) {\n            throw new IllegalArgumentException(\"Snowflake index requires at least one named column\");\n        }\n        script.deleteCharAt(script.length() - 1);\n        script.append(\")\");\n        return script.toString();\n    }\n\n    private String buildIndexName(TableIndex tableIndex) {\n        if(this.equals(PRIMARY_KEY)){\n            return \"\";\n        }else {\n            return SnowflakeIdentifierProcessor.INSTANCE.quoteIdentifierAlways(tableIndex.getName());\n        }\n    }\n\n    public String buildModifyIndex(TableIndex tableIndex) {\n        if (EditStatusEnum.DELETE.name().equals(tableIndex.getEditStatus())) {\n            return buildDropIndex(tableIndex);\n        }","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-snowflake/src/main/java/ai/chat2db/plugin/snowflake/enums/type/SnowflakeIndexTypeEnum.java#L90-L126","documentation":"Thrown by SnowflakeIndexTypeEnum.buildIndexColumn when, after iterating every TableIndexColumn in tableIndex.getColumnList(), none had a non-blank columnName. The builder appends quoted column names inside the parentheses; if nothing was appended it cannot safely delete the trailing comma, so it fails closed.","triggerScenarios":"Invoking buildIndexScript (transitively via CREATE TABLE index handling) on a TableIndex whose columnList is empty, or whose every column has a null/blank getColumnName().","commonSituations":"A frontend sends an index object before the user has added any columns; metadata load produced an index with column references stripped; an expression-only index whose 'column' is stored in a field other than columnName.","solutions":["Ensure tableIndex.getColumnList() contains at least one entry with a non-blank columnName before building the DDL.","Guard in the UI/API to reject index save when no columns are selected.","Skip building (continue) when columnList is empty, mirroring the blank-name/blank-type skip already in the CREATE path."],"exampleFix":"// before\nindex.setColumnList(Collections.emptyList());\n// -> Snowflake index requires at least one named column\n\n// after\nList<TableIndexColumn> cols = new ArrayList<>();\nTableIndexColumn c = new TableIndexColumn();\nc.setColumnName(\"id\");\ncols.add(c);\nindex.setColumnList(cols);","handlingStrategy":"validation","validationCode":"// Ensure at least one named column before building the index\nboolean hasNamed = tableIndex.getColumnList() != null\n    && tableIndex.getColumnList().stream()\n        .anyMatch(c -> StringUtils.isNotBlank(c.getColumnName()));\nif (!hasNamed) {\n    throw new IllegalArgumentException(\"Index has no named columns\");\n}","typeGuard":"static boolean indexHasNamedColumn(TableIndex idx) {\n    return idx.getColumnList() != null && idx.getColumnList().stream()\n        .anyMatch(c -> StringUtils.isNotBlank(c.getColumnName()));\n}","tryCatchPattern":null,"preventionTips":["Reject empty-column indexes at the UI/API boundary.","Skip index DDL generation when columnList is empty.","Confirm metadata loads resolve index column names."],"tags":["snowflake","ddl","index","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}