Skip to content

Commit 233162e

Browse files
committed
code review and manual testing
1 parent b382a4c commit 233162e

File tree

2 files changed

+19
-45
lines changed

2 files changed

+19
-45
lines changed

solr/core/src/java/org/apache/solr/handler/designer/DefaultSampleDocumentsLoader.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,14 @@ protected List<SolrInputDocument> loadCsvDocs(
152152
.loadDocs(stream);
153153
}
154154

155-
@SuppressWarnings("unchecked")
156155
protected List<SolrInputDocument> loadJsonLines(
157156
ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad) throws IOException {
158157
List<Map<String, Object>> docs = new ArrayList<>();
159158
try (Reader r = stream.getReader()) {
160159
BufferedReader br = new BufferedReader(r);
161160
String line;
162161
while ((line = br.readLine()) != null) {
163-
line = line.trim();
164-
if (line.startsWith("{") && line.endsWith("}")) {
165-
Object jsonLine = ObjectBuilder.getVal(new JSONParser(line));
166-
if (jsonLine instanceof Map) {
167-
docs.add((Map<String, Object>) jsonLine);
168-
}
169-
}
162+
parseStringToJson(docs, line);
170163
if (maxDocsToLoad > 0 && docs.size() == maxDocsToLoad) {
171164
break;
172165
}
@@ -176,6 +169,19 @@ protected List<SolrInputDocument> loadJsonLines(
176169
return docs.stream().map(JsonLoader::buildDoc).collect(Collectors.toList());
177170
}
178171

172+
private void parseStringToJson(List<Map<String, Object>> docs, String line) throws IOException {
173+
line = line.trim();
174+
if (line.startsWith("{") && line.endsWith("}")) {
175+
Object jsonLine = ObjectBuilder.getVal(new JSONParser(line));
176+
if (jsonLine instanceof Map<?, ?> rawMap) {
177+
// JSON object keys are always Strings; the cast is safe
178+
@SuppressWarnings("unchecked")
179+
Map<String, Object> typedMap = (Map<String, Object>) rawMap;
180+
docs.add(typedMap);
181+
}
182+
}
183+
}
184+
179185
@SuppressWarnings("unchecked")
180186
protected List<SolrInputDocument> loadJsonDocs(
181187
ContentStreamBase.ByteArrayStream stream, final int maxDocsToLoad) throws IOException {
@@ -293,17 +299,10 @@ protected List<SolrInputDocument> parseXmlDocs(XMLStreamReader parser, final int
293299
}
294300
}
295301

296-
@SuppressWarnings("unchecked")
297302
protected List<Map<String, Object>> loadJsonLines(String[] lines) throws IOException {
298303
List<Map<String, Object>> docs = new ArrayList<>(lines.length);
299304
for (String line : lines) {
300-
line = line.trim();
301-
if (line.startsWith("{") && line.endsWith("}")) {
302-
Object jsonLine = ObjectBuilder.getVal(new JSONParser(line));
303-
if (jsonLine instanceof Map) {
304-
docs.add((Map<String, Object>) jsonLine);
305-
}
306-
}
305+
parseStringToJson(docs, line);
307306
}
308307
return docs;
309308
}

solr/core/src/java/org/apache/solr/handler/designer/SchemaDesignerConfigSetHelper.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import java.util.List;
4848
import java.util.Map;
4949
import java.util.Objects;
50-
import java.util.Optional;
5150
import java.util.Set;
5251
import java.util.concurrent.TimeUnit;
5352
import java.util.concurrent.TimeoutException;
@@ -74,7 +73,6 @@
7473
import org.apache.solr.common.SolrException.ErrorCode;
7574
import org.apache.solr.common.SolrInputDocument;
7675
import org.apache.solr.common.cloud.DocCollection;
77-
import org.apache.solr.common.cloud.Replica;
7876
import org.apache.solr.common.cloud.SolrZkClient;
7977
import org.apache.solr.common.cloud.ZkMaintenanceUtils;
8078
import org.apache.solr.common.cloud.ZkStateReader;
@@ -536,29 +534,6 @@ static byte[] readAllBytes(IOSupplier<InputStream> hasStream) throws IOException
536534
}
537535
}
538536

539-
private String getBaseUrl(final String collection) {
540-
String baseUrl = null;
541-
try {
542-
Set<String> liveNodes = zkStateReader().getClusterState().getLiveNodes();
543-
DocCollection docColl = zkStateReader().getCollection(collection);
544-
if (docColl != null && !liveNodes.isEmpty()) {
545-
Optional<Replica> maybeActive =
546-
docColl.getReplicas().stream().filter(r -> r.isActive(liveNodes)).findAny();
547-
if (maybeActive.isPresent()) {
548-
baseUrl = maybeActive.get().getBaseUrl();
549-
}
550-
}
551-
} catch (Exception exc) {
552-
log.warn("Failed to lookup base URL for collection {}", collection, exc);
553-
}
554-
555-
if (baseUrl == null) {
556-
baseUrl = zkStateReader().getBaseUrlForNodeName(cc.getZkController().getNodeName());
557-
}
558-
559-
return baseUrl;
560-
}
561-
562537
protected String getManagedSchemaZkPath(final String configSet) {
563538
return getConfigSetZkPath(configSet, DEFAULT_MANAGED_SCHEMA_RESOURCE_NAME);
564539
}
@@ -819,8 +794,8 @@ protected ManagedIndexSchema removeLanguageSpecificObjectsAndFiles(
819794
final Set<String> toRemove =
820795
types.values().stream()
821796
.filter(this::isTextType)
822-
.filter(t -> !languages.contains(t.getTypeName().substring(TEXT_PREFIX_LEN)))
823797
.map(FieldType::getTypeName)
798+
.filter(typeName -> !languages.contains(typeName.substring(TEXT_PREFIX_LEN)))
824799
.filter(t -> !usedTypes.contains(t)) // not explicitly used by a field
825800
.collect(Collectors.toSet());
826801

@@ -961,9 +936,9 @@ protected ManagedIndexSchema restoreLanguageSpecificObjectsAndFiles(
961936

962937
List<SchemaField> addDynFields =
963938
Arrays.stream(copyFromSchema.getDynamicFields())
964-
.filter(df -> langFieldTypeNames.contains(df.getPrototype().getType().getTypeName()))
965-
.filter(df -> !existingDynFields.contains(df.getPrototype().getName()))
966939
.map(IndexSchema.DynamicField::getPrototype)
940+
.filter(prototype -> langFieldTypeNames.contains(prototype.getType().getTypeName()))
941+
.filter(prototype -> !existingDynFields.contains(prototype.getName()))
967942
.collect(Collectors.toList());
968943
if (!addDynFields.isEmpty()) {
969944
schema = schema.addDynamicFields(addDynFields, null, false);
@@ -1035,8 +1010,8 @@ protected ManagedIndexSchema restoreDynamicFields(
10351010
.collect(Collectors.toSet());
10361011
List<SchemaField> toAdd =
10371012
Arrays.stream(dynamicFields)
1038-
.filter(df -> !existingDFNames.contains(df.getPrototype().getName()))
10391013
.map(IndexSchema.DynamicField::getPrototype)
1014+
.filter(prototype -> !existingDFNames.contains(prototype.getName()))
10401015
.collect(Collectors.toList());
10411016

10421017
// only restore language specific dynamic fields that match our langSet

0 commit comments

Comments
 (0)