Rework selection generation of calculator. Add null check for empty dates

This commit is contained in:
Tadgh 2020-03-03 16:07:25 -08:00
parent a510543933
commit 8b223a1fd9
5 changed files with 24 additions and 6 deletions

View File

@ -20,7 +20,6 @@ package ca.uhn.fhir.jpa.migrate.taskdef;
* #L%
*/
import ca.uhn.fhir.jpa.migrate.JdbcUtils;
import ca.uhn.fhir.util.StopWatch;
import ca.uhn.fhir.util.VersionEnum;
import com.google.common.collect.ForwardingMap;
@ -77,8 +76,9 @@ public abstract class BaseColumnCalculatorTask extends BaseTableColumnTask<BaseC
getTxTemplate().execute(t -> {
JdbcTemplate jdbcTemplate = newJdbcTemplate();
jdbcTemplate.setMaxRows(100000);
String sql = "SELECT * FROM " + getTableName() + " WHERE " + getColumnName() + " IS NULL";
logInfo(ourLog, "Finding up to {} rows in {} that requires calculations", myBatchSize, getTableName());
String sql = "SELECT * FROM " + getTableName() + " WHERE " + getWhereClause();
logInfo(ourLog, "Finding up to {} rows in {} that requires calculations, using query: {}", myBatchSize, getTableName(), sql);
jdbcTemplate.query(sql, rch);
rch.done();

View File

@ -30,6 +30,8 @@ import java.util.Locale;
public abstract class BaseTableColumnTask<T extends BaseTableTask<T>> extends BaseTableTask<T> {
private String myColumnName;
//If a concrete class decides to, they can define a custom WHERE clause for the task.
private String myWhereClause;
public BaseTableColumnTask(String theProductVersion, String theSchemaVersion) {
super(theProductVersion, theSchemaVersion);
@ -41,11 +43,21 @@ public abstract class BaseTableColumnTask<T extends BaseTableTask<T>> extends Ba
return (T) this;
}
public String getColumnName() {
return myColumnName;
}
protected void setWhereClause(String theWhereClause) {
this.myWhereClause = theWhereClause;
}
protected String getWhereClause() {
if (myWhereClause == null) {
return getColumnName() + " IS NULL";
} else {
return myWhereClause;
}
}
@Override
public void validate() {
super.validate();

View File

@ -27,6 +27,8 @@ import org.apache.commons.lang3.builder.HashCodeBuilder;
public abstract class BaseTableTask<T extends BaseTableTask<T>> extends BaseTask<T> {
private String myTableName;
public BaseTableTask(String theProductVersion, String theSchemaVersion) {
super(theProductVersion, theSchemaVersion);
}
@ -34,7 +36,6 @@ public abstract class BaseTableTask<T extends BaseTableTask<T>> extends BaseTask
public String getTableName() {
return myTableName;
}
public T setTableName(String theTableName) {
Validate.notBlank(theTableName);
myTableName = theTableName;

View File

@ -26,8 +26,10 @@ public class CalculateOrdinalDatesTask extends BaseColumnCalculatorTask {
public CalculateOrdinalDatesTask(VersionEnum theRelease, String theVersion) {
super(theRelease, theVersion);
setDescription("Calculate SP_LOW_VALUE_DATE and SP_HIGH_VALUE_DATE based on existing SP_LOW and SP_HIGH date values in Date Search Params");
setDescription("Calculate SP_LOW_VALUE_DATE_ORDINAL and SP_HIGH_VALUE_DATE_ORDINAL based on existing SP_VALUE_LOW and SP_VALUE_HIGH date values in Date Search Params");
setWhereClause("SP_VALUE_LOW_DATE_ORDINAL IS NULL AND SP_VALUE_LOW IS NOT NULL) OR (SP_VALUE_HIGH_DATE_ORDINAL IS NULL AND SP_VALUE_HIGH IS NOT NULL");
}
@Override
protected boolean shouldSkipTask() {
return false; // TODO Is there a case where we should just not do this?

View File

@ -298,6 +298,9 @@ public class ResourceIndexedSearchParamDate extends BaseResourceIndexedSearchPar
public static Long calculateOrdinalValue(Date theDate) {
if (theDate == null) {
return null;
}
return (long) DateUtils.convertDatetoDayInteger(theDate);
}