-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use integers for date ordinals (#3346)
* Use integers for date ordinals * Add changelog * Adjust changelog
- Loading branch information
1 parent
c6122bc
commit 058e536
Showing
5 changed files
with
106 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...esources/ca/uhn/hapi/fhir/changelog/6_0_0/3346-always-use-integers-for-date-ordinals.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
type: fix | ||
issue: 3346 | ||
title: "When searching for date search parameters on Postgres, ordinals could sometimes be | ||
represented as strings, causing a search failure. This has been corrected." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...c/test/java/ca/uhn/fhir/jpa/search/builder/sql/SearchQueryBuilderDialectPostgresTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ca.uhn.fhir.jpa.search.builder.sql; | ||
|
||
import ca.uhn.fhir.jpa.api.config.DaoConfig; | ||
import ca.uhn.fhir.jpa.dao.predicate.SearchFilterParser; | ||
import ca.uhn.fhir.jpa.search.builder.predicate.BaseJoiningPredicateBuilder; | ||
import ca.uhn.fhir.jpa.search.builder.predicate.DatePredicateBuilder; | ||
import ca.uhn.fhir.jpa.search.builder.predicate.ResourceTablePredicateBuilder; | ||
import ca.uhn.fhir.rest.param.DateParam; | ||
import ca.uhn.fhir.rest.param.DateRangeParam; | ||
import com.healthmarketscience.sqlbuilder.Condition; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.hibernate.dialect.Dialect; | ||
import org.hibernate.dialect.PostgreSQL10Dialect; | ||
import org.hibernate.dialect.PostgreSQL95Dialect; | ||
import org.hibernate.dialect.SQLServer2012Dialect; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.util.Locale; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class SearchQueryBuilderDialectPostgresTest extends BaseSearchQueryBuilderDialectTest { | ||
|
||
/** | ||
* Make sure we're using integers and not strings as bind variables | ||
* for ordinals | ||
*/ | ||
@Test | ||
public void testOrdinalSearchesUseIntegerParameters() { | ||
DaoConfig daoConfig = new DaoConfig(); | ||
daoConfig.getModelConfig().setUseOrdinalDatesForDayPrecisionSearches(true); | ||
|
||
SearchQueryBuilder searchQueryBuilder = createSearchQueryBuilder(); | ||
when(mySqlObjectFactory.dateIndexTable(any())).thenReturn(new DatePredicateBuilder(searchQueryBuilder)); | ||
|
||
DatePredicateBuilder datePredicateBuilder = searchQueryBuilder.addDatePredicateBuilder(null); | ||
datePredicateBuilder.setDaoConfigForUnitTest(daoConfig); | ||
|
||
Condition datePredicate = datePredicateBuilder.createPredicateDateWithoutIdentityPredicate(new DateParam("2022"), SearchFilterParser.CompareOperation.eq); | ||
Condition comboPredicate = datePredicateBuilder.combineWithHashIdentityPredicate("Observation", "date", datePredicate); | ||
|
||
searchQueryBuilder.addPredicate(comboPredicate); | ||
|
||
GeneratedSql generatedSql = searchQueryBuilder.generate(0, 500); | ||
logSql(generatedSql); | ||
|
||
String sql = generatedSql.getSql(); | ||
assertEquals("SELECT t0.RES_ID FROM HFJ_SPIDX_DATE t0 WHERE ((t0.HASH_IDENTITY = ?) AND ((t0.SP_VALUE_LOW_DATE_ORDINAL >= ?) AND (t0.SP_VALUE_HIGH_DATE_ORDINAL <= ?))) limit ?", sql); | ||
|
||
assertEquals(4, StringUtils.countMatches(sql, "?")); | ||
assertEquals(4, generatedSql.getBindVariables().size()); | ||
assertEquals(123682819940570799L, generatedSql.getBindVariables().get(0)); | ||
assertEquals(20220101, generatedSql.getBindVariables().get(1)); | ||
assertEquals(20221231, generatedSql.getBindVariables().get(2)); | ||
assertEquals(500, generatedSql.getBindVariables().get(3)); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
protected Dialect createDialect() { | ||
return new PostgreSQL10Dialect(); | ||
} | ||
} |