Skip to content

Conversation

@bwdmr
Copy link
Contributor

@bwdmr bwdmr commented Jan 2, 2025

The WHERE clause will filter out these rows because NULL values do not satisfy either the IS NULL or the greater than conditions, effectively excluding them from the result set.

Turning the LEFT JOIN into an INNER JOIN for rows where NULL values would have been expected.

  • move includeDeleted checks from query to join, where the filter will be applied
  • copy filters over and add filter as necessary, on case deleted in not included
  • keep includeDeleted checks within query aswell, as null checks now can exists in where clause aswell.
  • adjust tests to reflect changes in code.

The WHERE clause will filter out these rows because NULL values do not satisfy either the IS NULL or the greater than conditions, effectively excluding them from the result set.

Turning the LEFT JOIN into an INNER JOIN for rows where NULL values would have been expected.

* move includeDeleted checks from query to join, where the filter will be applied
* copy filters over and add filter as necessary, on case deleted in not included
* keep includeDeleted checks within query aswell, as null checks now can exists in where clause aswell.
* adjust tests to reflect changes in code.
@bwdmr bwdmr requested a review from gwynne as a code owner January 2, 2025 13:02
@bwdmr bwdmr force-pushed the leftjointimestamp branch from 7c4f2c7 to 88fbec7 Compare January 19, 2025 14:45
@bwdmr bwdmr requested a review from gwynne January 19, 2025 14:46
@bwdmr bwdmr force-pushed the leftjointimestamp branch from 33236f1 to 983cd12 Compare January 20, 2025 01:11
@bwdmr bwdmr requested a review from 0xTim January 23, 2025 05:01
@codecov
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 24.42%. Comparing base (4f886eb) to head (b0b1544).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...es/FluentKit/Query/Builder/QueryBuilder+Join.swift 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #623      +/-   ##
==========================================
+ Coverage   24.22%   24.42%   +0.19%     
==========================================
  Files         149      149              
  Lines        9348     9373      +25     
==========================================
+ Hits         2265     2289      +24     
- Misses       7083     7084       +1     
Files with missing lines Coverage Δ
Sources/FluentKit/Properties/Timestamp.swift 87.37% <100.00%> (+2.49%) ⬆️
Sources/FluentKit/Query/Builder/QueryBuilder.swift 73.51% <100.00%> (ø)
...es/FluentKit/Query/Builder/QueryBuilder+Join.swift 56.81% <88.88%> (+3.06%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gwynne
Copy link
Member

gwynne commented Jan 31, 2025

It appears that the Mongo driver (or Mongo itself) can't handle this. @Joannis, can you provide any insight?

}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excess whitespace change, please remove

@bwdmr
Copy link
Contributor Author

bwdmr commented Feb 7, 2025

support for complex joins with filters is not implemented yet.

https://github.com/vapor/fluent-mongo-driver/blob/79bf35430e72e4290b3d08ac1eb8784d4e389c32/Sources/FluentMongoDriver/MongoDB%2BJoin.swift#L114

joins with filter would require a pipeline as in the following example

db.orders.aggregate([
  { $lookup: {
    from: "customers",
    let: { 
      orderId: "$customerId",
      orderDate: "$orderDate" 
    },
    pipeline: [
      { $match: {
        $expr: {
          $and: [
            { $eq: ["$_id", "$$orderId"] },
            { $gt: ["$memberSince", "$$orderDate"] },
            { $eq: ["$isVerified", true] }
          ]
        }
      }}
    ],
    as: "customerInfo"
  }}
])

gwynne and others added 3 commits February 7, 2025 06:46
* Add missing targets to api-docs.yml

* Add missing targets to pathsToInvalidate
…or#628)

The CompositeIDProperty was force-unwrapping its value during database input,
which would crash if the value was nil. This could happen during initial
inserts where the composite ID is meant to be set by a database trigger.
Now checks if value exists before attempting to input it.
@gwynne
Copy link
Member

gwynne commented Feb 7, 2025

A solution for the Mongo driver is being worked on (though not by me, as I neither have nor want any knowledge of Mongo 😅)

@bwdmr
Copy link
Contributor Author

bwdmr commented May 17, 2025

A solution for the Mongo driver is being worked on (though not by me, as I neither have nor want any knowledge of Mongo 😅)

can this be merged. i believe the mongo driver to be deprecated

@gwynne
Copy link
Member

gwynne commented May 17, 2025

Although the Mongo driver is deprecated for use in new Fluent 4 projects, it is unfortunately still in use by existing projects, and merging this would break normal usage for those users.

@bwdmr
Copy link
Contributor Author

bwdmr commented Oct 4, 2025

can we proceed. support for the mongo community could be included in a separate pr

@bwdmr bwdmr closed this Oct 29, 2025
@bwdmr bwdmr deleted the leftjointimestamp branch October 29, 2025 04:20
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.

4 participants