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/25 14:32:35 UTC

[I] [Bug] ClickHouse catalog: GRANULARITY hardcoded and shard key validation missing [gravitino]

jiangxt2 opened a new issue, #11802:
URL: https://github.com/apache/gravitino/issues/11802

   ### What would you like to be improved?
   
   There are two issues in the ClickHouse catalog's index and distributed table handling. Both are in the same file and involve pending TODO items from the same author, so I'm filing them together. Happy to split if preferred.
   
   **1. Index GRANULARITY hardcoded with wrong default for bloom_filter**
   
   `ClickHouseTableOperations.java` hardcodes GRANULARITY values in three locations:
   - `appendIndexesSql()` (line 486): minmax → `GRANULARITY 1`
   - `appendIndexesSql()` (line 495): bloom_filter → `GRANULARITY 3`
   - `addIndexDefinition()` (line 841, 845): same hardcoded values
   
   The bloom_filter default of `3` is incorrect — ClickHouse's actual default is `1`. This means tables created through Gravitino have different index behavior than tables created directly via SQL.
   
   Additionally, `getSecondaryIndexes()` (line 1243) queries `system.data_skipping_indices` but does not read the `granularity` column, losing round-trip fidelity.
   
   The TODO comments at lines 484 and 491 acknowledge this gap: `// TODO(yuqi) add a properties field to Index to support user defined GRANULARITY value.`
   
   The `Index.properties()` API (Index.java line 52) and `Indexes.of(type, name, fields, properties)` already exist — the infrastructure is ready.
   
   **2. Shard key validation only checks column existence, not type or nullability**
   
   `ClickHouseTableOperations.java` `handleDistributeTable()` (line 348-352) has a TODO: `// TODO(yuqi) WE need to check the columns in shard keys should be integer and not nullable`.
   
   Current validation (lines 359-369) only checks that the column name exists. ClickHouse itself rejects non-integer and nullable columns with `TYPE_MISMATCH`, but the error message is opaque. Client-side validation would provide clearer feedback.
   
   Verified on a local ClickHouse cluster:
   - `Nullable(Int64)` as shard key → server error: `Sharding expression has type Nullable(Int64), but should be one of integer type`
   - `String` as shard key → server error: `Sharding expression has type String, but should be one of integer type`
   
   ### How should we improve?
   
   **For GRANULARITY (3 locations in ClickHouseTableOperations.java):**
   - Read `index.properties().getOrDefault("granularity", "1")` instead of hardcoded values
   - In `getSecondaryIndexes()`, add `granularity` to the SELECT query and pass it via `Indexes.of(type, name, fields, Map.of("granularity", value))`
   - Fix bloom_filter default from `3` to `1` (ClickHouse actual default)
   
   **For shard key validation (handleDistributeTable):**
   - After finding the column, add:
     ```java
     Preconditions.checkArgument(!col.nullable(), 
         "Sharding key column '%s' must not be nullable", columnName);
     Preconditions.checkArgument(isIntegerType(col.dataType()), 
         "Sharding key column '%s' must be an integer type", columnName);
     ```
   


-- 
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.apache.org

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


Re: [I] [Bug] ClickHouse catalog: GRANULARITY hardcoded and shard key validation missing [gravitino]

Posted by "ArtificialIdoit (via GitHub)" <gi...@apache.org>.
ArtificialIdoit commented on issue #11802:
URL: https://github.com/apache/gravitino/issues/11802#issuecomment-4849709836

   Thanks for the detailed analysis. I agree this issue is valid and worth fixing.


-- 
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: [I] [Bug] ClickHouse catalog: GRANULARITY hardcoded and shard key validation missing [gravitino]

Posted by "cwq222 (via GitHub)" <gi...@apache.org>.
cwq222 commented on issue #11802:
URL: https://github.com/apache/gravitino/issues/11802#issuecomment-4849371814

   Great analysis! I fully agree with the two improvements proposed.


-- 
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: [I] [Bug] ClickHouse catalog: GRANULARITY hardcoded and shard key validation missing [gravitino]

Posted by "jiangxt2 (via GitHub)" <gi...@apache.org>.
jiangxt2 commented on issue #11802:
URL: https://github.com/apache/gravitino/issues/11802#issuecomment-4800468183

   I'd like to work on this. I've verified both issues on a local ClickHouse cluster and have a fix ready. Could you please assign this to me?


-- 
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: [I] [Bug] ClickHouse catalog: GRANULARITY hardcoded and shard key validation missing [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 closed issue #11802: [Bug] ClickHouse catalog: GRANULARITY hardcoded and shard key validation missing
URL: https://github.com/apache/gravitino/issues/11802


-- 
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