-
Notifications
You must be signed in to change notification settings - Fork 307
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
Join filter queries using Intersect and Union #2742
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great job thanks!
engine/src/main/java/com/google/android/fhir/search/MoreSearch.kt
Outdated
Show resolved
Hide resolved
SELECT a.resourceUuid, a.serializedResource | ||
FROM ResourceEntity a | ||
WHERE a.resourceUuid IN ( | ||
SELECT resourceUuid FROM StringIndexEntity | ||
WHERE resourceType = ? AND index_name = ? AND index_value = ? | ||
UNION | ||
SELECT resourceUuid FROM StringIndexEntity | ||
WHERE resourceType = ? AND index_name = ? AND index_value = ? | ||
INTERSECT | ||
SELECT resourceUuid | ||
FROM ResourceEntity a | ||
WHERE a.resourceType = ? AND a.resourceId IN ( | ||
SELECT substr(a.index_value, 9) | ||
FROM ReferenceIndexEntity a | ||
WHERE a.index_name = ? AND a.resourceUuid IN ( | ||
SELECT resourceUuid FROM TokenIndexEntity | ||
WHERE resourceType = ? AND index_name = ? AND (index_value = ? AND IFNULL(index_system,'') = ?) | ||
UNION | ||
SELECT resourceUuid FROM TokenIndexEntity | ||
WHERE resourceType = ? AND index_name = ? AND (index_value = ? AND IFNULL(index_system,'') = ?) | ||
) | ||
) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this won't perform as expected. The precedence of INTERSECTION is higher than UNION. Therefore, this query is interpreted as:
(Given: "John") UNION ( (Given: "Jane") INTERSECT (Condition: Diabetes OR Hypertension) )
This is not the intended logic. The test is trying to find Patients where:
( (Given: "John" OR Given: "Jane") AND (Condition: Diabetes OR Condition: Hypertens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you confirm this? And make changes if needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, will have a look
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Fixes #2725
Description
Clear and concise code change description.
Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?
Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)
Screenshots (if applicable)
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project../gradlew check
and./gradlew connectedCheck
to test my changes locally.