Apache Lucene open-source search software
SOLR-2947: fix 'where' clause bug on CachedSqlEntityProcessor (introduced w/SOLR-2382)
James Dyerfd6c1e657a67
diff --git a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.javaindex c042bfa86ac..dc99c1e8d10 100644--- a/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java+++ b/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/DIHCacheSupport.java@@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;public class DIHCacheSupport {private static final Logger log = LoggerFactory.getLogger(DIHCacheSupport.class);- private String cacheVariableName;+ private String cacheForeignKey;private String cacheImplName;private Map<String,DIHCache> queryVsCache = new HashMap<String,DIHCache>();private Map<String,Iterator<Map<String,Object>>> queryVsCacheIterator;@@ -27,10 +27,8 @@ public class DIHCacheSupport {this.cacheImplName = cacheImplName;String where = context.getEntityAttribute("where");- String cacheKey = context- .getEntityAttribute(DIHCacheSupport.CACHE_PRIMARY_KEY);- String lookupKey = context- .getEntityAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY);+ String cacheKey = context.getEntityAttribute(DIHCacheSupport.CACHE_PRIMARY_KEY);+ String lookupKey = context.getEntityAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY);if (cacheKey != null && lookupKey == null) {throw new DataImportHandlerException(DataImportHandlerException.SEVERE,"'cacheKey' is specified for the entity "@@ -43,15 +41,16 @@ public class DIHCacheSupport {} else {if (where != null) {String[] splits = where.split("=");- cacheVariableName = splits[1].trim();+ cacheKey = splits[0];+ cacheForeignKey = splits[1].trim();} else {- cacheVariableName = lookupKey;+ cacheForeignKey = lookupKey;}cacheDoKeyLookup = true;}context.setSessionAttribute(DIHCacheSupport.CACHE_PRIMARY_KEY, cacheKey,Context.SCOPE_ENTITY);- context.setSessionAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY, lookupKey,+ context.setSessionAttribute(DIHCacheSupport.CACHE_FOREIGN_KEY, cacheForeignKey,Context.SCOPE_ENTITY);context.setSessionAttribute(DIHCacheSupport.CACHE_DELETE_PRIOR_DATA,"true", Context.SCOPE_ENTITY);@@ -90,7 +89,7 @@ public class DIHCacheSupport {}queryVsCache = null;dataSourceRowCache = null;- cacheVariableName = null;+ cacheForeignKey = null;}/**@@ -142,10 +141,10 @@ public class DIHCacheSupport {*/protected Map<String,Object> getIdCacheData(Context context, String query,Iterator<Map<String,Object>> rowIterator) {- Object key = context.resolve(cacheVariableName);+ Object key = context.resolve(cacheForeignKey);if (key == null) {throw new DataImportHandlerException(DataImportHandlerException.WARN,- "The cache lookup value : " + cacheVariableName+ "The cache lookup value : " + cacheForeignKey+ " is resolved to be null in the entity :"+ context.getEntityAttribute("name"));diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.javaindex af1a3b2538a..e6dead10157 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/AbstractDataImportHandlerTestCase.java@@ -36,6 +36,7 @@ import java.io.FileOutputStream;import java.io.IOException;import java.io.File;import java.util.HashMap;+import java.util.LinkedHashMap;import java.util.List;import java.util.Map;@@ -148,7 +149,7 @@ public abstract class AbstractDataImportHandlerTestCase extends*/@SuppressWarnings("unchecked")public static Map createMap(Object... args) {- Map result = new HashMap();+ Map result = new LinkedHashMap();if (args == null || args.length == 0)return result;diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.javaindex e945a15eb32..e2cf59f324a 100644--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestCachedSqlEntityProcessor.java@@ -184,7 +184,7 @@ public class TestCachedSqlEntityProcessor extends AbstractDataImportHandlerTestC}@Test- public void withWhereClause() {+ public void withKeyAndLookup() {List fields = new ArrayList();fields.add(createMap("column", "id"));fields.add(createMap("column", "desc"));@@ -200,7 +200,7 @@ public class TestCachedSqlEntityProcessor extends AbstractDataImportHandlerTestC}@Test- public void withKeyAndLookup() {+ public void withWhereClause() {List fields = new ArrayList();fields.add(createMap("column", "id"));fields.add(createMap("column", "desc"));@@ -216,7 +216,7 @@ public class TestCachedSqlEntityProcessor extends AbstractDataImportHandlerTestCprivate void doWhereTest(String q, Context context, MockDataSource ds, Map xNamespace) {List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();- rows.add(createMap("id", 1, "desc", "one"));+ rows.add(createMap("desc", "one", "id", 1));rows.add(createMap("id", 2, "desc", "two"));rows.add(createMap("id", 2, "desc", "another two"));rows.add(createMap("id", 3, "desc", "three"));