This is an automated email from the ASF dual-hosted git repository.

thelabdude pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 8e74f9f  SOLR-15570: Check stored or docValues when merging fields 
from the Luke schema response (#244)
8e74f9f is described below

commit 8e74f9fa2db83a010034d1153c98262bb86fda82
Author: Timothy Potter <[email protected]>
AuthorDate: Mon Aug 2 13:06:57 2021 -0600

    SOLR-15570: Check stored or docValues when merging fields from the Luke 
schema response (#244)
---
 .../src/java/org/apache/solr/handler/sql/SolrSchema.java  | 12 +++++++++++-
 .../src/test-files/solr/configsets/sql/conf/schema.xml    |  3 +++
 .../src/test/org/apache/solr/handler/TestSQLHandler.java  | 15 ++++++++++-----
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java 
b/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java
index d527018..b5c99e3 100644
--- a/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java
+++ b/solr/core/src/java/org/apache/solr/handler/sql/SolrSchema.java
@@ -19,6 +19,7 @@ package org.apache.solr.handler.sql;
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.Date;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -43,6 +44,7 @@ import org.apache.solr.client.solrj.response.LukeResponse;
 import org.apache.solr.common.cloud.Aliases;
 import org.apache.solr.common.cloud.ClusterState;
 import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.luke.FieldFlag;
 import org.apache.solr.schema.DateValueFieldType;
 import org.apache.solr.schema.DoubleValueFieldType;
 import org.apache.solr.schema.FloatValueFieldType;
@@ -127,6 +129,10 @@ class SolrSchema extends AbstractSchema implements 
Closeable {
       PKIAuthenticationPlugin.withServerIdentity(false);
     }
   }
+
+  private boolean isStoredOrDocValues(final EnumSet<FieldFlag> flags) {
+    return flags != null && (flags.contains(FieldFlag.STORED) || 
flags.contains(FieldFlag.DOC_VALUES));
+  }
   
   RelProtoDataType getRelDataType(String collection) {
     // Temporary type factory, just for the duration of this method. Allowable
@@ -139,8 +145,12 @@ class SolrSchema extends AbstractSchema implements 
Closeable {
     Map<String, LukeResponse.FieldInfo> fieldsInUseMap = 
getFieldInfo(collection);
 
     LukeResponse schema = getSchema(collection);
+    // Only want fields that are stored or have docValues enabled
+    Map<String, LukeResponse.FieldInfo> storedFields = 
schema.getFieldInfo().entrySet().stream()
+            .filter(e -> isStoredOrDocValues(e.getValue().getFlags()))
+            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
     // merge the actual fields in use returned by Luke with the declared 
fields in the schema that are empty
-    Map<String, LukeResponse.FieldInfo> combinedFields = 
Stream.of(fieldsInUseMap, schema.getFieldInfo())
+    Map<String, LukeResponse.FieldInfo> combinedFields = 
Stream.of(fieldsInUseMap, storedFields)
             .flatMap(map -> map.entrySet().stream())
             .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, 
(v1, v2) -> v1));
 
diff --git a/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml 
b/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml
index f0872a8..0638a79 100644
--- a/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml
+++ b/solr/core/src/test-files/solr/configsets/sql/conf/schema.xml
@@ -66,6 +66,9 @@
   <field name="pdatex" type="pdatex" indexed="true" stored="true"/>
   <field name="pdatexs" type="pdatex" indexed="true" stored="true" 
multiValued="true"/>
 
+  <field name="notstored" type="string" indexed="true" docValues="false" 
stored="false"/>
+  <field name="dvonly" type="string" docValues="true" stored="false"/>
+
   <!-- Field type demonstrating an Analyzer failure -->
   <fieldType name="failtype1" class="solr.TextField">
     <analyzer type="index">
diff --git a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java 
b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
index f7209a1..a1a2882 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
@@ -2236,16 +2236,21 @@ public class TestSQLHandler extends SolrCloudTestCase {
   @Test
   public void testSelectEmptyField() throws Exception {
     new UpdateRequest()
-        .add("id", "01")
-        .add("id", "02")
-        .add("id", "03")
-        .add("id", "04")
-        .add("id", "05")
+        .add("id", "01", "notstored", "X", "dvonly", "Y")
+        .add("id", "02", "notstored", "X", "dvonly", "Y")
+        .add("id", "03", "notstored", "X", "dvonly", "Y")
+        .add("id", "04", "notstored", "X", "dvonly", "Y")
+        .add("id", "05", "notstored", "X", "dvonly", "Y")
         .commit(cluster.getSolrClient(), COLLECTIONORALIAS);
 
     // stringx is declared in the schema but has no docs
     expectResults("SELECT id, stringx FROM $ALIAS", 5);
+    expectResults("SELECT id, stringx FROM $ALIAS LIMIT 10", 5);
+    expectResults("SELECT id, stringx, dvonly FROM $ALIAS", 5);
+    expectResults("SELECT id, stringx, dvonly FROM $ALIAS LIMIT 10", 5);
+
     // notafield_i matches a dynamic field pattern but has no docs, so don't 
allow this
     expectThrows(IOException.class, () -> expectResults("SELECT id, stringx, 
notafield_i FROM $ALIAS", 5));
+    expectThrows(IOException.class, () -> expectResults("SELECT id, stringx, 
notstored FROM $ALIAS", 5));
   }
 }

Reply via email to