lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject svn commit: r822904 - in /lucene/solr/trunk/contrib/dataimporthandler/src: main/java/org/apache/solr/handler/dataimport/DocBuilder.java test/java/org/apache/solr/handler/dataimport/TestSqlEntityProcessor2.java
Date Wed, 07 Oct 2009 20:50:38 GMT
Author: shalin
Date: Wed Oct  7 20:50:34 2009
New Revision: 822904

URL: http://svn.apache.org/viewvc?rev=822904&view=rev
Log:
SOLR-1496 -- Last index time uses wrong date format

Modified:
    lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
    lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestSqlEntityProcessor2.java

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java?rev=822904&r1=822903&r2=822904&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/DocBuilder.java
Wed Oct  7 20:50:34 2009
@@ -83,11 +83,10 @@
       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 @@
         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;

Modified: lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestSqlEntityProcessor2.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestSqlEntityProcessor2.java?rev=822904&r1=822903&r2=822904&view=diff
==============================================================================
--- lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestSqlEntityProcessor2.java
(original)
+++ lucene/solr/trunk/contrib/dataimporthandler/src/test/java/org/apache/solr/handler/dataimport/TestSqlEntityProcessor2.java
Wed Oct  7 20:50:34 2009
@@ -20,7 +20,8 @@
 
 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 @@
     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"



Mime
View raw message