OtterMind/Chat2DB · error · IllegalArgumentException

Invalid Hive index sort direction: {value}

Error message

Invalid Hive index sort direction: {value}

What it means

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.

Source

Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-hive/src/main/java/ai/chat2db/plugin/hive/HiveSqlGuards.java:102

        if (columns.isEmpty()) {
            throw invalid("partition clause", value);
        }
        scanTypeExpression(declaration, "partition clause", true);
        return prefix + " (" + columns + ")";
    }

    /**
     * Validate an index sort direction: only ASC/DESC are legal, returned in canonical uppercase.
     */
    public static String requireAscOrDesc(String value) {
        String trimmed = StringUtils.trimToEmpty(value);
        if ("ASC".equalsIgnoreCase(trimmed)) {
            return "ASC";
        }
        if ("DESC".equalsIgnoreCase(trimmed)) {
            return "DESC";
        }
        throw new IllegalArgumentException("Invalid Hive index sort direction: " + value);
    }

    private static void scanTypeExpression(String expression, String description, boolean requireRootParentheses) {
        Deque<Character> delimiters = new ArrayDeque<>();
        List<String> rootWords = new ArrayList<>();
        boolean sawName = false;
        for (int i = 0; i < expression.length(); i++) {
            char c = expression.charAt(i);
            if (c == '`') {
                i = scanBacktickQuoted(expression, i, description);
                sawName = true;
                continue;
            }
            if (startsWith(expression, i, "--") || startsWith(expression, i, "/*")
                    || startsWith(expression, i, "*/") || c == ';' || c == '\n' || c == '\r'
                    || Character.isISOControl(c)) {
                throw invalid(description, expression);
            }

View on GitHub (pinned to 5ee1e990e7)

Solutions

  1. Set ascOrDesc to "ASC", "DESC", or leave it blank (the caller skips blank values).
  2. Map short codes to ASC/DESC at the import boundary.
  3. For primary-key indexes the direction check is skipped; set the index type to PRIMARY_KEY when direction validation should not apply.

Example fix

// before
column.setAscOrDesc(" "); // blank-but-not-empty
HiveSqlGuards.requireAscOrDesc(column.getAscOrDesc());

// after
column.setAscOrDesc(StringUtils.trimToNull(column.getAscOrDesc())); // null -> skipped
Defensive patterns

Strategy: validation

Validate before calling

static boolean isHiveDir(String v) {
    return v != null && ("ASC".equalsIgnoreCase(v.trim()) || "DESC".equalsIgnoreCase(v.trim()));
}

Type guard

static String hiveDirOrNull(String v) {
    if (v == null) return null;
    String t = v.trim();
    if ("ASC".equalsIgnoreCase(t)) return "ASC";
    if ("DESC".equalsIgnoreCase(t)) return "DESC";
    return null;
}

Prevention

When it happens

Trigger: Calling requireAscOrDesc(value) with a non-ASC/DESC token, or building a Hive non-primary index whose column.ascOrDesc is an invalid direction string.

Common situations: 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.

Related errors


AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14). Data as JSON: /api/errors/5ab6198f354be0df. Report an issue: GitHub.