{"record":{"id":"5ab6198f354be0df","repo":"OtterMind/Chat2DB","slug":"invalid-hive-index-sort-direction-value","errorCode":null,"errorMessage":"Invalid Hive index sort direction: {value}","messagePattern":"Invalid Hive index sort direction: (.+?)","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/HiveSqlGuards.java","lineNumber":102,"sourceCode":"        if (columns.isEmpty()) {\n            throw invalid(\"partition clause\", value);\n        }\n        scanTypeExpression(declaration, \"partition clause\", true);\n        return prefix + \" (\" + columns + \")\";\n    }\n\n    /**\n     * Validate an index sort direction: only ASC/DESC are legal, returned in canonical uppercase.\n     */\n    public static String requireAscOrDesc(String value) {\n        String trimmed = StringUtils.trimToEmpty(value);\n        if (\"ASC\".equalsIgnoreCase(trimmed)) {\n            return \"ASC\";\n        }\n        if (\"DESC\".equalsIgnoreCase(trimmed)) {\n            return \"DESC\";\n        }\n        throw new IllegalArgumentException(\"Invalid Hive index sort direction: \" + value);\n    }\n\n    private static void scanTypeExpression(String expression, String description, boolean requireRootParentheses) {\n        Deque<Character> delimiters = new ArrayDeque<>();\n        List<String> rootWords = new ArrayList<>();\n        boolean sawName = false;\n        for (int i = 0; i < expression.length(); i++) {\n            char c = expression.charAt(i);\n            if (c == '`') {\n                i = scanBacktickQuoted(expression, i, description);\n                sawName = true;\n                continue;\n            }\n            if (startsWith(expression, i, \"--\") || startsWith(expression, i, \"/*\")\n                    || startsWith(expression, i, \"*/\") || c == ';' || c == '\\n' || c == '\\r'\n                    || Character.isISOControl(c)) {\n                throw invalid(description, expression);\n            }","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-hive/src/main/java/ai/chat2db/plugin/hive/HiveSqlGuards.java#L84-L120","documentation":"Thrown by HiveSqlGuards.requireAscOrDesc when an index sort direction is neither ASC nor DESC. The method canonicalizes to uppercase and is called from HiveIndexTypeEnum.buildIndexColumn for non-PRIMARY_KEY indexes.","triggerScenarios":"Calling requireAscOrDesc(value) with a non-ASC/DESC token, or building a Hive non-primary index whose column.ascOrDesc is an invalid direction string.","commonSituations":"Hive index metadata imported with a blank-but-non-null direction containing whitespace; a model copied from a dialect using 'A'/'D' codes; UI defaulting direction to a placeholder.","solutions":["Set ascOrDesc to \"ASC\", \"DESC\", or leave it blank (the caller skips blank values).","Map short codes to ASC/DESC at the import boundary.","For primary-key indexes the direction check is skipped; set the index type to PRIMARY_KEY when direction validation should not apply."],"exampleFix":"// before\ncolumn.setAscOrDesc(\" \"); // blank-but-not-empty\nHiveSqlGuards.requireAscOrDesc(column.getAscOrDesc());\n\n// after\ncolumn.setAscOrDesc(StringUtils.trimToNull(column.getAscOrDesc())); // null -> skipped","handlingStrategy":"validation","validationCode":"static boolean isHiveDir(String v) {\n    return v != null && (\"ASC\".equalsIgnoreCase(v.trim()) || \"DESC\".equalsIgnoreCase(v.trim()));\n}","typeGuard":"static String hiveDirOrNull(String v) {\n    if (v == null) return null;\n    String t = v.trim();\n    if (\"ASC\".equalsIgnoreCase(t)) return \"ASC\";\n    if (\"DESC\".equalsIgnoreCase(t)) return \"DESC\";\n    return null;\n}","tryCatchPattern":null,"preventionTips":["Set ascOrDesc to ASC/DESC or leave it blank/null.","Use the PRIMARY_KEY index type to bypass the direction check.","Trim whitespace from imported direction values."],"tags":["hive","sql-guard","ddl","index","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}