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 query chained on sort bug where we over-filter results #5903

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up unit test and add changelog. Fix unit test.
  • Loading branch information
lukedegruchy committed May 2, 2024
commit ce7b58b5e808f577df091c533d033dfcd34f51f3
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
type: fix
issue: 5904
title: "Under certain conditions, when running a GET query with a chained sort and linked resources will return less
resources than expected, including a smaller total.
This has been fixed."
lukedegruchy marked this conversation as resolved.
Show resolved Hide resolved
u
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* Sandbox for implementing queries.
Expand Down Expand Up @@ -143,21 +144,24 @@ void testSortByPid() {

@Test
lukedegruchy marked this conversation as resolved.
Show resolved Hide resolved
void testChainedSort() {
final IIdType practitionerId = myDataBuilder.createPractitioner(myDataBuilder.withFamily("Jones"));

IIdType practitionerId = myDataBuilder.createPractitioner(myDataBuilder.withFamily("Jones"));

String id1 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithy")).getIdPart();
String id2 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithwick")).getIdPart();
String id3 = myDataBuilder.createPatient(
final String id1 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithy")).getIdPart();
final String id2 = myDataBuilder.createPatient(myDataBuilder.withFamily("Smithwick")).getIdPart();
final String id3 = myDataBuilder.createPatient(
myDataBuilder.withFamily("Smith"),
myDataBuilder.withReference("generalPractitioner", practitionerId)).getIdPart();


IBundleProvider iBundleProvider = myTestDaoSearch.searchForBundleProvider("Patient?_total=ACCURATE&_sort=Practitioner:general-practitioner.family");
final IBundleProvider iBundleProvider = myTestDaoSearch.searchForBundleProvider("Patient?_total=ACCURATE&_sort=Practitioner:general-practitioner.family");
assertEquals(3, iBundleProvider.size());
List<IBaseResource> allResources = iBundleProvider.getAllResources();

final List<IBaseResource> allResources = iBundleProvider.getAllResources();
assertEquals(3, iBundleProvider.size());
assertEquals(3, allResources.size());

final List<String> actualIds = allResources.stream().map(IBaseResource::getIdElement).map(IIdType::getIdPart).toList();
assertTrue(actualIds.containsAll(List.of(id1, id2, id3)));
}

public static final class TestDirtiesContextTestExecutionListener extends DirtiesContextTestExecutionListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public void testSearch_SortWithoutUpliftRefchain_SingleChain_String() {
String querySql = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, false);
assertEquals(1, countMatches(querySql, "HFJ_SPIDX_STRING"), querySql);
assertEquals(0, countMatches(querySql, "HASH_NORM_PREFIX"), querySql);
assertEquals(1, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(2, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(1, countMatches(querySql, "HFJ_RES_LINK"), querySql);
}

Expand Down Expand Up @@ -760,7 +760,7 @@ public void testSearch_SortWithoutUpliftRefchain_SingleChain_String_AlsoIncludes
String querySql = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, false);
assertEquals(2, countMatches(querySql, "HFJ_SPIDX_STRING"), querySql);
assertEquals(1, countMatches(querySql, "HASH_NORM_PREFIX"), querySql);
assertEquals(1, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(2, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(2, countMatches(querySql, "HFJ_RES_LINK"), querySql);
}

Expand Down Expand Up @@ -794,7 +794,7 @@ public void testSearch_SortWithoutUpliftRefchain_SingleChain_Token() {
assertEquals(2, myCaptureQueriesListener.getSelectQueriesForCurrentThread().size());
String querySql = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, false);
assertEquals(1, countMatches(querySql, "HFJ_SPIDX_TOKEN"), querySql);
assertEquals(1, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(2, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(1, countMatches(querySql, "HFJ_RES_LINK"), querySql);
}

Expand Down Expand Up @@ -828,7 +828,7 @@ public void testSearch_SortWithoutUpliftRefchain_SingleChain_Date() {
assertEquals(2, myCaptureQueriesListener.getSelectQueriesForCurrentThread().size());
String querySql = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, false);
assertEquals(1, countMatches(querySql, "HFJ_SPIDX_DATE"), querySql);
assertEquals(1, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(2, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(1, countMatches(querySql, "HFJ_RES_LINK"), querySql);
}

Expand Down Expand Up @@ -863,7 +863,7 @@ public void testSearch_SortWithoutUpliftRefchain_SingleChain_MultiTargetReferenc
String querySql = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, false);
assertEquals(1, countMatches(querySql, "HFJ_SPIDX_STRING"), querySql);
assertEquals(0, countMatches(querySql, "HASH_NORM_PREFIX"), querySql);
assertEquals(1, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(2, countMatches(querySql, "HASH_IDENTITY"), querySql);
assertEquals(1, countMatches(querySql, "HFJ_RES_LINK"), querySql);
}

Expand Down
Loading