Skip to content

Fix non-equi join error with equi + 2 inequality conditions (#7641)#7642

Open
tarun-t wants to merge 1 commit intoRdatatable:masterfrom
tarun-t:fix-nonequi-join-rightcols-7641
Open

Fix non-equi join error with equi + 2 inequality conditions (#7641)#7642
tarun-t wants to merge 1 commit intoRdatatable:masterfrom
tarun-t:fix-nonequi-join-rightcols-7641

Conversation

@tarun-t
Copy link

@tarun-t tarun-t commented Feb 14, 2026

Summary

Fixes #7641. Non-equi joins combining an equality condition with two inequality conditions on the same column (e.g., on = .(id == id, val >= lo, val <= hi)) error on
1.18.0+ due to rightcols being overwritten by chmatchdup.

When rightcols has duplicates (same x column in multiple conditions), chmatchdup remaps them into the expanded result namespace nx. This overwrote rightcols,
causing downstream code (.shallow(x, rightcols) in .join_result_key) to reference columns beyond ncol(x).

Fix: Introduce ansrightcols for the remapped indices, keep rightcols as original column indices into x. Only icolsAns needs the remapped values; all other
downstream uses need the original x-relative indices.

Changes

  • R/data.table.R: Replace rightcols = chmatchdup(...) with ansrightcols = chmatchdup(...), use ansrightcols only for icolsAns
  • inst/tests/tests.Rraw: Regression test (1483.91)
  • NEWS.md: Bug fix entry

…le#7641)

When rightcols contains duplicates (same x column in multiple non-equi
conditions), chmatchdup remaps them into the expanded result namespace.
This overwrote rightcols, causing downstream code (e.g. .shallow(x, rightcols)
in .join_result_key) to reference columns beyond ncol(x).

Introduce ansrightcols for the remapped indices and keep rightcols as
original column indices into x. Only icolsAns needs the remapped values;
all other uses (xcols, names_x[rightcols], .join_result_key) need the
original x-relative indices.

Closes Rdatatable#7641
@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.02%. Comparing base (1bd88cb) to head (20849ca).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7642   +/-   ##
=======================================
  Coverage   99.02%   99.02%           
=======================================
  Files          87       87           
  Lines       16896    16897    +1     
=======================================
+ Hits        16732    16733    +1     
  Misses        164      164           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Non-equi join with equi + 2 inequality conditions errors on 1.18.0+ (worked on 1.17.x)

1 participant