prql icon indicating copy to clipboard operation
prql copied to clipboard

fix: BETWEEN optimization now triggers by comparing expr kind, not span

Open queelius opened this issue 8 months ago • 0 comments

Summary

  • Fixes the try_into_between optimization which was dead code since it compared rq::Expr values including their span field
  • Changes comparison from a_l == b_l (full Expr including span) to a_l.kind == b_l.kind (semantic content only)
  • Adds regression test verifying BETWEEN is now generated

Fixes #5737

Before

from t | filter (a >= 5 && a <= 10)

Generated:

SELECT * FROM t WHERE a >= 5 AND a <= 10

After

SELECT * FROM t WHERE a BETWEEN 5 AND 10

Root Cause

rq::Expr derives PartialEq which includes the span field. The same column a referenced at two different source positions has the same CId but different Span values, so the equality check a_l == b_l always failed.

Test plan

  • [x] Added test_between_optimization regression test
  • [x] All 450 prqlc tests pass (including new test)
  • [x] Change is a one-line fix in the comparison logic

Generated with Claude Code

queelius avatar Mar 25 '26 08:03 queelius