SOLR-1496 -- Last index time uses wrong date format

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@822904 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shalin Shekhar Mangar 2009-10-07 20:50:34 +00:00
parent 9a9499341f
commit 127bccd6d3
2 changed files with 43 additions and 6 deletions

View File

@ -83,11 +83,10 @@ public class DocBuilder {
VariableResolverImpl resolver = new VariableResolverImpl();
Map<String, Object> indexerNamespace = new HashMap<String, Object>();
if (persistedProperties.getProperty(LAST_INDEX_TIME) != null) {
indexerNamespace.put(LAST_INDEX_TIME,
DataImporter.DATE_TIME_FORMAT.get().parse(persistedProperties.getProperty(LAST_INDEX_TIME)));
indexerNamespace.put(LAST_INDEX_TIME, persistedProperties.getProperty(LAST_INDEX_TIME));
} else {
// set epoch
indexerNamespace.put(LAST_INDEX_TIME, EPOCH);
indexerNamespace.put(LAST_INDEX_TIME, DataImporter.DATE_TIME_FORMAT.get().format(EPOCH));
}
indexerNamespace.put(INDEX_START_TIME, dataImporter.getIndexStartTime());
indexerNamespace.put("request", requestParameters.requestParams);
@ -98,13 +97,13 @@ public class DocBuilder {
if (lastIndex != null) {
indexerNamespace.put(key, lastIndex);
} else {
indexerNamespace.put(key, EPOCH);
indexerNamespace.put(key, DataImporter.DATE_TIME_FORMAT.get().format(EPOCH));
}
}
resolver.addNamespace(DataConfig.IMPORTER_NS_SHORT, indexerNamespace);
resolver.addNamespace(DataConfig.IMPORTER_NS, indexerNamespace);
return resolver;
} catch (ParseException e) {
} catch (Exception e) {
DataImportHandlerException.wrapAndThrow(DataImportHandlerException.SEVERE, e);
// unreachable statement
return null;

View File

@ -20,7 +20,8 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.text.ParseException;
/**
* <p>
@ -187,6 +188,43 @@ public class TestSqlEntityProcessor2 extends AbstractDataImportHandlerTest {
assertQ(req("desc:hello"), "//*[@numFound='1']");
}
@Test
@SuppressWarnings("unchecked")
public void testLastIndexTime() throws Exception {
List row = new ArrayList();
row.add(createMap("id", 5));
MockDataSource.setIterator("select * from x where last_modified > OK", row.iterator());
super.runFullImport(dataConfig_LastIndexTime);
assertQ(req("id:5"), "//*[@numFound='1']");
}
static class DateFormatValidatingEvaluator extends Evaluator {
public String evaluate(String expression, Context context) {
List l = EvaluatorBag.parseParams(expression, context.getVariableResolver());
Object o = l.get(0);
String dateStr = null;
if (o instanceof EvaluatorBag.VariableWrapper) {
EvaluatorBag.VariableWrapper wrapper = (EvaluatorBag.VariableWrapper) o;
o = wrapper.resolve();
dateStr = o.toString();
}
SimpleDateFormat formatter = DataImporter.DATE_TIME_FORMAT.get();
try {
formatter.parse(dateStr);
} catch (ParseException e) {
DataImportHandlerException.wrapAndThrow(DataImportHandlerException.SEVERE, e);
}
return "OK";
}
}
private static String dataConfig_LastIndexTime = "<dataConfig>\n" +
"\t<function name=\"checkDateFormat\" class=\"org.apache.solr.handler.dataimport.TestSqlEntityProcessor2$DateFormatValidatingEvaluator\"/>\n" +
"\t<document>\n" +
"\t\t<entity name=\"x\" query=\"select * from x where last_modified > ${dih.functions.checkDateFormat(dih.last_index_time)}\" />\n" +
"\t</document>\n" +
"</dataConfig>";
private static String dataConfig = "<dataConfig>\n"
+ " <document>\n"
+ " <entity name=\"x\" pk=\"id\" query=\"select * from x\" deletedPkQuery=\"select id from x where last_modified > NOW AND deleted='true'\" deltaQuery=\"select id from x where last_modified > NOW\">\n"