You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "jiangxt2 (via GitHub)" <gi...@apache.org> on 2026/06/18 05:21:07 UTC

[PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

jiangxt2 opened a new pull request, #11731:
URL: https://github.com/apache/gravitino/pull/11731

   ## What changes were proposed in this pull request?
   
   ### INDEX Syntax Fix (`DorisTableOperations.java`)
   
   - **PRIMARY_KEY/UNIQUE_KEY filtering**: These are table model keys in Doris, not index-level concepts. Filtered from `appendIndexesSql()` and instead emitted as `UNIQUE KEY(col)` via new `appendTableModelKeySql()` method
   - **USING clause**: Non-key indexes generate `INDEX `name` (`col`) USING <type>` syntax (INVERTED/BITMAP/ANN)
   - **BITMAP → INVERTED fallback**: Doris 4.0.6 removed BITMAP index support; always generate `USING INVERTED` for cross-version compatibility
   - **ANN → VECTOR mapping**: Read direction maps Doris ANN index type to Gravitino VECTOR; write direction generates `USING ANN`
   - **Backtick quoting**: `addIndexDefinition()` and `deleteIndexDefinition()` now quote index names with backticks
   - **Debug guards**: Added `if (LOG.isDebugEnabled())` protection for index logging loops
   
   ### Auto Increment Support (`DorisTableOperations.java`)
   
   - Removed local `validateIncrementCol(JdbcColumn[])` override that hard-rejected all auto-increment columns
   - Delegated to base class `JdbcTableOperations.validateIncrementCol(columns, indexes)` which validates via index metadata
   - Doris-side constraints (UNIQUE_KEYS/DUP_KEYS only, BIGINT type, NOT NULL) enforced by Doris server
   
   ## Does this PR introduce any user-facing change?
   
   Users can now create tables with auto-increment columns and secondary indexes (INVERTED/ANN) through Gravitino on Doris 3.0+.
   
   ## How was this patch tested?
   
   Unit tests in `TestDorisTableOperationsSqlGeneration`:
   - `testCreateTableWithPrimaryKeyIndex`: PRIMARY_KEY filtered from INDEX clause
   - `testCreateTableWithInvertedIndex`: INVERTED index generates `USING INVERTED`
   - `testCreateTableWithBitmapIndex`: BITMAP index generates `USING INVERTED` (fallback)
   - `testMapDorisIndexType`: ANN→VECTOR, BLOOMFILTER→DATA_SKIPPING_BLOOM_FILTER
   - `testCreateTableWithAutoIncrement`: AUTO_INCREMENT + UNIQUE KEY model
   - `testAddIndexDefinition`: ALTER TABLE ADD INDEX with USING clause
   - `testDeleteIndexDefinition`: DROP INDEX with backtick quoting
   
   Integration tests (Doris 4.0.6 and 3.0.6.2):
   - UNIQUE KEY + AUTO_INCREMENT table creation verified
   - ADD INDEX USING INVERTED verified
   - DROP INDEX verified
   
   Related to #11590, #3272


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "zhoukangcn (via GitHub)" <gi...@apache.org>.
zhoukangcn commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3487335404


##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/DorisImageName.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.integration.test.container;
+
+/**
+ * Doris Docker image versions for multi-version integration testing.
+ *
+ * <p>{@link #VERSION_1_2} uses the Gravitino CI all-in-one image (FE + BE in a single image) for
+ * backward-compatible testing against Doris 1.2.x.
+ *
+ * <p>{@link #VERSION_3_0} uses the official Apache Doris split images ({@code apache/doris:fe-3.x}
+ * and {@code apache/doris:be-3.x}). {@link DorisContainer} detects the {@code :fe-} prefix and
+ * automatically derives the corresponding BE image, passing both via compose environment variables.
+ *
+ * @see DorisContainer
+ * @see ContainerSuite#startDorisContainer(DorisImageName)
+ */
+public enum DorisImageName {
+  VERSION_1_2("apache/gravitino-ci:doris-0.1.5"),
+  VERSION_3_0("apache/doris:fe-3.0.6.2"),

Review Comment:
   Can the FE image be used for BE?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4779579919

   Fixed. The CI failure was caused by `CatalogDorisIT` asserting `PRIMARY_KEY` for all indexes — a behavior inherited from the upstream `getIndexes()` which hardcodes `PRIMARY_KEY` regardless of actual index type.
   
   The fix reads the `Index_type` column from `SHOW INDEX` using `ResultSetMetaData` to detect column availability, then maps via `mapDorisIndexType()`:
   
   - `Key_name = "PRIMARY"` → `PRIMARY_KEY`
   - `Index_type = "INVERTED"` → `INVERTED`
   - `Index_type = "BITMAP"` → `INVERTED` (cross-version compat)
   - `Index_type = null` (Doris 1.2.x) → inferred from index name
   
   Also addressed: catch block narrowed to use `ResultSetMetaData` instead of swallowing all `SQLException`, and added index existence assertion in 1.2.x IT.
   
   Local CI results:
   ```
   Unit tests:          12/12 ✅
   CatalogDorisIT:      15/15 ✅
   CatalogDoris3xIT:     5/5  ✅
   CatalogDoris4xIT:     5/5  ✅
   ```


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "FANNG1 (via GitHub)" <gi...@apache.org>.
FANNG1 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4808406220

   Do we need to keep dedicated Doris 3.x and 4.x IT suites in this PR? Even though they are gated by `-PdorisMultiVersionTest`, maintaining multiple full Doris clusters/tests here still adds significant resource cost and CI/local maintenance overhead. Could we instead keep the default Doris IT plus focused SQL-generation/unit coverage, and only run extra Doris versions manually or in a separate compatibility job when needed?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4765037907

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|67.16% **`+0.08%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|80.97%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|46.82%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|3.66%|:red_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|10.4%|:red_circle:|
   |catalog-fileset|80.23%|:green_circle:|
   |catalog-glue|66.91%|:green_circle:|
   |catalog-hive|79.42%|:green_circle:|
   |catalog-jdbc-clickhouse|80.02%|:green_circle:|
   |catalog-jdbc-common|44.22%|:green_circle:|
   |catalog-jdbc-doris|80.06% **`+0.91%`**|:green_circle:|
   |catalog-jdbc-hologres|54.03%|:green_circle:|
   |catalog-jdbc-mysql|79.23%|:green_circle:|
   |catalog-jdbc-oceanbase|78.38%|:green_circle:|
   |catalog-jdbc-postgresql|82.29%|:green_circle:|
   |catalog-jdbc-starrocks|78.51%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|58.53%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.86%|:green_circle:|
   |catalog-lakehouse-paimon|82.14%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.51%|:green_circle:|
   |client-java|78.01%|:green_circle:|
   |common|50.17%|:green_circle:|
   |core|82.59%|:green_circle:|
   |filesystem-hadoop3|77.27%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|47.12%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-common|10.88%|:red_circle:|
   |hive-metastore-common|53.77%|:green_circle:|
   |iceberg-common|58.15%|:green_circle:|
   |iceberg-rest-server|73.9%|:green_circle:|
   |idp-basic|86.2%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|66.17%|:green_circle:|
   |lance-common|20.83%|:red_circle:|
   |lance-rest-server|60.13%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|82.95%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|85.96%|:green_circle:|
   |server-common|74.18%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|41.66%|:green_circle:|
   |trino-connector|40.25%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |catalog-jdbc-doris|[DorisTableOperations.java](https://github.com/jiangxt2/gravitino/blob/34c867627e4a04c0ae680032014abbcea4d65b0a/catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java)|80.97%|:green_circle:|
   
   </details>


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4904433575

   Done. Updated the PR description to match the standard template.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4796617845

   @zhoukangcn , I have no more comments, do you have time to take a look?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4862954689

   Hi maintainers, could you please approve the CI workflows for this PR?


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4790317574

   Thanks — adopted the single-version-in-CI approach and gated the rest for local runs.
   
   **What changed (3 files, no production code):**
   - `build.gradle.kts`: the new `doris-multi-version` JUnit tag is excluded by default; pass `-PdorisMultiVersionTest` to include it.
   - `CatalogDoris3xIT` / `CatalogDoris4xIT`: tagged `doris-multi-version`, so they are skipped in CI.
   - `CatalogDorisIT` (1.2.x): unchanged — the only version CI runs.
   
   CI therefore starts a single Doris container, avoiding the BE `MEM_LIMIT_EXCEEDED`. The full matrix still runs locally, **one version per Gradle invocation** (`ContainerSuite` keeps each cluster alive until JVM exit, so versions are run separately rather than stacked in one JVM):
   
   | Run | Result |
   | --- | --- |
   | CI-equivalent (default, no flag) | `CatalogDorisIT` (1.2.x) **15/15**; 3x/4x excluded by the tag |
   | `-PdorisMultiVersionTest` → `CatalogDoris3xIT` (3.0.x) | **5/5** |
   | `-PdorisMultiVersionTest` → `CatalogDoris4xIT` (4.0.x) | **5/5** |
   | Unit tests (`TestDorisTableOperationsSqlGeneration`) | **12/12** |
   


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4828803045

   Thanks for the review @zhoukangcn! Two responses:
   
   **1. PR scope**
   
   I understand the concern about size. The actual breakdown for Doris-related files (13 files, +1267/-81):
   
   - Production code: 1 file (`DorisTableOperations.java`), ~250 lines
   - Unit tests: 3 files, ~335 lines (new `TestDorisTableOperationsSqlGeneration`)
   - Integration tests: 3 files, ~590 lines (`CatalogDoris3xIT` / `CatalogDoris4xIT`)
   - Test infra (Docker/Container): 6 files, ~170 lines
   
   ~81% of the diff is test code. The INDEX syntax and Auto Increment logic are tightly coupled — Auto Increment requires a `UNIQUE KEY` table model declaration, and they share `appendTableModelKeySql()` / `mapDorisIndexType()`. Splitting them would require reviewers to cross-reference two PRs to understand the key-model flow.
   
   That said, if you still prefer a split, I can extract the Docker infra changes (DorisImageName, ContainerSuite, docker-compose) into a separate prerequisite PR. Let me know your preference.
   
   **2. Backward compatibility**
   
   Valid concern. I verified the behavior on Doris 3.0.6.2 and 4.0.6:
   
   | Syntax | 3.0.6.2 | 4.0.6 |
   |--------|---------|-------|
   | `INDEX name (col)` (bare, no USING) | ✅ defaults to INVERTED | ✅ defaults to INVERTED |
   | `INDEX name (col) USING BITMAP` | ✅ accepted, stored as INVERTED | ❌ parse error |
   | `INDEX name (col) USING INVERTED` | ✅ | ✅ |
   
   Since bare `INDEX name (col)` defaults to BITMAP on 1.2.x and INVERTED on 3.0+/4.0+, the simplest backward-compatible fix is to **omit the USING clause entirely** for BITMAP indexes — letting each Doris version apply its own default. This preserves old behavior on 1.2.x without requiring version detection.
   
   I'll update `mapIndexTypeToUsingClause()` to return an empty string for the BITMAP case, and adjust the read path (`mapDorisIndexType`) accordingly. Will push the fix once the scope question above is settled.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4789058587

   @jiangxt2 
   
   If the CI does not have enough resources to run multiple versions, we can choose one to run in the CI pipeline, and run them all locally. 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "zhoukangcn (via GitHub)" <gi...@apache.org>.
zhoukangcn commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4797127691

   > @zhoukangcn , I have no more comments, do you have time to take a look?
   
   @yuqi1129 I will try to take a look at this weekend, thanks.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 merged PR #11731:
URL: https://github.com/apache/gravitino/pull/11731


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3449646811


##########
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:
   Is this limitation only applicable for 1.x or also 3.x? 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4762400713

   Done. Added `CatalogDoris3xIT` with 5 test cases using the Doris 3.0.x Docker image:
   
   - `testCreateTableWithInvertedIndex` — INVERTED index creation + read-back
   - `testAddAndDropInvertedIndex` — ALTER TABLE add/drop INVERTED index
   - `testCreateTableWithAutoIncrement` — Auto Increment with UNIQUE_KEY model
   - `testCreateTableWithPrimaryKeySmokeTest` — PRIMARY_KEY → DUPLICATE KEY mapping
   - `testIndexReadBackMapping` — index type read-back correctness
   
   Also added multi-version Doris container infrastructure (`DorisImageName` enum, split FE/BE image support in `DorisContainer` and `docker-compose.yaml`) so that 1.2.x and 3.0.x clusters can coexist in the same test lifecycle.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "zhoukangcn (via GitHub)" <gi...@apache.org>.
zhoukangcn commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3497437811


##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -228,28 +234,153 @@ private static void validateDistribution(Distribution distribution, JdbcColumn[]
     }
   }
 
+  /**
+   * Validates that the Doris server version supports AUTO_INCREMENT columns. AUTO_INCREMENT was
+   * introduced in Doris 2.1.0. On older versions, the SQL parser does not recognize the
+   * AUTO_INCREMENT keyword and returns a syntax error.
+   */
+  private void validateAutoIncrementVersion(JdbcColumn[] columns) {
+    boolean hasAutoIncrement = Arrays.stream(columns).anyMatch(Column::autoIncrement);
+    if (!hasAutoIncrement) {
+      return;
+    }
+    Preconditions.checkState(dataSource != null, "dataSource is required for version validation");
+    String version = null;
+    try (Connection connection = dataSource.getConnection();
+        Statement stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT VERSION()")) {

Review Comment:
   Similarly, you can use `SHOW VARIABLES LIKE 'version_comment';` to retrieve the version.  
   
   I’m considering whether it would be better to store the version in the Doris catalog properties. This way, we could avoid having to fetch it repeatedly.
   
   @yuqi1129 Do you have some advice?



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "zhoukangcn (via GitHub)" <gi...@apache.org>.
zhoukangcn commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4828509692

   Thanks for the work. A few concerns:
   
   **1. PR scope**
   
   +1275/-85 across 15 files — mixing INDEX syntax fix, AUTO_INCREMENT support, version detection, and multi-version Docker infra. Would be easier to review if split into 2-3 smaller PRs.
   
   **2. Backward compatibility**
   
   We should maintain backward compatibility with Doris 1.2.x until we explicitly announce dropping support in a future release. The new code unconditionally generates `USING INVERTED` for non-key indexes, but inverted index was not officially introduced until Doris 2.0.0 (per the [2.0.0 release notes](https://doris.apache.org/blog/release-note-2.0.0): "In Apache Doris 2.0.0, we introduced inverted index"). Although `IndexType.INVERTED` exists in the 1.2.x source code, we need to confirm whether the 1.2.x release packages actually include full support for it. The old `INDEX name (col)` without a USING clause worked fine on 1.2.x by defaulting to BITMAP. A version-aware branch (omit `USING` clause when Doris < 2.0) may be needed to avoid breaking existing deployments.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4777034842

   @jiangxt2 CI fails, and you may need to take a look.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4779465983

   Fixed. The CI failure was caused by `getIndexes()` hardcoding `PRIMARY_KEY` for all indexes, which broke `CatalogDorisIT` assertions. The fix reads `Index_type` column from `SHOW INDEX` via `ResultSetMetaData` and maps it through `mapDorisIndexType()`. Also addressed M4 (catch block scope) and L4 (index existence assertion in 1.2.x IT). All tests pass locally: 12 unit + 15 CatalogDorisIT + 5 CatalogDoris3xIT + 5 CatalogDoris4xIT.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4767500347

   Pushed a new commit addressing all review comments. Here is a summary of the fixes:
   
   **Critical**
   - **C2 (line 316)**: Fixed PRIMARY_KEY validation/generation mismatch. `appendTableModelKeySql` now handles both `UNIQUE_KEY` and `PRIMARY_KEY` index types, both emitting `UNIQUE KEY(col)` (Doris Nereids parser does not accept `PRIMARY KEY(col)` syntax; functionally equivalent).
   - **C3 (line 104)**: Added `validateAutoIncrementVersion()` — queries `SELECT VERSION()` and rejects AUTO_INCREMENT if Doris server < 2.1.0. Clear error message: *"AUTO_INCREMENT requires Doris 2.1.0 or later. Current server version: X.Y.Z"*.
   
   **Medium**
   - **C1/M1 (line 302/530)**: Fixed BITMAP read/write asymmetry. `mapDorisIndexType` now returns `INVERTED` for BITMAP, matching the write path. **Note on 1.2.x**: We chose read-write consistency (both paths emit INVERTED) over version detection, since (1) BITMAP index creation via Gravitino on 1.2.x is an edge case not covered by the existing test suite; (2) server-side version detection for each index type would add significant complexity; (3) the comment in `mapIndexTypeToUsingClause` documents the rationale. If the community prefers version detection here, we can add it in a follow-up.
   - **M2 (line 520)**: Fixed null `Index_type` default — now returns `UNIQUE_KEY` instead of `INVERTED` for non-PRIMARY indexes (matching the BTREE case).
   - **M3 (line 343)**: Documented UNIQUE KEY ordered prefix constraint in Javadoc.
   - **M4 (line 36)**: Added `VERSION_4_0` to `DorisImageName` enum + new `CatalogDoris4xIT` integration test class covering 4.0.x specific features (INVERTED index, ADD/DROP INDEX, AUTO_INCREMENT, UNIQUE KEY model, BITMAP read-back mapping).
   
   **Low**
   - **L1 (line 90)**: Simplified debug logging (removed redundant `type.name()`).
   
   **Test results**
   - Unit tests: 12/12 ✅
   - CatalogDoris3xIT: 5/5 ✅
   - CatalogDoris4xIT: 5/5 ✅


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3498437914


##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -228,28 +234,153 @@ private static void validateDistribution(Distribution distribution, JdbcColumn[]
     }
   }
 
+  /**
+   * Validates that the Doris server version supports AUTO_INCREMENT columns. AUTO_INCREMENT was
+   * introduced in Doris 2.1.0. On older versions, the SQL parser does not recognize the
+   * AUTO_INCREMENT keyword and returns a syntax error.
+   */
+  private void validateAutoIncrementVersion(JdbcColumn[] columns) {
+    boolean hasAutoIncrement = Arrays.stream(columns).anyMatch(Column::autoIncrement);
+    if (!hasAutoIncrement) {
+      return;
+    }
+    Preconditions.checkState(dataSource != null, "dataSource is required for version validation");
+    String version = null;
+    try (Connection connection = dataSource.getConnection();
+        Statement stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT VERSION()")) {

Review Comment:
   I'm afraid that information like version is not so suitable to store in catalog properties. About performance consideration, we haven't got detailed statistics about whether version-fetching is a time-consumting operations, so I am inclined to leave it as it is.  If we did find that, it would largely influence the API output, and we could just start the refactor work. 



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4889952402

   > Hi maintainers, could you please approve the CI workflows for this PR?
   
   Done, I will continue to move this PR forward. 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4901979802

   I'm going to merge this one as some can be improved later if they are really a problem after fullly testing. 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4904074820

   @jiangxt2 
   Please modify the PR description to align it with the others. 


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4762416568

   Done. Added `CatalogDoris3xIT` using the Doris 3.0.x Docker image, covering INVERTED index creation/drop, Auto Increment, PRIMARY_KEY model mapping, and index read-back. Also introduced multi-version Doris container infrastructure (`DorisImageName` enum, split FE/BE image support) so 1.2.x and 3.0.x clusters coexist in the same test lifecycle.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4788626361

   The BackendIT failure appears to be a CI resource issue rather than something introduced by this PR.
   
   The only failing test is `CatalogDorisIT.testDorisTablePartitionOperation`, which expects `NoSuchPartitionException` but receives `RuntimeException` caused by `MEM_LIMIT_EXCEEDED` in the Doris BE:
   
   ```
   sys available memory 1.52 GB less than low water mark 1.56 GB
   ```
   
   Looking at the stack trace, the failure occurs in `correctJdbcTableFields()` (line 622) during a `SELECT TABLE_COMMENT FROM information_schema.TABLES` query. This code path was not modified by this PR — the Doris BE simply ran out of memory at execution time due to limited free memory on the CI runner.
   
   This seems to be a known class of CI flakiness in the Gravitino project. I noticed similar past examples such as #3791 (container startup failure), #2811 (port timing issues), and #4822 (reducing CI resource consumption by excluding redundant tests). Please let me know if there is anything else I should address.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4739695663

   Is it possible to add some ITs to cover your changes? You can change to use the 3.x Docker image for your newly added ITs.


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3449721022


##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -387,15 +481,67 @@ protected List<Index> getIndexes(Connection connection, String databaseName, Str
       while (resultSet.next()) {
         String indexName = resultSet.getString("Key_name");
         String columnName = resultSet.getString("Column_name");
-        indexes.add(
-            Indexes.of(Index.IndexType.PRIMARY_KEY, indexName, new String[][] {{columnName}}));
+        // Index_type column may not exist in older Doris versions (e.g. 1.2.x).
+        // Fall back to null so mapDorisIndexType can infer from indexName.
+        String indexType;
+        try {
+          indexType = resultSet.getString("Index_type");
+        } catch (SQLException e) {
+          LOG.warn(
+              "Index_type column not available in SHOW INDEX output, "
+                  + "inferring index type from index name '{}'. "
+                  + "Upgrade to Doris 3.0+ for accurate index type mapping.",
+              indexName);
+          indexType = null;
+        }
+        Index.IndexType gravitinoIndexType = mapDorisIndexType(indexType, indexName);
+        indexes.add(Indexes.of(gravitinoIndexType, indexName, new String[][] {{columnName}}));
       }
       return indexes;
     } catch (SQLException e) {
       throw exceptionMapper.toGravitinoException(e);
     }
   }
 
+  @VisibleForTesting
+  static Index.IndexType mapDorisIndexType(String indexType, String indexName) {
+    if (indexType == null) {
+      // Index_type column unavailable (Doris 1.2.x) or returned null.
+      // Infer from index name: "PRIMARY" is the primary key, everything else defaults to
+      // INVERTED as a safe fallback (Doris 1.2.x indexes are all BTREE-based key indexes,
+      // but without Index_type we cannot distinguish UNIQUE_KEY from PRIMARY_KEY).
+      if ("PRIMARY".equals(indexName)) {
+        return Index.IndexType.PRIMARY_KEY;
+      }
+      LOG.warn(
+          "Index_type is null for index '{}', defaulting to INVERTED. "
+              + "Load table metadata from Doris 3.0+ for accurate index type mapping.",
+          indexName);
+      return Index.IndexType.INVERTED;
+    }
+    switch (indexType.toUpperCase()) {
+      case "BTREE":
+        if ("PRIMARY".equals(indexName)) {
+          return Index.IndexType.PRIMARY_KEY;
+        }
+        return Index.IndexType.UNIQUE_KEY;
+      case "INVERTED":
+        return Index.IndexType.INVERTED;
+      case "BITMAP":

Review Comment:
   Read maps `BITMAP`->`IndexType.BITMAP`, but the write path forces `BITMAP`->`USING INVERTED` (around line 302). A BITMAP index round-tripped through Gravitino silently becomes INVERTED. Pick one direction consistently, ideally version-aware.



##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -233,23 +244,106 @@ private static void appendIndexesSql(Index[] indexes, StringBuilder sqlBuilder)
       return;
     }
 
-    // validate indexes
-    Arrays.stream(indexes)
-        .forEach(
-            index -> {
-              if (index.fieldNames().length > 1) {
-                throw new IllegalArgumentException("Index does not support multi fields in Doris");
-              }
-            });
+    // Log index types for debugging
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("appendIndexesSql: processing {} indexes", indexes.length);
+      for (Index index : indexes) {
+        LOG.debug("  index: name={}, type={}", index.name(), index.type());
+      }
+    }
 
-    String indexSql =
+    // Filter out PRIMARY_KEY and UNIQUE_KEY indexes — they are table model keys in Doris,
+    // defined via UNIQUE KEY(col) / DUPLICATE KEY(col) syntax, not via INDEX clause.
+    List<Index> nonKeyIndexes =
         Arrays.stream(indexes)
-            .map(index -> String.format("INDEX %s (%s)", index.name(), index.fieldNames()[0][0]))
+            .filter(
+                index ->
+                    index.type() != Index.IndexType.PRIMARY_KEY
+                        && index.type() != Index.IndexType.UNIQUE_KEY)
+            .collect(Collectors.toList());
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("appendIndexesSql: {} non-key indexes after filtering", nonKeyIndexes.size());
+    }
+
+    if (nonKeyIndexes.isEmpty()) {
+      return;
+    }
+
+    nonKeyIndexes.forEach(
+        index -> {
+          if (index.fieldNames().length > 1) {
+            throw new IllegalArgumentException("Index does not support multi fields in Doris");
+          }
+        });
+
+    String indexSql =
+        nonKeyIndexes.stream()
+            .map(
+                index -> {
+                  String usingClause = mapIndexTypeToUsingClause(index.type());
+                  return String.format(
+                      "INDEX `%s` (`%s`) %s", index.name(), index.fieldNames()[0][0], usingClause);
+                })
             .collect(Collectors.joining(",\n"));
 
     sqlBuilder.append(",").append(NEW_LINE).append(indexSql);
   }
 
+  private static String mapIndexTypeToUsingClause(Index.IndexType indexType) {
+    switch (indexType) {
+      case PRIMARY_KEY:
+      case UNIQUE_KEY:
+        throw new IllegalStateException(
+            "PRIMARY_KEY and UNIQUE_KEY should be filtered out before index SQL generation, got: "
+                + indexType);
+      case INVERTED:
+        return "USING INVERTED";
+      case BITMAP:

Review Comment:
   This unconditionally emits `USING INVERTED` for every non-key index (including BITMAP). There is no Doris server-version detection anywhere in the catalog, so the "cross-version compatibility" here is really one hardcoded choice applied to all versions. Two concerns:
   
   1. Inverted index is not GA until Doris 2.0. On 1.2.x (still in the test matrix as `VERSION_1_2`) `USING INVERTED` likely fails, whereas the previous `INDEX name (col)` form defaulted to a bitmap index and worked — this looks like a regression for the oldest supported version.
   2. BITMAP is silently rewritten to INVERTED even on versions that still support BITMAP (2.x/3.x), changing user intent. Note the read path (`mapDorisIndexType`) maps `BITMAP`->`BITMAP`, so write/read are asymmetric.
   
   Consider detecting the server version once and branching, or explicitly narrowing the supported range. Please also verify against Doris docs: when inverted GA'd, and whether 3.0+ truly converts BITMAP->INVERTED internally / 4.0.6 removed BITMAP.



##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -233,23 +244,106 @@ private static void appendIndexesSql(Index[] indexes, StringBuilder sqlBuilder)
       return;
     }
 
-    // validate indexes
-    Arrays.stream(indexes)
-        .forEach(
-            index -> {
-              if (index.fieldNames().length > 1) {
-                throw new IllegalArgumentException("Index does not support multi fields in Doris");
-              }
-            });
+    // Log index types for debugging
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("appendIndexesSql: processing {} indexes", indexes.length);
+      for (Index index : indexes) {
+        LOG.debug("  index: name={}, type={}", index.name(), index.type());
+      }
+    }
 
-    String indexSql =
+    // Filter out PRIMARY_KEY and UNIQUE_KEY indexes — they are table model keys in Doris,
+    // defined via UNIQUE KEY(col) / DUPLICATE KEY(col) syntax, not via INDEX clause.
+    List<Index> nonKeyIndexes =
         Arrays.stream(indexes)
-            .map(index -> String.format("INDEX %s (%s)", index.name(), index.fieldNames()[0][0]))
+            .filter(
+                index ->
+                    index.type() != Index.IndexType.PRIMARY_KEY
+                        && index.type() != Index.IndexType.UNIQUE_KEY)
+            .collect(Collectors.toList());
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("appendIndexesSql: {} non-key indexes after filtering", nonKeyIndexes.size());
+    }
+
+    if (nonKeyIndexes.isEmpty()) {
+      return;
+    }
+
+    nonKeyIndexes.forEach(
+        index -> {
+          if (index.fieldNames().length > 1) {
+            throw new IllegalArgumentException("Index does not support multi fields in Doris");
+          }
+        });
+
+    String indexSql =
+        nonKeyIndexes.stream()
+            .map(
+                index -> {
+                  String usingClause = mapIndexTypeToUsingClause(index.type());
+                  return String.format(
+                      "INDEX `%s` (`%s`) %s", index.name(), index.fieldNames()[0][0], usingClause);
+                })
             .collect(Collectors.joining(",\n"));
 
     sqlBuilder.append(",").append(NEW_LINE).append(indexSql);
   }
 
+  private static String mapIndexTypeToUsingClause(Index.IndexType indexType) {
+    switch (indexType) {
+      case PRIMARY_KEY:
+      case UNIQUE_KEY:
+        throw new IllegalStateException(
+            "PRIMARY_KEY and UNIQUE_KEY should be filtered out before index SQL generation, got: "
+                + indexType);
+      case INVERTED:
+        return "USING INVERTED";
+      case BITMAP:
+        // Doris 4.0.6 removed BITMAP index support; 3.0+ internally converts BITMAP to INVERTED.
+        // Always generate USING INVERTED for cross-version compatibility.
+        return "USING INVERTED";
+      case VECTOR:
+        return "USING ANN";
+      default:
+        // Doris does not support BTREE as an explicit USING clause for non-key indexes.
+        // Known types that reach here (e.g. BLOOMFILTER) are table-level properties, not indexes.
+        throw new UnsupportedOperationException(
+            "Doris does not support index type " + indexType + " via ADD INDEX syntax");
+    }
+  }
+
+  private static void appendTableModelKeySql(Index[] indexes, StringBuilder sqlBuilder) {

Review Comment:
   Validation/generation mismatch. The base `validateIncrementCol(columns, indexes)` accepts an auto-increment column keyed by **PRIMARY_KEY or UNIQUE_KEY**, but this method only emits `UNIQUE KEY(...)` for UNIQUE_KEY and silently skips PRIMARY_KEY. So a table with an auto-inc column + PRIMARY_KEY passes validation yet generates DDL with no key (DUPLICATE model): the key intent is lost and Doris may reject the auto-inc column. Either map PRIMARY_KEY->`UNIQUE KEY` on supported versions, or reject it clearly — don't accept in validation and drop in generation. (Also a behavior change vs. the old code, which emitted PRIMARY_KEY as an INDEX; uniqueness is now silently dropped on create.)



##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -233,23 +244,106 @@ private static void appendIndexesSql(Index[] indexes, StringBuilder sqlBuilder)
       return;
     }
 
-    // validate indexes
-    Arrays.stream(indexes)
-        .forEach(
-            index -> {
-              if (index.fieldNames().length > 1) {
-                throw new IllegalArgumentException("Index does not support multi fields in Doris");
-              }
-            });
+    // Log index types for debugging
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("appendIndexesSql: processing {} indexes", indexes.length);
+      for (Index index : indexes) {
+        LOG.debug("  index: name={}, type={}", index.name(), index.type());
+      }
+    }
 
-    String indexSql =
+    // Filter out PRIMARY_KEY and UNIQUE_KEY indexes — they are table model keys in Doris,
+    // defined via UNIQUE KEY(col) / DUPLICATE KEY(col) syntax, not via INDEX clause.
+    List<Index> nonKeyIndexes =
         Arrays.stream(indexes)
-            .map(index -> String.format("INDEX %s (%s)", index.name(), index.fieldNames()[0][0]))
+            .filter(
+                index ->
+                    index.type() != Index.IndexType.PRIMARY_KEY
+                        && index.type() != Index.IndexType.UNIQUE_KEY)
+            .collect(Collectors.toList());
+
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("appendIndexesSql: {} non-key indexes after filtering", nonKeyIndexes.size());
+    }
+
+    if (nonKeyIndexes.isEmpty()) {
+      return;
+    }
+
+    nonKeyIndexes.forEach(
+        index -> {
+          if (index.fieldNames().length > 1) {
+            throw new IllegalArgumentException("Index does not support multi fields in Doris");
+          }
+        });
+
+    String indexSql =
+        nonKeyIndexes.stream()
+            .map(
+                index -> {
+                  String usingClause = mapIndexTypeToUsingClause(index.type());
+                  return String.format(
+                      "INDEX `%s` (`%s`) %s", index.name(), index.fieldNames()[0][0], usingClause);
+                })
             .collect(Collectors.joining(",\n"));
 
     sqlBuilder.append(",").append(NEW_LINE).append(indexSql);
   }
 
+  private static String mapIndexTypeToUsingClause(Index.IndexType indexType) {
+    switch (indexType) {
+      case PRIMARY_KEY:
+      case UNIQUE_KEY:
+        throw new IllegalStateException(
+            "PRIMARY_KEY and UNIQUE_KEY should be filtered out before index SQL generation, got: "
+                + indexType);
+      case INVERTED:
+        return "USING INVERTED";
+      case BITMAP:
+        // Doris 4.0.6 removed BITMAP index support; 3.0+ internally converts BITMAP to INVERTED.
+        // Always generate USING INVERTED for cross-version compatibility.
+        return "USING INVERTED";
+      case VECTOR:
+        return "USING ANN";
+      default:
+        // Doris does not support BTREE as an explicit USING clause for non-key indexes.
+        // Known types that reach here (e.g. BLOOMFILTER) are table-level properties, not indexes.
+        throw new UnsupportedOperationException(
+            "Doris does not support index type " + indexType + " via ADD INDEX syntax");
+    }
+  }
+
+  private static void appendTableModelKeySql(Index[] indexes, StringBuilder sqlBuilder) {
+    // Only emit UNIQUE KEY declaration when an explicit UNIQUE_KEY index is present.
+    // PRIMARY_KEY indexes are intentionally skipped: Doris 1.2.x does not support UNIQUE KEY
+    // syntax (only DUPLICATE KEY / AGGREGATE KEY), and the default DUPLICATE KEY model already
+    // satisfies PRIMARY_KEY's uniqueness semantics. Users targeting Doris 2.0+ who need the
+    // UNIQUE KEY model should pass Index.IndexType.UNIQUE_KEY instead.
+    long keyIndexCount =
+        Arrays.stream(indexes)
+            .filter(
+                index ->
+                    index.type() == Index.IndexType.PRIMARY_KEY
+                        || index.type() == Index.IndexType.UNIQUE_KEY)
+            .count();
+    Preconditions.checkArgument(
+        keyIndexCount <= 1,
+        "Doris table model key can have at most one PRIMARY_KEY or UNIQUE_KEY index, got: %s",
+        keyIndexCount);
+
+    Arrays.stream(indexes)
+        .filter(index -> index.type() == Index.IndexType.UNIQUE_KEY)
+        .findFirst()
+        .ifPresent(
+            keyIndex -> {
+              String cols =
+                  Arrays.stream(keyIndex.fieldNames())
+                      .map(field -> BACK_QUOTE + field[0] + BACK_QUOTE)
+                      .collect(Collectors.joining(", "));
+              sqlBuilder.append(NEW_LINE).append("UNIQUE KEY(").append(cols).append(")");

Review Comment:
   Doris requires key columns to be an ordered prefix of the schema. This emits `UNIQUE KEY(col)` without validating/reordering column position, so a key column that isn't first produces invalid DDL (Doris: "Key columns should be a ordered prefix of the schema"). At minimum document the constraint, or validate it.



##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -387,15 +481,67 @@ protected List<Index> getIndexes(Connection connection, String databaseName, Str
       while (resultSet.next()) {
         String indexName = resultSet.getString("Key_name");
         String columnName = resultSet.getString("Column_name");
-        indexes.add(
-            Indexes.of(Index.IndexType.PRIMARY_KEY, indexName, new String[][] {{columnName}}));
+        // Index_type column may not exist in older Doris versions (e.g. 1.2.x).
+        // Fall back to null so mapDorisIndexType can infer from indexName.
+        String indexType;
+        try {
+          indexType = resultSet.getString("Index_type");
+        } catch (SQLException e) {
+          LOG.warn(
+              "Index_type column not available in SHOW INDEX output, "
+                  + "inferring index type from index name '{}'. "
+                  + "Upgrade to Doris 3.0+ for accurate index type mapping.",
+              indexName);
+          indexType = null;
+        }
+        Index.IndexType gravitinoIndexType = mapDorisIndexType(indexType, indexName);
+        indexes.add(Indexes.of(gravitinoIndexType, indexName, new String[][] {{columnName}}));
       }
       return indexes;
     } catch (SQLException e) {
       throw exceptionMapper.toGravitinoException(e);
     }
   }
 
+  @VisibleForTesting
+  static Index.IndexType mapDorisIndexType(String indexType, String indexName) {
+    if (indexType == null) {
+      // Index_type column unavailable (Doris 1.2.x) or returned null.
+      // Infer from index name: "PRIMARY" is the primary key, everything else defaults to
+      // INVERTED as a safe fallback (Doris 1.2.x indexes are all BTREE-based key indexes,
+      // but without Index_type we cannot distinguish UNIQUE_KEY from PRIMARY_KEY).
+      if ("PRIMARY".equals(indexName)) {
+        return Index.IndexType.PRIMARY_KEY;
+      }
+      LOG.warn(
+          "Index_type is null for index '{}', defaulting to INVERTED. "
+              + "Load table metadata from Doris 3.0+ for accurate index type mapping.",
+          indexName);
+      return Index.IndexType.INVERTED;

Review Comment:
   Inconsistent mapping for the same physical index: when `Index_type` is present and `BTREE` (non-PRIMARY) you return `UNIQUE_KEY` (line 527), but when the column is absent (1.2.x, where everything is BTREE) the same index defaults to `INVERTED` here. For consistency the null branch should default to `UNIQUE_KEY`, matching the BTREE case the comment describes.



##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -87,7 +87,21 @@ protected String generateCreateTableSql(
       Distribution distribution,
       Index[] indexes) {
 
-    validateIncrementCol(columns);
+    // Log index information for debugging
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(
+          "generateCreateTableSql: tableName={}, indexes.length={}", tableName, indexes.length);
+      for (int i = 0; i < indexes.length; i++) {
+        LOG.debug(
+            "  indexes[{}]: name={}, type={}, type.name()={}",
+            i,
+            indexes[i].name(),
+            indexes[i].type(),
+            indexes[i].type().name());
+      }
+    }
+
+    validateIncrementCol(columns, indexes);

Review Comment:
   Delegating to the base validator is fine, but it also removes the only version guard: Doris auto-increment requires 2.1.0+. On older servers the column now reaches Doris and fails with a less clear server-side error (the old code gave a clear message). The title says 3.0+, but this affects 1.2.x/2.0.x too — consider a clear lower-bound check or documenting the minimum.



##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/DorisImageName.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.integration.test.container;
+
+/**
+ * Doris Docker image versions for multi-version integration testing.
+ *
+ * <p>{@link #VERSION_1_2} uses the Gravitino CI all-in-one image (FE + BE in a single image) for
+ * backward-compatible testing against Doris 1.2.x.
+ *
+ * <p>{@link #VERSION_3_0} uses the official Apache Doris split images ({@code apache/doris:fe-3.x}
+ * and {@code apache/doris:be-3.x}). {@link DorisContainer} detects the {@code :fe-} prefix and
+ * automatically derives the corresponding BE image, passing both via compose environment variables.
+ *
+ * @see DorisContainer
+ * @see ContainerSuite#startDorisContainer(DorisImageName)
+ */
+public enum DorisImageName {
+  VERSION_1_2("apache/gravitino-ci:doris-0.1.5"),
+  VERSION_3_0("apache/doris:fe-3.0.6.2");

Review Comment:
   The PR description says integration tests ran on Doris 4.0.6 and 3.0.6.2, but the image matrix only has `VERSION_1_2` and `VERSION_3_0` (3.0.6.2) — no 4.0.6. The BITMAP->INVERTED logic is justified by "4.0.6 removed BITMAP", yet 4.0.6 isn't in the automated matrix, so that version-specific behavior isn't actually covered. Either add a 4.0.6 image or adjust the description.



##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -87,7 +87,21 @@ protected String generateCreateTableSql(
       Distribution distribution,
       Index[] indexes) {
 
-    validateIncrementCol(columns);
+    // Log index information for debugging

Review Comment:
   Minor: this debug block logs both `index.type()` and `index.type().name()` (redundant), and there is a second similar loop in `appendIndexesSql`. Consider trimming to one concise line.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#issuecomment-4767585906

   Thank you for the thorough review. I have pushed a new commit (`dc9cc3d88`) addressing all 8 comments.
   
   **Comment-by-comment response**
   
   **line 920 — PRIMARY_KEY/UNIQUE_KEY limitation**: Already replied. This applies to all Doris versions. `PRIMARY_KEY` and `UNIQUE_KEY` belong to `KeysType` (table data model), not `IndexType` (index types). The `UnsupportedOperationException` is a defensive guard.
   
   **line 316 — PRIMARY_KEY validation/generation mismatch**: Fixed. `appendTableModelKeySql` now handles both `UNIQUE_KEY` and `PRIMARY_KEY` index types, both emitting `UNIQUE KEY(col)`. Doris Nereids parser (4.0.x) does not accept `PRIMARY KEY(col)` syntax in CREATE TABLE; the PRIMARY KEY model is functionally equivalent to UNIQUE KEY in Doris.
   
   **line 104 — AUTO_INCREMENT version guard**: Fixed. Added `validateAutoIncrementVersion()` — queries `SELECT VERSION()` and rejects AUTO_INCREMENT if Doris server < 2.1.0. Clear error message: *"AUTO_INCREMENT requires Doris 2.1.0 or later. Current server version: X.Y.Z"*.
   
   **line 302/530 — BITMAP→INVERTED hardcoded, read/write asymmetry**: Fixed. `mapDorisIndexType` now returns `INVERTED` for BITMAP, matching the write path. On the 1.2.x concern: we chose read-write consistency over version detection. If you prefer version-aware branching, I can add it in a follow-up PR.
   
   **line 520 — null Index_type default**: Fixed. Now returns `UNIQUE_KEY` instead of `INVERTED` for non-PRIMARY indexes when `Index_type` is absent (Doris 1.2.x), matching the BTREE case.
   
   **line 343 — UNIQUE KEY ordered prefix constraint**: Documented in Javadoc: *"Doris requires key columns to be an ordered prefix of the schema. The caller must ensure the key column is the first column in the table definition."*
   
   **line 36 — Test matrix missing 4.0.6**: Fixed. Added `VERSION_4_0` to `DorisImageName` enum + new `CatalogDoris4xIT` integration test class covering 4.0.x specific features (INVERTED index, ADD/DROP INDEX, AUTO_INCREMENT, UNIQUE KEY model, BITMAP read-back mapping).
   
   **line 90 — Redundant debug logging**: Fixed. Simplified to `name={}, type={}`.
   
   **Version compatibility**
   
   - INVERTED index: Experimental on 1.2.x, GA in 2.0+
   - BITMAP index: Default (no USING) on 1.2.x; `USING BITMAP` on 3.0.x; removed from Nereids grammar on 4.0.x, mapped to INVERTED
   - AUTO_INCREMENT: Not supported on 1.2.x (parser error); supported on 3.0.x / 4.0.x
   - UNIQUE KEY model: Not supported on 1.2.x; supported on 3.0.x / 4.0.x
   - ANN/VECTOR index: Supported on 4.0.6+
   
   **Test results**
   
   ```
   Unit tests (TestDorisTableOperationsSqlGeneration): 12/12 ✅
   CatalogDoris3xIT (Doris 3.0.6.2):                  5/5  ✅
   CatalogDoris4xIT (Doris 4.0.6):                    5/5  ✅
   ```
   
   ---
   
   感谢详细的 review。我已推送新 commit(`dc9cc3d88`)修复了全部 8 条评论。
   
   **逐条回应**
   
   **line 920 — PRIMARY_KEY/UNIQUE_KEY 限制**:已回复。此限制适用于所有 Doris 版本。`PRIMARY_KEY` 和 `UNIQUE_KEY` 属于 `KeysType`(表数据模型),不属于 `IndexType`(索引类型)。`UnsupportedOperationException` 是防御性守卫。
   
   **line 316 — PRIMARY_KEY 验证/生成不匹配**:已修复。`appendTableModelKeySql` 现在同时处理 `UNIQUE_KEY` 和 `PRIMARY_KEY`,均生成 `UNIQUE KEY(col)`。Doris Nereids 解析器(4.0.x)不接受 `PRIMARY KEY(col)` 语法;PRIMARY KEY 模型在 Doris 中与 UNIQUE KEY 功能等价。
   
   **line 104 — AUTO_INCREMENT 版本守卫**:已修复。新增 `validateAutoIncrementVersion()` —— 查询 `SELECT VERSION()`,Doris 版本 < 2.1.0 时拒绝 AUTO_INCREMENT,错误信息:*"AUTO_INCREMENT requires Doris 2.1.0 or later. Current server version: X.Y.Z"*。
   
   **line 302/530 — BITMAP→INVERTED 硬编码,读写不对称**:已修复。`mapDorisIndexType` 现在对 BITMAP 返回 `INVERTED`,与写路径一致。关于 1.2.x 的顾虑:我们选择了读写一致性而非版本检测。如果你倾向于版本感知分支,我可以在后续 PR 中补充。
   
   **line 520 — null Index_type 默认值**:已修复。当 `Index_type` 不存在时(Doris 1.2.x),非 PRIMARY 索引现在返回 `UNIQUE_KEY`(而非 `INVERTED`),与 BTREE 分支行为一致。
   
   **line 343 — UNIQUE KEY 有序前缀约束**:已在 Javadoc 中标注:*"Doris 要求 key columns 是 schema 的有序前缀,调用方必须确保 key column 是表定义中的第一列。"*
   
   **line 36 — 测试矩阵缺 4.0.6**:已修复。在 `DorisImageName` 枚举中新增 `VERSION_4_0` + 新增 `CatalogDoris4xIT` 集成测试类,覆盖 4.0.x 特有功能(INVERTED 索引、ADD/DROP INDEX、AUTO_INCREMENT、UNIQUE KEY 模型、BITMAP 读回映射)。
   
   **line 90 — 冗余 debug 日志**:已修复,精简为 `name={}, type={}`。
   
   **版本兼容性**
   
   - INVERTED 索引:1.2.x 为实验性,2.0+ 为 GA
   - BITMAP 索引:1.2.x 默认(无 USING);3.0.x 支持 `USING BITMAP`;4.0.x 已从 Nereids 语法移除,映射为 INVERTED
   - AUTO_INCREMENT:1.2.x 不支持(parser 报错);3.0.x / 4.0.x 支持
   - UNIQUE KEY 模型:1.2.x 不支持;3.0.x / 4.0.x 支持
   - ANN/VECTOR 索引:4.0.6+ 支持
   
   **测试结果**
   
   ```
   单元测试 (TestDorisTableOperationsSqlGeneration): 12/12 ✅
   CatalogDoris3xIT (Doris 3.0.6.2):                5/5  ✅
   CatalogDoris4xIT (Doris 4.0.6):                  5/5  ✅
   ```


-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3496807088


##########
catalogs/catalog-jdbc-doris/src/main/java/org/apache/gravitino/catalog/doris/operation/DorisTableOperations.java:
##########
@@ -228,28 +234,153 @@ private static void validateDistribution(Distribution distribution, JdbcColumn[]
     }
   }
 
+  /**
+   * Validates that the Doris server version supports AUTO_INCREMENT columns. AUTO_INCREMENT was
+   * introduced in Doris 2.1.0. On older versions, the SQL parser does not recognize the
+   * AUTO_INCREMENT keyword and returns a syntax error.
+   */
+  private void validateAutoIncrementVersion(JdbcColumn[] columns) {
+    boolean hasAutoIncrement = Arrays.stream(columns).anyMatch(Column::autoIncrement);
+    if (!hasAutoIncrement) {
+      return;
+    }
+    Preconditions.checkState(dataSource != null, "dataSource is required for version validation");
+    String version = null;
+    try (Connection connection = dataSource.getConnection();
+        Statement stmt = connection.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT VERSION()")) {

Review Comment:
   Thanks for catching this! I've pushed a fix.
   
   **Why `SELECT VERSION()` returns `5.7.99`**: This is actually a Doris design choice, not a Gravitino bug. Doris hardcodes `5.7.99` as the MySQL protocol version (see `GlobalVariable.java` and `MysqlHandshakePacket.java`) to:
   1. Maintain MySQL JDBC driver compatibility (protocol v10)
   2. Prevent vulnerability scanners from falsely reporting MySQL CVEs (patch 99 exceeds the real MySQL 5.7 range of 5.7.0–5.7.44, so scanners can't match it to known vulnerabilities)
   
   The consequence is that `SELECT VERSION()` is fundamentally unreliable for Doris version detection — it always returns `5.7.99` regardless of the actual Doris version.
   
   **Fix**: Replaced `SELECT VERSION()` with `SHOW FRONTENDS`, which returns the actual Doris version in the `Version` column (e.g. `doris-3.0.6.2-rc01-910c4249c5`). Extracted using regex `(\d+\.\d+\.\d+\.?\d*)` to handle both 3-part (`1.2.2`) and 4-part (`3.0.6.2`) formats.
   
   Also addressed the BITMAP backward compatibility concern: omit the `USING` clause entirely, letting each Doris version apply its own default (1.2.x → BITMAP, 3.0+/4.0+ → INVERTED).
   
   Verified on all three local Doris clusters (1.2.2, 3.0.6.2, 4.0.6):
   ```
   Unit tests:              ✅
   CatalogDorisIT (1.2.x):     ✅
   CatalogDoris3xIT (3.0.6.2): ✅
   CatalogDoris4xIT (4.0.6):   ✅
   ```



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [#11590] fix(doris): fix INDEX syntax and support AUTO_INCREMENT for Doris 3.0+ [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on code in PR #11731:
URL: https://github.com/apache/gravitino/pull/11731#discussion_r3487416842


##########
integration-test-common/src/test/java/org/apache/gravitino/integration/test/container/DorisImageName.java:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.integration.test.container;
+
+/**
+ * Doris Docker image versions for multi-version integration testing.
+ *
+ * <p>{@link #VERSION_1_2} uses the Gravitino CI all-in-one image (FE + BE in a single image) for
+ * backward-compatible testing against Doris 1.2.x.
+ *
+ * <p>{@link #VERSION_3_0} uses the official Apache Doris split images ({@code apache/doris:fe-3.x}
+ * and {@code apache/doris:be-3.x}). {@link DorisContainer} detects the {@code :fe-} prefix and
+ * automatically derives the corresponding BE image, passing both via compose environment variables.
+ *
+ * @see DorisContainer
+ * @see ContainerSuite#startDorisContainer(DorisImageName)
+ */
+public enum DorisImageName {
+  VERSION_1_2("apache/gravitino-ci:doris-0.1.5"),
+  VERSION_3_0("apache/doris:fe-3.0.6.2"),

Review Comment:
   Hi @zhoukangcn, the FE and BE are separate images on Docker Hub (e.g. `apache/doris:fe-3.0.6.2` and `apache/doris:be-3.0.6.2`). The enum stores the FE image as the canonical identifier; `DorisContainer` automatically derives the BE image by replacing the `:fe-` prefix with `:be-`. For the 1.2.x all-in-one image, no derivation is needed since FE and BE are bundled together.



-- 
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: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org