Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-565 Subquery alias with id fails to use correct alias with eq #2258

Merged
merged 3 commits into from
Sep 28, 2024

Conversation

bog-walk
Copy link
Member

Description

Summary of the change:
The aliased id column from a subquery now generates the correct aliased table identifier when used in an equality comparison with an unwrapped right-hand side value.

Detailed description:

  • Why:

    • In PR fix: EXPOSED-472 Alias IdTable fails with isNull and eq ops #2189 , a fix was implemented for the use of aliased tables with comparison operators that rely on mapIdComparison() and mapIdOperator(). The added tests only covered cases when the right-hand side of the operators was a wrapped EntityID value. Unwrapped values use operators that first need to wrap them as an EntityID instance, for which reason the invoking expression's table is found as an IdTable. The latter was then incorrectly being used to call mapIdComparison(), meaning that the column identifier used in SQL generation was the delegate non-aliased identifier.
  • How:

    • Equality operators that accept an unwrapped value on the right-hand side now have mapIdComparison() called directly on the invoking column's table, not the delegate IdTable used to create a wrapping EntityID instance.
    • Updated tests from previous fix to cover this case.

Type of Change

Please mark the relevant options with an "X":

  • Bug fix

Affected databases:

  • All

Checklist

  • Unit tests are in place
  • The build is green (including the Detekt check)

Related Issues

EXPOSED-565, EXPOSED-568, EXPOSED-472

@@ -339,7 +339,7 @@ interface ISqlExpressionBuilder {
val table = (columnType as EntityIDColumnType<*>).idColumn.table as IdTable<T>
val entityID = EntityID(t, table)
return if ((this as? Column<*>)?.isEntityIdentifier() == true) {
table.mapIdComparison(entityID, ::EqOp)
(this as Column<*>).table.mapIdComparison(entityID, ::EqOp)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: cast to Column<*> should not be required, because it's already check in the condition. The same for NeqOp

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed. Used this directly to make sure local property table isn't used.

…th eq

A fix for using mapIdComparison() with aliased table had been implemented, but
it did not fully cover the case when the right-hand side of the comparison involved
an unwrapped id column value. The latter was still using the delegate table associated
with the column type, instead of the invoking alias expression's alias table
identifier.
…th eq

- Add test that uses CompositeID on right-hand side
…th eq

- Remove unnecessary (this as Column<*>) cast
@bog-walk bog-walk merged commit ae28c53 into main Sep 28, 2024
5 checks passed
@bog-walk bog-walk deleted the bog-walk/fix-alias-id-eq branch September 28, 2024 14:39
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.

2 participants