From c1d1c274ae30d7c002a9f31cf6c7ae34b5e55315 Mon Sep 17 00:00:00 2001 From: Shalin Shekhar Mangar Date: Thu, 11 Dec 2008 13:43:23 +0000 Subject: [PATCH] SOLR-884 -- CachedSqlEntityProcessor should check if the cache key is present in the query results git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@725684 13f79535-47bb-0310-9956-ffa450edef68 --- contrib/dataimporthandler/CHANGES.txt | 3 +++ .../handler/dataimport/EntityProcessorBase.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) 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> 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>>(); for (Map 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>()); rowIdVsRows.get(k).add(row);