Red icon indicating copy to clipboard operation
Red copied to clipboard

Add comprehensive test coverage for EXISTS/NOT EXISTS subquery functionality

Open Copilot opened this issue 5 months ago • 0 comments

This PR adds comprehensive test coverage for the EXISTS/NOT EXISTS subquery functionality that was already implemented in Red ORM but not thoroughly tested.

Background

Issue #578 requested the ability to use EXISTS/NOT EXISTS as subqueries in Red ORM. The functionality was already implemented via the exists, is-empty, and manual Red::AST::Function approaches, but lacked proper test coverage to ensure it works as expected.

Changes

  • Added t/89-exists-subquery.rakutest with comprehensive test coverage for:
    • .exists method generating correct SQL with EXISTS clauses
    • .exists.not method generating correct SQL with NOT EXISTS clauses
    • .is-empty method (equivalent to .exists.not)
    • Manual Red::AST::Function approach with NOT EXISTS
    • Complex queries combining EXISTS checks with other conditions

Functionality Confirmed

All approaches mentioned in the original issue now work correctly:

# Recommended approach
my $last = StatsViewRefresh.^rs.max(*.refresh-time);
my $exists-not = StatsViewRefresh.^rs.exists.not;
Upload.^all.grep( -> $v { $exists-not OR $v.uploaded > $last }).so;

# Alternative approaches also work
StatsViewRefresh.^rs.is-empty
Red::AST::Function.new(args => [StatsViewRefresh.^rs.map(*.id).ast], func => 'NOT EXISTS')

These generate proper SQL with EXISTS/NOT EXISTS clauses as requested.

Fixes #578.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 360.zef.pm
    • Triggering command: curl --silent -L -z /home/REDACTED/.zef/store/360.zef.pm -o /home/REDACTED/.zef/store/360.zef.pm REDACTED (dns block)
    • Triggering command: wget -P /home/REDACTED/.zef/store --quiet REDACTED -O /home/REDACTED/.zef/store/360.zef.pm (dns block)
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Sep 11 '25 02:09 Copilot