lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject [19/50] [abbrv] lucene-solr:apiv2: SOLR-6744: Consider uniqueKey rename when handling shard responses in distributed search
Date Wed, 07 Sep 2016 09:57:07 GMT
SOLR-6744: Consider uniqueKey rename when handling shard responses in distributed search


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/b3d12d26
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/b3d12d26
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/b3d12d26

Branch: refs/heads/apiv2
Commit: b3d12d265bb389f1ec239e8a96f044f7b89c01b1
Parents: 6bff06c
Author: Tomas Fernandez Lobbe <tflobbe@apache.org>
Authored: Fri Aug 26 16:10:48 2016 -0700
Committer: Tomas Fernandez Lobbe <tflobbe@apache.org>
Committed: Fri Aug 26 16:10:48 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                     |  3 +++
 .../solr/handler/component/QueryComponent.java       |  5 ++++-
 .../java/org/apache/solr/search/ReturnFields.java    |  7 +++++++
 .../org/apache/solr/search/SolrReturnFields.java     | 11 +++++++++++
 .../DistributedQueryComponentCustomSortTest.java     | 15 +++++++++++++--
 5 files changed, 38 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3d12d26/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index f4bf7a7..b502bf0 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -76,6 +76,9 @@ Bug Fixes
 
 * SOLR-9389: HDFS Transaction logs stay open for writes which leaks Xceivers. (Tim Owen via
Mark Miller)
 
+* SOLR-6744: fl renaming / alias of uniqueKey field generates null pointer exception in SolrCloud
configuration
+  (Mike Drob via Tomás Fernández Löbbe)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3d12d26/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
index 0e37439..ba6a68d 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -1305,6 +1305,10 @@ public class QueryComponent extends SearchComponent
 
       String keyFieldName = rb.req.getSchema().getUniqueKeyField().getName();
       boolean removeKeyField = !rb.rsp.getReturnFields().wantsField(keyFieldName);
+      if (rb.rsp.getReturnFields().getFieldRenames().get(keyFieldName) != null) {
+        // if id was renamed we need to use the new name
+        keyFieldName = rb.rsp.getReturnFields().getFieldRenames().get(keyFieldName);
+      }
 
       for (ShardResponse srsp : sreq.responses) {
         if (srsp.getException() != null) {
@@ -1330,7 +1334,6 @@ public class QueryComponent extends SearchComponent
           continue;
         }
         SolrDocumentList docs = (SolrDocumentList) srsp.getSolrResponse().getResponse().get("response");
-
         for (SolrDocument doc : docs) {
           Object id = doc.getFieldValue(keyFieldName);
           ShardDoc sdoc = rb.resultIds.get(id.toString());

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3d12d26/solr/core/src/java/org/apache/solr/search/ReturnFields.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/ReturnFields.java b/solr/core/src/java/org/apache/solr/search/ReturnFields.java
index dabfdd6..ec2b878 100644
--- a/solr/core/src/java/org/apache/solr/search/ReturnFields.java
+++ b/solr/core/src/java/org/apache/solr/search/ReturnFields.java
@@ -16,6 +16,7 @@
  */
 package org.apache.solr.search;
 
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.solr.response.transform.DocTransformer;
@@ -53,6 +54,12 @@ public abstract class ReturnFields {
    */
   public abstract Set<String> getRequestedFieldNames();
 
+  /**
+   * Get the fields which have been renamed
+   * @return a mapping of renamed fields
+   */
+  public abstract Map<String,String> getFieldRenames();
+
   /** Returns <code>true</code> if the specified field should be returned. */
   public abstract boolean wantsField(String name);
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3d12d26/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java b/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java
index 6382f45..2b1b303 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrReturnFields.java
@@ -35,9 +35,11 @@ import org.apache.solr.response.transform.TransformerFactory;
 import org.apache.solr.response.transform.ValueSourceAugmenter;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -64,6 +66,7 @@ public class SolrReturnFields extends ReturnFields {
   protected DocTransformer transformer;
   protected boolean _wantsScore = false;
   protected boolean _wantsAllFields = false;
+  protected Map<String,String> renameFields = Collections.emptyMap();
 
   public SolrReturnFields() {
     _wantsAllFields = true;
@@ -129,6 +132,9 @@ public class SolrReturnFields extends ReturnFields {
       }
       augmenters.addTransformer( new RenameFieldTransformer( from, to, copy ) );
     }
+    if (rename.size() > 0 ) {
+      renameFields = rename.asShallowMap();
+    }
     if( !_wantsAllFields && !globs.isEmpty() ) {
       // TODO??? need to fill up the fields with matching field names in the index
       // and add them to okFieldNames?
@@ -145,6 +151,11 @@ public class SolrReturnFields extends ReturnFields {
     }
   }
 
+  @Override
+  public Map<String,String> getFieldRenames() {
+    return renameFields;
+  }
+
   // like getId, but also accepts dashes for legacy fields
   public static String getFieldName(StrParser sp) {
     sp.eatws();

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/b3d12d26/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentCustomSortTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentCustomSortTest.java
b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentCustomSortTest.java
index 9e9401b..4b3e92a 100644
--- a/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentCustomSortTest.java
+++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedQueryComponentCustomSortTest.java
@@ -60,12 +60,19 @@ public class DistributedQueryComponentCustomSortTest extends BaseDistributedSear
     index(id, "12", "text", "d", "payload", ByteBuffer.wrap(new byte[] { 0x34, (byte)0xdd,
0x4d }));             //  7 
     index(id, "13", "text", "d", "payload", ByteBuffer.wrap(new byte[] { (byte)0x80, 0x11,
0x33 }));             // 12 
     commit();
-                                                                                        
 
+
     QueryResponse rsp;
+
     rsp = query("q", "*:*", "fl", "id", "sort", "payload asc", "rows", "20");
     assertFieldValues(rsp.getResults(), id, 7, 1, 6, 4, 2, 10, 12, 3, 5, 9, 8, 13, 11); 
     rsp = query("q", "*:*", "fl", "id", "sort", "payload desc", "rows", "20");
     assertFieldValues(rsp.getResults(), id, 11, 13, 8, 9, 5, 3, 12, 10, 2, 4, 6, 1, 7);
+
+    // SOLR-6744
+    rsp = query("q", "*:*", "fl", "key:id", "sort", "payload asc", "rows", "20");
+    assertFieldValues(rsp.getResults(), "key", 7, 1, 6, 4, 2, 10, 12, 3, 5, 9, 8, 13, 11);
+    rsp = query("q", "*:*", "fl", "key:id,id:text", "sort", "payload asc", "rows", "20");
+    assertFieldValues(rsp.getResults(), "key", 7, 1, 6, 4, 2, 10, 12, 3, 5, 9, 8, 13, 11);
     
     rsp = query("q", "text:a", "fl", "id", "sort", "payload asc", "rows", "20");
     assertFieldValues(rsp.getResults(), id, 1, 3, 5, 9);
@@ -76,7 +83,11 @@ public class DistributedQueryComponentCustomSortTest extends BaseDistributedSear
     assertFieldValues(rsp.getResults(), id, 4, 2, 10);
     rsp = query("q", "text:b", "fl", "id", "sort", "payload desc", "rows", "20");
     assertFieldValues(rsp.getResults(), id, 10, 2, 4);
-    
+
+    // SOLR-6744
+    rsp = query("q", "text:b", "fl", "key:id", "sort", "payload asc", "rows", "20");
+    assertFieldValues(rsp.getResults(), id, null, null, null);
+
     rsp = query("q", "text:c", "fl", "id", "sort", "payload asc", "rows", "20");
     assertFieldValues(rsp.getResults(), id, 7, 6, 8);
     rsp = query("q", "text:c", "fl", "id", "sort", "payload desc", "rows", "20");


Mime
View raw message