You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by th...@apache.org on 2021/08/02 19:07:35 UTC
[lucene-solr] branch branch_8x updated: SOLR-15570: Check stored or
docValues when merging fields from the Luke schema response (#2544)
This is an automated email from the ASF dual-hosted git repository.
thelabdude pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 817e380 SOLR-15570: Check stored or docValues when merging fields from the Luke schema response (#2544)
817e380 is described below
commit 817e380bb428cbd45dda9587f8e029058c09a5a5
Author: Timothy Potter <th...@gmail.com>
AuthorDate: Mon Aug 2 13:07:15 2021 -0600
SOLR-15570: Check stored or docValues when merging fields from the Luke schema response (#2544)
---
.../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 136ebce..88baa40 100644
--- a/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
+++ b/solr/core/src/test/org/apache/solr/handler/TestSQLHandler.java
@@ -2285,16 +2285,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));
}
}