[Cherry-pick to branch-1.3] [#12518] fix(trino-connector): Keep the engine types when applying projections - #12931
Merged
diqiu50 merged 1 commit intoSep 4, 2026
Conversation
…ing projections (apache#12520) ### What changes were proposed in this pull request? Restore the types the engine assigned to the projected variables when returning the result of `applyProjection`, instead of forwarding the types the internal connector derived from its own column handles. ### Why are the changes needed? Gravitino and the internal connector can describe the same column with different Trino types. A MySQL tinytext column is an unbounded varchar in the metadata layer but a varchar(255) in the internal connector, so pushing a projection down produced an assignment whose two sides disagreed. Since Trino 444 the planner verifies the types in an assignment, which turns the disagreement into `Types don't match: varchar vs varchar(255)` while the query is still being planned. The normalization is type-agnostic: it does not special-case any column type, so it also covers `enum` / `set` and any future divergence. Assignments for columns the internal connector synthesized for pushed-down expressions have no counterpart among the engine variables and keep their internal types. A pre-existing, separate defect is deliberately not addressed here: `MySQLDataTypeTransformer` truncates the declared precision of MySQL time/datetime columns to 0 on every Trino version, so selecting such columns already fails at result serialization today, with or without pushdown. It will be reported and fixed separately. `applyAggregation` intentionally stays unchanged: its returned assignment names are synthesized by the internal connector and have no engine-side variables to restore types from; the JDBC base connector already types them with the engine-supplied aggregate output types. Fix: apache#12518 ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? - Added `TestGravitinoMetadataApplyProjection` (5 cases, including a name-collision guard case): without the fix, the two restore cases fail with the mismatched types. - Added the `00015_projection_pushdown` tester to the jdbc-mysql test set: without the fix it reproduces the reported planner error (`Types don't match: varchar vs varchar(65535)`) on Trino 478; with the fix the whole jdbc-mysql test set passes (16/16). - Verified on Trino 443 (which has no assignment verification) that the change is a harmless normalization: the same queries return identical results. --------- Co-authored-by: yuhui <hui@datastrato.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> (cherry picked from commit a4bdfda)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is narrowly scoped, preserves existing behavior for synthesized columns, and is covered by both unit and integration tests targeting the reported failure mode.
Pull request overview
Cherry-picks a fix into branch-1.3 for the Trino connector’s applyProjection path so that projected column assignments keep the engine’s declared types (avoiding Trino plan type-mismatch failures when an internal JDBC connector reports a different type for the same underlying column handle).
Changes:
- Adjust
GravitinoMetadata#applyProjectionto restore assignment types from the engine’s projection expressions using column-handle-based matching (handles internal variable renames). - Add focused unit tests covering restored types, renames, nested expressions, and synthesized columns.
- Add a MySQL JDBC integration testset reproducing the projection pushdown scenario that previously triggered the type mismatch.
File summaries
| File | Description |
|---|---|
| trino-connector/trino-connector/src/test/java/org/apache/gravitino/trino/connector/TestGravitinoMetadataApplyProjection.java | New unit tests validating engine type preservation across several projection/assignment scenarios. |
| trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/GravitinoMetadata.java | Restores engine-assigned types for returned projection assignments, keyed by underlying column handles. |
| trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00015_projection_pushdown.sql | Adds an integration query that exercises projection pushdown with computed columns. |
| trino-connector/integration-test/src/test/resources/trino-ci-testset/testsets/jdbc-mysql/00015_projection_pushdown.txt | Expected output for the new MySQL projection pushdown testset. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Code Coverage Report
Files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cherry-pick Information:
branch-1.3