OtterMind/Chat2DB · error · IllegalArgumentException
Invalid DB2 index column ordering: {ascOrDesc}
Error message
Invalid DB2 index column ordering: {ascOrDesc} What it means
Thrown by Db2SqlGuards.requireSortDirection when an index column's sort direction is not ASC or DESC (case-insensitive). The method whitelists only the two legal DB2 index ordering tokens and rejects anything else so a non-escapable value cannot be interpolated into generated CREATE INDEX DDL. This is a fail-closed SQL guard, not a runtime constraint from the DB2 server.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-db2/src/main/java/ai/chat2db/plugin/db2/Db2SqlGuards.java:102
* Validates a fallback column type expression (a type name that does not match
* an enum constant, e.g. {@code VARCHAR(10)}) before it is embedded into
* generated DDL. Returns the type unchanged when it matches the strict shape;
* throws otherwise.
*/
public static String requireColumnTypeExpression(String columnType) {
if (columnType == null || !FALLBACK_COLUMN_TYPE_PATTERN.matcher(columnType).matches()) {
throw new IllegalArgumentException("Invalid DB2 column type: " + columnType);
}
return columnType;
}
/**
* Validates an index column sort direction against the ASC/DESC whitelist.
* Returns the direction unchanged when whitelisted; throws otherwise.
*/
public static String requireSortDirection(String ascOrDesc) {
if (!"ASC".equalsIgnoreCase(ascOrDesc) && !"DESC".equalsIgnoreCase(ascOrDesc)) {
throw new IllegalArgumentException("Invalid DB2 index column ordering: " + ascOrDesc);
}
return ascOrDesc;
}
}
View on GitHub (pinned to 5ee1e990e7)
Solutions
- Normalize ascOrDesc to "ASC"/"DESC" (or blank) before calling the builder so the guard only sees whitelisted tokens.
- If you control the TableIndexColumn, leave ascOrDesc blank/null instead of passing an invalid sentinel like 'A'.
- When reading raw DB2 catalog codes, map 'A'->"ASC", 'D'->"DESC" at the metadata layer rather than forwarding them.
- Wrap the DDL build in try/catch on IllegalArgumentException and report the offending index/column to the user instead of failing the whole build.
Example fix
// before
String dir = indexColumn.getAscOrDesc(); // raw DB2 code 'A' / 'D'
script.append(" ").append(Db2SqlGuards.requireSortDirection(dir));
// after
String dir = indexColumn.getAscOrDesc();
if ("A".equalsIgnoreCase(dir)) dir = "ASC";
else if ("D".equalsIgnoreCase(dir)) dir = "DESC";
if (StringUtils.isNotBlank(dir)) {
script.append(" ").append(Db2SqlGuards.requireSortDirection(dir));
} Defensive patterns
Strategy: validation
Validate before calling
// Run before building DB2 index DDL
static String normalizeDir(String ascOrDesc) {
if (ascOrDesc == null) return null;
String t = ascOrDesc.trim();
if ("A".equalsIgnoreCase(t)) return "ASC";
if ("D".equalsIgnoreCase(t)) return "DESC";
if ("ASC".equalsIgnoreCase(t) || "DESC".equalsIgnoreCase(t)) return t.toUpperCase(Locale.ROOT);
return null; // blank -> skip
} Type guard
// Narrow to a known direction before calling the guard
static boolean isDb2SortDir(String v) {
return v != null && ("ASC".equalsIgnoreCase(v) || "DESC".equalsIgnoreCase(v)
|| "A".equalsIgnoreCase(v) || "D".equalsIgnoreCase(v));
} Prevention
- Map raw DB2 catalog 'A'/'D' codes to ASC/DESC at the metadata import layer.
- Leave ascOrDesc blank when no ordering is needed instead of passing a sentinel.
- Constrain the index-column direction UI to an ASC/DESC/(none) selector.
When it happens
Trigger: Calling Db2SqlGuards.requireSortDirection(ascOrDesc) with a value that is neither "ASC" nor "DESC" (e.g. null, "", "ASCENDING", "NULLS FIRST", or a metadata-derived corrupted string). Indirectly triggered when DB2 index DDL is built for a TableIndex whose column's getAscOrDesc() returns an unexpected token.
Common situations: Importing DB2 index metadata where the SYSCAT.INDEXCOLUSE sort direction column is blank or null; copying an index model from another dialect that used a non-standard ordering; a tool populating TableIndexColumn.ascOrDesc with the raw DB2 'A'/'D' code instead of the spelled-out direction.
Related errors
- Invalid DM index sort direction: {value}
- Invalid Hive index sort direction: {value}
- Unsupported DM VARCHAR unit: {unit}
- Invalid DM BIT literal: {value}
- DM index must contain at least one named column
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/bfe96b45cfc68dbb.
Report an issue: GitHub.