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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sandbox test and log traces as well as TODO breadcrumbs. #5943

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,7 @@ private Condition createPredicateSearchParameter(
}
}

// LUKETODO: we already have the HASH_SYS WHERE SQL here and nothing else
return toAndPredicate(andPredicates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,14 @@ private void searchForIdsWithAndOr(
continue;
}
List<List<IQueryParameterType>> andOrParams = myParams.get(nextParamName);
Condition predicate = theQueryStack.searchForIdsWithAndOr(with().setResourceName(myResourceName)
final QueryStack.SearchForIdsParams searchForIdsParams = with().setResourceName(myResourceName)
.setParamName(nextParamName)
.setAndOrParams(andOrParams)
.setRequest(theRequest)
.setRequestPartitionId(myRequestPartitionId));
// .setSourceJoinColumn(theQueryStack.) ????
.setRequestPartitionId(myRequestPartitionId);
// LUKETODO: setResourceName appears NOT to work here?!?!?!??!??!?!
Condition predicate = theQueryStack.searchForIdsWithAndOr(searchForIdsParams);
if (predicate != null) {
theSearchSqlBuilder.addPredicate(predicate);
}
Expand Down Expand Up @@ -672,14 +675,26 @@ private void createChunkedQuery(

// If we haven't added any predicates yet, we're doing a search for all resources. Make sure we add the
// partition ID predicate in that case.
if (!sqlBuilder.haveAtLeastOnePredicate()) {
Condition partitionIdPredicate = sqlBuilder
.getOrCreateResourceTablePredicateBuilder()
.createPartitionIdPredicate(myRequestPartitionId);
if (partitionIdPredicate != null) {
sqlBuilder.addPredicate(partitionIdPredicate);
}
}
// LUKETODO: commenting this out seems to fix the problem
// if (!sqlBuilder.haveAtLeastOnePredicate()) {
// LUKETODO: this is where we add the RES_TYPE clause
// LUKETODO: we skip this in the failing case because there's no predicate??????
Condition partitionIdPredicate =
sqlBuilder.getOrCreateResourceTablePredicateBuilder().createPartitionIdPredicate(myRequestPartitionId);
if (partitionIdPredicate != null) {
sqlBuilder.addPredicate(partitionIdPredicate);
}
// }
// // If we haven't added any predicates yet, we're doing a search for all resources. Make sure we add the

// // partition ID predicate in that case.
// if (!sqlBuilder.haveAtLeastOnePredicate()) {
// Condition partitionIdPredicate =
// sqlBuilder.getOrCreateResourceTablePredicateBuilder().createPartitionIdPredicate(myRequestPartitionId);
// if (partitionIdPredicate != null) {
// sqlBuilder.addPredicate(partitionIdPredicate);
// }
// }

// Add PID list predicate for full text search and/or lastn operation
if (thePidList != null && thePidList.size() > 0) {
Expand Down Expand Up @@ -739,6 +754,7 @@ private void createChunkedQuery(
* Now perform the search
*/
GeneratedSql generatedSql = sqlBuilder.generate(theOffset, myMaxResultsToFetch);
ourLog.info("6086: generatedSql:\n{}\nparams:\n{}", generatedSql.getSql(), generatedSql.getBindVariables());
if (!generatedSql.isMatchNothing()) {
SearchQueryExecutor executor =
mySqlBuilderFactory.newSearchQueryExecutor(generatedSql, myMaxResultsToFetch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ public ResourceTablePredicateBuilder getOrCreateResourceTablePredicateBuilder(
ResourceTablePredicateBuilder resourceTable = mySqlBuilderFactory.resourceTable(this);
addTable(resourceTable, null);
if (theIncludeResourceTypeAndNonDeletedFlag) {
// LUKETODO: this is where we add the RES_TYPE clause
Condition typeAndDeletionPredicate = resourceTable.createResourceTypeAndNonDeletedPredicates();
addPredicate(typeAndDeletionPredicate);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package ca.uhn.fhir.jpa.dao.r4;

import ca.uhn.fhir.batch2.jobs.step.ResourceIdListStep;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.interceptor.api.Hook;
import ca.uhn.fhir.interceptor.api.Pointcut;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.svc.IBatch2DaoSvc;
import ca.uhn.fhir.jpa.dao.TestDaoSearch;
import ca.uhn.fhir.jpa.test.BaseJpaTest;
import ca.uhn.fhir.jpa.test.config.TestHSearchAddInConfig;
Expand Down Expand Up @@ -30,7 +33,10 @@
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.transaction.PlatformTransactionManager;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -68,6 +74,8 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest {
DaoTestDataBuilder myDataBuilder;
@Autowired
TestDaoSearch myTestDaoSearch;
@Autowired
IBatch2DaoSvc myBatch2DaoSvc;

@Override
protected PlatformTransactionManager getTxManager() {
Expand Down Expand Up @@ -164,6 +172,42 @@ void testChainedSort() {
assertTrue(actualIds.containsAll(List.of(id1, id2, id3)));
}

// LUKETODO: consider @Nested class
@Test
void testDeleteExpunge1() {
// SearchParameterMap[params={event=[[TokenParam[system=http://terminology.hl7.org/CodeSystem/v2-0003,value=], TokenParam[system=https://harris-chr.com/fhir/CodeSystem/arc-interface-trigger,value=]]]}]
// MessageHeader?event=http://terminology.hl7.org/CodeSystem/v2-0003|,https://harris-chr.com/fhir/CodeSystem/arc-interface-trigger|&_lastUpdated=ge2023-09-17T00:00:00.000000Z&_lastUpdated=le2025-09-23T23:59:59.999999Z&_expunge=true
// myTestDaoSearch.searchForResources("MessageHeader?event=http://terminology.hl7.org/CodeSystem/v2-0003|,https://harris-chr.com/fhir/CodeSystem/arc-interface-trigger|&_lastUpdated=ge2023-09-17T00:00:00.000000Z&_lastUpdated=le2025-09-23T23:59:59.999999Z&_expunge=true");
final LocalDateTime startDateTime = LocalDateTime.now().minusDays(2);
final Date startDate = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
final LocalDateTime endDateTime = LocalDateTime.now().minusDays(1);
final Date endDate = Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant());

myBatch2DaoSvc.fetchResourceIdStream(startDate, endDate, RequestPartitionId.allPartitions(), "MessageHeader?event=http://terminology.hl7.org/CodeSystem/v2-0003|,https://harris-chr.com/fhir/CodeSystem/arc-interface-trigger|&_lastUpdated=ge2023-09-17T00:00:00.000000Z&_lastUpdated=le2025-09-23T23:59:59.999999Z&_expunge=true")
.visitStreamNoResult(x -> {
var z = x.toList();
});
final List<String> queries = myCapturedQueries.stream().toList();

ourLog.info("queries: {}", queries);
}

@Test
void testDeleteExpunge2() {
final LocalDateTime startDateTime = LocalDateTime.now().minusDays(2);
final Date startDate = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
final LocalDateTime endDateTime = LocalDateTime.now().minusDays(1);
final Date endDate = Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant());

myBatch2DaoSvc.fetchResourceIdStream(startDate, endDate, RequestPartitionId.allPartitions(), "MessageHeader?_lastUpdated=ge2023-09-17T00:00:00.000000Z&_lastUpdated=le2025-09-23T23:59:59.999999Z&_expunge=true")
.visitStreamNoResult(x -> {
var z = x.toList();
});
final List<String> queries = myCapturedQueries.stream().toList();

ourLog.info("queries: {}", queries);
}

public static final class TestDirtiesContextTestExecutionListener extends DirtiesContextTestExecutionListener {

@Override
Expand Down
Loading