Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-884 -- CachedSqlEntityProcessor should check if the cache key is present in the query results

Shalin Shekhar Mangarc1d1c274ae30
diff --git a/contrib/dataimporthandler/CHANGES.txt b/contrib/dataimporthandler/CHANGES.txt
index d0ee8e71bfa..a4cf9ffa2dd 100644
--- a/contrib/dataimporthandler/CHANGES.txt
+++ b/contrib/dataimporthandler/CHANGES.txt
@@ -76,6 +76,9 @@ Bug Fixes
11. SOLR-841: DataImportHandler should throw exception if a field does not have column attribute
(Michael Henson, shalin)
+12. SOLR-884: CachedSqlEntityProcessor should check if the cache key is present in the query results
+ (Noble Paul via shalin)
+
Documentation
----------------------
diff --git a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java
index 854ddb6efa8..278584b752c 100644
--- a/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java
+++ b/contrib/dataimporthandler/src/main/java/org/apache/solr/handler/dataimport/EntityProcessorBase.java
@@ -341,6 +341,12 @@ public class EntityProcessorBase extends EntityProcessor {
.get(query);
List<Map<String, Object>> rows = null;
Object key = resolver.resolve(cacheVariableName);
+ if (key == null) {
+ throw new DataImportHandlerException(DataImportHandlerException.WARN,
+ "The cache lookup value : " + cacheVariableName + " is resolved to be null in the entity :" +
+ context.getEntityAttribute("name"));
+
+ }
if (rowIdVsRows != null) {
rows = rowIdVsRows.get(key);
if (rows == null)
@@ -355,6 +361,17 @@ public class EntityProcessorBase extends EntityProcessor {
rowIdVsRows = new HashMap<Object, List<Map<String, Object>>>();
for (Map<String, Object> row : rows) {
Object k = row.get(cachePk);
+ if (k == null) {
+ throw new DataImportHandlerException(DataImportHandlerException.WARN,
+ "No value available for the cache key : " + cachePk + " in the entity : " +
+ context.getEntityAttribute("name"));
+ }
+ if (!k.getClass().equals(key.getClass())) {
+ throw new DataImportHandlerException(DataImportHandlerException.WARN,
+ "The key in the cache type : " + k.getClass().getName() +
+ "is not same as the lookup value type " + key.getClass().getName() + " in the entity " +
+ context.getEntityAttribute("name"));
+ }
if (rowIdVsRows.get(k) == null)
rowIdVsRows.put(k, new ArrayList<Map<String, Object>>());
rowIdVsRows.get(k).add(row);