diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 4a1f5dc4e6a..bb1a27d265c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -135,6 +135,10 @@ Bug Fixes in zookeeper as UTF-8. This bug was found after upgrading to forbidden-apis 1.4. (Uwe Schindler) +* SOLR-4376: DataImportHandler uses wrong date format for last_index_time if + a delta-import is run first before any full-imports. + (Sebastien Lorber, Arcadius Ahouansou via shalin) + Optimizations ---------------------- diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHProperties.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHProperties.java index 0ea391c4974..911322eef82 100644 --- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHProperties.java +++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHProperties.java @@ -37,6 +37,8 @@ public abstract class DIHProperties { public abstract Map readIndexerProperties(); + public abstract String convertDateToString(Date d); + public Date getCurrentTimestamp() { return new Date(); } diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java index 01991de3611..d3e5230e866 100644 --- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java +++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DocBuilder.java @@ -117,6 +117,7 @@ public class DocBuilder { private VariableResolver getVariableResolver() { try { VariableResolver resolver = null; + String epoch = propWriter.convertDateToString(EPOCH); if(dataImporter != null && dataImporter.getCore() != null && dataImporter.getCore().getResourceLoader().getCoreProperties() != null){ resolver = new VariableResolver(dataImporter.getCore().getResourceLoader().getCoreProperties()); @@ -129,7 +130,7 @@ public class DocBuilder { indexerNamespace.put(LAST_INDEX_TIME, persistedProperties.get(LAST_INDEX_TIME)); } else { // set epoch - indexerNamespace.put(LAST_INDEX_TIME, EPOCH); + indexerNamespace.put(LAST_INDEX_TIME, epoch); } indexerNamespace.put(INDEX_START_TIME, dataImporter.getIndexStartTime()); indexerNamespace.put("request", new HashMap(reqParams.getRawParams())); @@ -140,7 +141,7 @@ public class DocBuilder { if (lastIndex != null) { entityNamespace.put(SolrWriter.LAST_INDEX_KEY, lastIndex); } else { - entityNamespace.put(SolrWriter.LAST_INDEX_KEY, EPOCH); + entityNamespace.put(SolrWriter.LAST_INDEX_KEY, epoch); } indexerNamespace.put(entity.getName(), entityNamespace); } diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java index 1d652b8d516..7967558a852 100644 --- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java +++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/SimplePropertiesWriter.java @@ -130,7 +130,8 @@ public class SimplePropertiesWriter extends DIHProperties { } - protected String convertDateToString(Date d) { + @Override + public String convertDateToString(Date d) { return dateFormat.format(d); } protected Date convertStringToDate(String s) { diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSqlEntityProcessorDelta.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSqlEntityProcessorDelta.java index 93928e61ff5..4fd3a61d114 100644 --- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSqlEntityProcessorDelta.java +++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestSqlEntityProcessorDelta.java @@ -23,7 +23,7 @@ import org.junit.Test; */ /** - * Test with various combinations of parameters, child entites, transformers. + * Test with various combinations of parameters, child entities, transformers. */ public class TestSqlEntityProcessorDelta extends AbstractSqlEntityProcessorTestCase { private boolean delta = false; @@ -48,6 +48,21 @@ public class TestSqlEntityProcessorDelta extends AbstractSqlEntityProcessorTestC singleEntity(c); validateChanges(); } + + @Test + public void testDeltaImportWithoutInitialFullImport() throws Exception { + log.debug("testDeltaImportWithoutInitialFullImport delta-import..."); + countryEntity = false; + delta = true; + /* + * We need to add 2 in total: + * +1 for deltaQuery i.e identifying id of items to update, + * +1 for deletedPkQuery i.e delete query + */ + singleEntity(totalPeople() + 2); + validateChanges(); + } + @Test public void testWithSimpleTransformer() throws Exception { log.debug("testWithSimpleTransformer full-import...");