Compare commits

...

3 Commits

Author SHA1 Message Date
Luke deGruchy b7aa544a2f
Merge 3c776ab363 into 3f6d1eb29b 2024-09-26 10:43:19 -04:00
Luke deGruchy 3c776ab363 Test experiment in pipelines. 2024-05-16 16:26:03 -04:00
Luke deGruchy a0e41439a6 Add sandbox test and log traces as well as TODO breadcrumbs. 2024-05-16 15:15:25 -04:00
4 changed files with 71 additions and 9 deletions

View File

@ -2675,6 +2675,7 @@ public class QueryStack {
}
}
// LUKETODO: we already have the HASH_SYS WHERE SQL here and nothing else
return toAndPredicate(andPredicates);
}

View File

@ -297,11 +297,14 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
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);
}
@ -677,14 +680,26 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
// 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);
// 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
addPidListPredicate(thePidList, sqlBuilder);
@ -743,6 +758,7 @@ public class SearchBuilder implements ISearchBuilder<JpaPid> {
private void executeSearch(
Integer theOffset, List<ISearchQueryExecutor> theSearchQueryExecutors, SearchQueryBuilder sqlBuilder) {
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);

View File

@ -646,6 +646,7 @@ public class SearchQueryBuilder {
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);
}

View File

@ -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;
@ -30,7 +33,10 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
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.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
@ -66,6 +72,8 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest {
DaoTestDataBuilder myDataBuilder;
@Autowired
TestDaoSearch myTestDaoSearch;
@Autowired
IBatch2DaoSvc myBatch2DaoSvc;
@Override
protected PlatformTransactionManager getTxManager() {
@ -162,6 +170,42 @@ public class FhirResourceDaoR4QuerySandbox extends BaseJpaTest {
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