Skip to content

Fix SQLAlchemy true division semantics - #753

Merged
laughingman7743 merged 1 commit into
masterfrom
fix/sqlalchemy-true-division
Aug 11, 2026
Merged

Fix SQLAlchemy true division semantics#753
laughingman7743 merged 1 commit into
masterfrom
fix/sqlalchemy-true-division

Conversation

@laughingman7743

Copy link
Copy Markdown
Member

WHAT

  • Compile integer true division with a floating-point divisor.
  • Explicitly cast numeric and floating-point operands so Athena preserves SQLAlchemy true division semantics.
  • Re-enable the complete SQLAlchemy TrueDivTest compliance class.
  • Add compiler regression coverage for literal, bound, mixed numeric, and floating-point expressions.

Refs #736

WHY

Athena follows Trino integer and decimal coercion rules. The default SQLAlchemy compilation produced rounded integer results, a float instead of Decimal for numeric literals, and a REAL precision artifact for floating-point literals. Explicit type coercion makes all SQLAlchemy true division compliance cases return the expected values and Python types.

VALIDATION

  • just lint
  • .venv/bin/pytest tests/pyathena/sqlalchemy/test_compiler.py::TestAthenaStatementCompiler::test_visit_truediv_binary -n 1 -q (5 passed)
  • .venv/bin/pytest tests/sqlalchemy/test_suite.py::TrueDivTest -n 1 -q (9 passed)

SELF-REVIEW

  1. Correctness and regression: verified integer, decimal, mixed numeric/integer, and floating-point compilation; confirmed floor division remains unchanged; added literal-column and bound-parameter coverage.
  2. Maintainability and compatibility: reused SQLAlchemy type constructs and the existing cross-version double-type helper; confirmed no public API or DBAPI conversion changes.

@laughingman7743
laughingman7743 marked this pull request as ready for review August 11, 2026 07:55
@laughingman7743
laughingman7743 merged commit 5f0f784 into master Aug 11, 2026
15 checks passed
@laughingman7743
laughingman7743 deleted the fix/sqlalchemy-true-division branch August 11, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant