jiangxt2 commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3450495342
##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -766,7 +912,17 @@ private StringBuilder appendColumnDefinition(JdbcColumn
column, StringBuilder sq
}
static String addIndexDefinition(TableChange.AddIndex addIndex) {
- return String.format("ADD INDEX %s (%s)", addIndex.getName(),
addIndex.getFieldNames()[0][0]);
+ // PRIMARY_KEY and UNIQUE_KEY are table-level concepts in Doris, not
index-level
+ // They should not be added via ALTER TABLE ADD INDEX
+ if (addIndex.getType() == Index.IndexType.PRIMARY_KEY
+ || addIndex.getType() == Index.IndexType.UNIQUE_KEY) {
+ throw new UnsupportedOperationException(
+ "PRIMARY_KEY and UNIQUE_KEY cannot be added via ALTER TABLE ADD
INDEX in Doris");
Review Comment:
This limitation applies to **all Doris versions**, not version-specific.
In Doris, `PRIMARY_KEY` and `UNIQUE_KEY` belong to `KeysType` (table data
model), not `IndexType` (index types). These are two completely separate enum
hierarchies. The `IndexDef.IndexType` enum only contains index types:
```java
// IndexDef.java (all versions: 1.2.x, 3.0.x, 4.0.x)
public enum IndexType {
BITMAP,
INVERTED,
BLOOMFILTER,
NGRAM_BF // 4.0.x adds ANN
}
// KeysType.java (all versions)
public enum KeysType {
DUP_KEYS,
AGG_KEYS,
UNIQUE_KEYS,
PRIMARY_KEYS
}
The ANTLR grammar (DorisParser.g4) also only accepts BITMAP | INVERTED |
NGRAM_BF | ANN in the USING clause — PRIMARY_KEY and UNIQUE_KEY are not valid
index type keywords.
Since PRIMARY_KEY/UNIQUE_KEY are not in the IndexType enum, it's
impossible to construct an IndexDef with these types at the Java compilation
level. The UnsupportedOperationException in addIndexDefinition() is a defensive
guard against invalid SQL generation.
---
That said, I noticed a related issue you also pointed out (comment on line
316): the base validator accepts PRIMARY_KEY + AUTO_INCREMENT, but
appendTableModelKeySql() only emits UNIQUE KEY and silently skips PRIMARY_KEY.
This causes a validation/generation mismatch — a table with PRIMARY_KEY +
AUTO_INCREMENT passes validation but generates DDL without a key declaration. I
will fix this by mapping PRIMARY_KEY to PRIMARY KEY() in the DDL generation as
well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]