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

   ### What changes were proposed in this pull request?
   
   When a ClickHouse table contains a PROJECTION with its own ORDER BY
   clause, Gravitino parses the wrong ORDER BY from the SHOW CREATE TABLE
   output and returns incorrect sort keys.
   
   This PR strips PROJECTION definition blocks from the DDL before applying
   the existing regex patterns, so the table-level ORDER BY / PARTITION BY /
   SETTINGS clauses are matched correctly.
   
   ### Why are the changes needed?
   
   A PROJECTION block sits inside the column-definition body of the DDL:
   
   ```sql
   CREATE TABLE t (
       `id` Int64,
       PROJECTION p_normal ( SELECT * ORDER BY dt ),
       `dt` Date
   )
   ENGINE = MergeTree
   ORDER BY (id, dt)
   ```
   
   The projection-internal `ORDER BY dt` appears before the table-level
   `ORDER BY (id, dt)`, so `find()` matches the wrong one. This affects
   any table with a Normal projection (projections with no ORDER BY, like
   Aggregate projections with only GROUP BY, are not affected).
   
   Fixes #11972
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Tables without projections are unaffected. For tables with
   projections, `sortOrder()` now returns the correct table-level sort keys
   instead of garbled projection-internal content.
   
   ### How was this patch tested?
   
   - Unit tests: 19 new tests covering Normal/Aggregate/Multiple projections,
     INDEX coexistence, projection at different positions, string literals
     containing "PROJECTION", and escaped string literals inside projection
     bodies.
   - Docker integration tests: 11 tests on real ClickHouse 24.8 covering
     inline CREATE, ALTER TABLE ADD PROJECTION, PARTITION BY + PRIMARY KEY,
     ReplacingMergeTree, complex sort keys, and projections at all positions.
   - Existing tests (SETTINGS, INDEX, type mapping) continue to pass.
   


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

Reply via email to