Repository navigation
fix(trino): treat DECIMAL(p) as scale 0, not a default non-zero scale - #2404
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
WalkthroughBare and precision-only Trino ChangesDECIMAL Scale Default Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@core/wren/src/wren/connector/trino.py`:
- Around line 103-109: The Athena DECIMAL parsing logic is still using the old
Trino default and needs the same fix as the Trino connector. Update the DECIMAL
handling in the athena parser to match the semantics used in trino.py: bare
DECIMAL and DECIMAL(p) should default to precision 38 and scale 0, and any
precision-only DECIMAL path should avoid producing scale values larger than
precision. Make the change in the DECIMAL branch of the Athena connector parser
so both connectors stay consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 78d148e0-69e5-4363-9d05-317b227a13bb
📒 Files selected for processing (2)
core/wren/src/wren/connector/trino.pycore/wren/tests/connectors/test_trino.py
Mirror the Trino DECIMAL fix in the Athena connector parser, which shares the same Trino-flavoured type semantics. DECIMAL(p) is precision p with scale 0, and bare DECIMAL is DECIMAL(38, 0). The default scale of 9 mistyped precision-only DECIMAL columns and, for small precisions (e.g. DECIMAL(5)), produced scale > precision, which PyArrow rejects with ArrowInvalid. Addresses CodeRabbit review on Canner#2404.
|
Good catch — the Athena connector shares the same Trino-flavoured DECIMAL parsing and had the identical bug. Pushed 3d078e4 applying the same fix there: bare |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
core/wren/src/wren/connector/athena.py (1)
93-107: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAdd Athena DECIMAL regression tests core/wren/tests/unit/test_athena_connector.py only covers
decimal(12,4); add baredecimaland precision-only cases likedecimal(10)anddecimal(5)to keep Athena aligned with the Trino parser.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/wren/src/wren/connector/athena.py` around lines 93 - 107, Add regression coverage in test_athena_connector for Athena DECIMAL handling beyond decimal(12,4): include bare decimal, precision-only decimal(10), and a small precision case like decimal(5) to verify the Athena connector stays aligned with the Trino parser and the DECIMAL logic in the Athena type conversion path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@core/wren/src/wren/connector/athena.py`:
- Around line 93-107: Add regression coverage in test_athena_connector for
Athena DECIMAL handling beyond decimal(12,4): include bare decimal,
precision-only decimal(10), and a small precision case like decimal(5) to verify
the Athena connector stays aligned with the Trino parser and the DECIMAL logic
in the Athena type conversion path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 59517541-cb79-490b-8afe-5b86480b54b2
📒 Files selected for processing (1)
core/wren/src/wren/connector/athena.py
|
Added the requested Athena DECIMAL regression coverage in |
Address CodeRabbit review on Canner#2404: cover bare `decimal`, `decimal(10)`, and `decimal(5)` to keep the Athena connector aligned with the Trino parser's DECIMAL(p)=scale-0 handling.
|
Addressed the CodeRabbit suggestion in 2ed54d6: added |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code - If this code review was useful, please react with 👍. Otherwise, react with 👎. |
|
@Bartok9, there is some conflict. Could you resolve it? |
|
Thanks @goldmedal — and thanks for the review. Conflict resolved: merged latest |
…o scale Trino/Athena DECIMAL semantics: DECIMAL(p) is precision p with scale 0, and bare DECIMAL is DECIMAL(38, 0). The previous default of scale 9 mistyped precision-only DECIMAL columns and, for small precisions (e.g. DECIMAL(5)), produced scale > precision which PyArrow rejects with ArrowInvalid. Adds regression tests for bare DECIMAL, DECIMAL(p), and small-precision cases in both the Trino and Athena connectors.
62a6824 to
005c906
Compare
|
Thanks @goldmedal — conflict resolved. ✅ The branch had picked up a tangled history (duplicate commits + merge commits) after the ibis-drop refactor (#2313) landed on main. I've rebased it onto current
CI is re-running on the clean commit; lint already green. Should be a clean merge now — let me know if you'd like anything else adjusted. 🙏 |
Summary
DECIMAL(p)(precision only) and bareDECIMALto a PyArrow decimal with a default scale of 9 instead of scale0.DECIMALcolumn, and for small precisions (e.g.DECIMAL(5)) producesscale > precision, which PyArrow rejects outright.Root Cause
Symptom — Columns declared as
DECIMAL(p)(or bareDECIMAL) in Trino come back fromwrenwith a fractional scale (e.g.DECIMAL(10)→decimal128(10, 9)). For small precisions likeDECIMAL(5), materialising the result table raisespyarrow.lib.ArrowInvalidbecause the requested scale (9) exceeds the precision (5).Root cause — In
_trino_data_type_to_arrow(core/wren/src/wren/connector/trino.py), theT.DECIMALbranch initialisesprecision, scale = 38, 9. The scale is only overwritten when an explicit second parameter is present. But in TrinoDECIMAL(p)means precisionpwith scale 0, and bareDECIMALisDECIMAL(38, 0). The non-zero default scale is wrong.Evidence — Before the fix, on current
main:The existing test even codified the wrong default (
("decimal", pa.decimal128(38, 9))); it is corrected here to(38, 0).Fix + why this level — Change the default to
precision, scale = 38, 0. This is the correct layer: the cursor-type → Arrow mapping is the single place Trino DECIMAL types are interpreted, so fixing the default here corrects schema typing, value coercion, and avoids the downstream ArrowInvalid without touching any caller. The explicitDECIMAL(p, s)path is unchanged.Scope / risk — Touches only the
T.DECIMALbranch in the Trino connector (and the corresponding test expectations).DECIMAL(p, s)behaviour is identical. This mirrors the same fix in the Athena connector (#2403); the two connectors share the Trino-flavoured type grammar.Verification
uv run --no-sync pytest tests/connectors/test_trino.py -k data_type— 40 passed (was 37; +3 new cases).ruff format --check src/+ruff check src/— clean.Real behavior proof
Captured from a real run on this branch (
uv run python3):Regression cases (added to the parametrized
test_parse_trino_data_type) assert the new shape and FAIL on currentmain:All three pass with the fix.
Summary by CodeRabbit
DECIMALtypes so bareDECIMALand precision-onlyDECIMAL(p)now default to scale0.DECIMAL(5)) to prevent invalid decimal definitions during conversion.DECIMALparsing behavior.