aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2023-01-19 20:50:56 +0100
committerJon Bratseth <bratseth@gmail.com>2023-01-19 20:50:56 +0100
commitfa17d66d3b4466cfa47cea78e841721782462976 (patch)
tree66ef3bfc13cf869b129f2c674747a8ec8346d010
parentb4de61b832dbb50ad8d7a1100e384869538bcd83 (diff)
Cleanup - no functional chnges
-rw-r--r--docprocs/src/main/java/com/yahoo/docprocs/indexing/IndexingProcessor.java50
-rw-r--r--docprocs/src/main/java/com/yahoo/docprocs/indexing/ScriptManager.java7
-rw-r--r--docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java3
-rw-r--r--docprocs/src/test/java/com/yahoo/docprocs/indexing/ScriptManagerTestCase.java6
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java3
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java2
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldValueConverter.java12
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ScriptParser.java32
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java22
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/linguistics/AnnotatorConfig.java3
-rw-r--r--indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/parser/IndexingInput.java1
11 files changed, 60 insertions, 81 deletions
diff --git a/docprocs/src/main/java/com/yahoo/docprocs/indexing/IndexingProcessor.java b/docprocs/src/main/java/com/yahoo/docprocs/indexing/IndexingProcessor.java
index a55159cdaa0..657c8a161f7 100644
--- a/docprocs/src/main/java/com/yahoo/docprocs/indexing/IndexingProcessor.java
+++ b/docprocs/src/main/java/com/yahoo/docprocs/indexing/IndexingProcessor.java
@@ -95,56 +95,56 @@ public class IndexingProcessor extends DocumentProcessor {
return docTypeMgr;
}
- private void processDocument(DocumentPut prev, List<DocumentOperation> out) {
- DocumentType hadType = prev.getDocument().getDataType();
+ private void processDocument(DocumentPut input, List<DocumentOperation> out) {
+ DocumentType hadType = input.getDocument().getDataType();
DocumentScript script = scriptMgr.getScript(hadType);
if (script == null) {
- log.log(Level.FINE, "No indexing script for document '%s'.", prev.getId());
- out.add(prev);
+ log.log(Level.FINE, "No indexing script for document '%s'.", input.getId());
+ out.add(input);
return;
}
- log.log(Level.FINE, "Processing document '%s'.", prev.getId());
+ log.log(Level.FINE, "Processing document '%s'.", input.getId());
DocumentType wantType = docTypeMgr.getDocumentType(hadType.getName());
- Document prevDoc = prev.getDocument();
+ Document inputDocument = input.getDocument();
if (hadType != wantType) {
// this happens when you have a concrete document; we need to
// convert back to a "normal" Document for indexing of complex structures
// to work properly.
GrowableByteBuffer buffer = new GrowableByteBuffer(64 * 1024, 2.0f);
DocumentSerializer serializer = DocumentSerializerFactory.createHead(buffer);
- serializer.write(prevDoc);
+ serializer.write(inputDocument);
buffer.flip();
- prevDoc = docTypeMgr.createDocument(buffer);
+ inputDocument = docTypeMgr.createDocument(buffer);
}
- Document next = script.execute(adapterFactory, prevDoc);
- if (next == null) {
- log.log(Level.FINE, "Document '%s' produced no output.", prev.getId());
+ Document output = script.execute(adapterFactory, inputDocument);
+ if (output == null) {
+ log.log(Level.FINE, "Document '%s' produced no output.", input.getId());
return;
}
- out.add(new DocumentPut(prev, next));
+ out.add(new DocumentPut(input, output));
}
- private void processUpdate(DocumentUpdate prev, List<DocumentOperation> out) {
- DocumentScript script = scriptMgr.getScript(prev.getType());
+ private void processUpdate(DocumentUpdate input, List<DocumentOperation> out) {
+ DocumentScript script = scriptMgr.getScript(input.getType());
if (script == null) {
- log.log(Level.FINE, "No indexing script for update '%s'.", prev.getId());
- out.add(prev);
+ log.log(Level.FINE, "No indexing script for update '%s'.", input.getId());
+ out.add(input);
return;
}
- log.log(Level.FINE, "Processing update '%s'.", prev.getId());
- DocumentUpdate next = script.execute(adapterFactory, prev);
- if (next == null) {
- log.log(Level.FINE, "Update '%s' produced no output.", prev.getId());
+ log.log(Level.FINE, "Processing update '%s'.", input.getId());
+ DocumentUpdate output = script.execute(adapterFactory, input);
+ if (output == null) {
+ log.log(Level.FINE, "Update '%s' produced no output.", input.getId());
return;
}
- next.setCondition(prev.getCondition());
- out.add(next);
+ output.setCondition(input.getCondition());
+ out.add(output);
}
- private void processRemove(DocumentRemove prev, List<DocumentOperation> out) {
- log.log(Level.FINE, "Not processing remove '%s'.", prev.getId());
- out.add(prev);
+ private void processRemove(DocumentRemove input, List<DocumentOperation> out) {
+ log.log(Level.FINE, "Not processing remove '%s'.", input.getId());
+ out.add(input);
}
private Map<String, Embedder> toMap(ComponentRegistry<Embedder> embedders) {
diff --git a/docprocs/src/main/java/com/yahoo/docprocs/indexing/ScriptManager.java b/docprocs/src/main/java/com/yahoo/docprocs/indexing/ScriptManager.java
index de3a429e357..acc5a2066c9 100644
--- a/docprocs/src/main/java/com/yahoo/docprocs/indexing/ScriptManager.java
+++ b/docprocs/src/main/java/com/yahoo/docprocs/indexing/ScriptManager.java
@@ -72,6 +72,10 @@ public class ScriptManager {
return null;
}
+ /**
+ * Returns an unmodifiable map from document type name to a map of the scripts which must be run given an update
+ * to each possible field in that type.
+ */
private static Map<String, Map<String, DocumentScript>> createScriptsMap(DocumentTypeManager docTypeMgr,
IlscriptsConfig config,
Linguistics linguistics,
@@ -106,11 +110,8 @@ public class ScriptManager {
List<StatementExpression> appendedList = new ArrayList<>(((ScriptExpression)prev.getExpression()).asList());
appendedList.add(statement);
script = new ScriptExpression(appendedList);
- log.log(Level.FINE, "Appending script for field '" + fieldName + "' = " + statement);
- log.log(Level.FINE, "Full script for field '" + fieldName + "' = " + appendedList);
} else {
script = new ScriptExpression(statement);
- log.log(Level.FINE, "Setting script for field '" + fieldName + "' = " + statement);
}
DocumentScript documentScript = new DocumentScript(ilscript.doctype(), inputFieldNameExtractor.getInputFieldNames(), script);
fieldScripts.put(fieldName, documentScript);
diff --git a/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java b/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java
index c6ba63b7924..1f7cd008fb0 100644
--- a/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java
+++ b/docprocs/src/test/java/com/yahoo/docprocs/indexing/IndexingProcessorTestCase.java
@@ -32,7 +32,8 @@ import static org.junit.Assert.assertTrue;
public class IndexingProcessorTestCase {
private static final String CONFIG_ID = "dir:src/test/cfg";
- private IndexingProcessor indexer = newProcessor(CONFIG_ID);
+
+ private final IndexingProcessor indexer = newProcessor(CONFIG_ID);
@Test
public void requireThatIndexerProcessesDocuments() {
diff --git a/docprocs/src/test/java/com/yahoo/docprocs/indexing/ScriptManagerTestCase.java b/docprocs/src/test/java/com/yahoo/docprocs/indexing/ScriptManagerTestCase.java
index 4a7e643fb0a..578c3517922 100644
--- a/docprocs/src/test/java/com/yahoo/docprocs/indexing/ScriptManagerTestCase.java
+++ b/docprocs/src/test/java/com/yahoo/docprocs/indexing/ScriptManagerTestCase.java
@@ -5,11 +5,9 @@ import com.yahoo.document.DocumentType;
import com.yahoo.document.DocumentTypeManager;
import com.yahoo.language.process.Embedder;
import com.yahoo.vespa.configdefinition.IlscriptsConfig;
-import com.yahoo.vespa.indexinglanguage.parser.ParseException;
import org.junit.Test;
import java.util.Iterator;
-import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -20,7 +18,7 @@ import static org.junit.Assert.assertNull;
public class ScriptManagerTestCase {
@Test
- public void requireThatScriptsAreAppliedToSubType() throws ParseException {
+ public void requireThatScriptsAreAppliedToSubType() {
var typeMgr = DocumentTypeManager.fromFile("src/test/cfg/documentmanager_inherit.cfg");
DocumentType docType = typeMgr.getDocumentType("newssummary");
assertNotNull(docType);
@@ -35,7 +33,7 @@ public class ScriptManagerTestCase {
}
@Test
- public void requireThatScriptsAreAppliedToSuperType() throws ParseException {
+ public void requireThatScriptsAreAppliedToSuperType() {
var typeMgr = DocumentTypeManager.fromFile("src/test/cfg/documentmanager_inherit.cfg");
DocumentType docType = typeMgr.getDocumentType("newsarticle");
assertNotNull(docType);
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java
index 8050efd51f9..9500bd6a185 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldPathUpdateHelper.java
@@ -29,8 +29,7 @@ public abstract class FieldPathUpdateHelper {
public static void applyUpdate(FieldPathUpdate update, Document doc) {
if (update instanceof AddFieldPathUpdate) {
update.applyTo(doc);
- } else if (update instanceof AssignFieldPathUpdate) {
- AssignFieldPathUpdate assign = (AssignFieldPathUpdate)update;
+ } else if (update instanceof AssignFieldPathUpdate assign) {
boolean createMissingPath = assign.getCreateMissingPath();
boolean removeIfZero = assign.getRemoveIfZero();
assign.setCreateMissingPath(true);
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java
index 4182c133000..2601c5d0f71 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldUpdateAdapter.java
@@ -192,7 +192,6 @@ public class FieldUpdateAdapter implements UpdateAdapter {
return ret;
}
- @SuppressWarnings({ "unchecked" })
private List<ValueUpdate> createRemoveValueUpdateForEachElement(Iterator<FieldValue> it) {
List<ValueUpdate> ret = new ArrayList<>();
while (it.hasNext()) {
@@ -215,7 +214,6 @@ public class FieldUpdateAdapter implements UpdateAdapter {
return ret;
}
- @SuppressWarnings({ "unchecked" })
private List<ValueUpdate> createMapValueUpdatesForStruct(StructuredFieldValue struct, MapValueUpdate upd) {
List<ValueUpdate> ret = new ArrayList<>();
for (Iterator<Map.Entry<Field, FieldValue>> it = struct.iterator(); it.hasNext();) {
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldValueConverter.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldValueConverter.java
index 4900574f549..4f96f2b7a31 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldValueConverter.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/FieldValueConverter.java
@@ -57,9 +57,7 @@ public abstract class FieldValueConverter {
return null;
}
Array ret = DataType.getArray(nextType).createFieldValue();
- for (FieldValue nextVal : next) {
- ret.add(nextVal);
- }
+ ret.addAll(next);
return ret;
}
@@ -96,9 +94,7 @@ public abstract class FieldValueConverter {
return null;
}
MapFieldValue ret = DataType.getMap(nextKeyType, nextValType).createFieldValue();
- for (Map.Entry<FieldValue, FieldValue> entry : next.entrySet()) {
- ret.put(entry.getKey(), entry.getValue());
- }
+ ret.putAll(next);
return ret;
}
@@ -128,9 +124,7 @@ public abstract class FieldValueConverter {
WeightedSet ret = DataType.getWeightedSet(nextType, val.getDataType().createIfNonExistent(),
val.getDataType().removeIfZero()).createFieldValue();
- for (Map.Entry<FieldValue, Integer> entry : next.entrySet()) {
- ret.put(entry.getKey(), entry.getValue());
- }
+ ret.putAll(next);
return ret;
}
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ScriptParser.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ScriptParser.java
index 2b4e0db699b..ec9329c3c29 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ScriptParser.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/ScriptParser.java
@@ -16,36 +16,20 @@ import com.yahoo.vespa.indexinglanguage.parser.TokenMgrException;
public final class ScriptParser {
public static Expression parseExpression(ScriptParserContext config) throws ParseException {
- return parse(config, new ParserMethod<Expression>() {
-
- @Override
- public Expression call(IndexingParser parser) throws ParseException {
- return parser.root();
- }
- });
+ return parse(config, parser -> parser.root());
}
public static ScriptExpression parseScript(ScriptParserContext config) throws ParseException {
- return parse(config, new ParserMethod<ScriptExpression>() {
-
- @Override
- public ScriptExpression call(IndexingParser parser) throws ParseException {
- return parser.script();
- }
- });
+ return parse(config, parser -> parser.script());
}
public static StatementExpression parseStatement(ScriptParserContext config) throws ParseException {
- return parse(config, new ParserMethod<StatementExpression>() {
-
- @Override
- public StatementExpression call(IndexingParser parser) throws ParseException {
- try {
- return parser.statement();
- }
- catch (TokenMgrException e) {
- throw new ParseException(e.getMessage());
- }
+ return parse(config, parser -> {
+ try {
+ return parser.statement();
+ }
+ catch (TokenMgrException e) {
+ throw new ParseException(e.getMessage());
}
});
}
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java
index f45fe7f97c3..3b7d09d0ea8 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/SimpleAdapterFactory.java
@@ -60,21 +60,25 @@ public class SimpleAdapterFactory implements AdapterFactory {
ret.add(new IdentityFieldPathUpdateAdapter(fieldUpd, newDocumentAdapter(complete, true)));
}
} catch (NullPointerException e) {
- throw new IllegalArgumentException("Exception during handling of update '" + fieldUpd + "' to field '" + fieldUpd.getFieldPath() + "'", e);
+ throw new IllegalArgumentException("Exception during handling of update '" + fieldUpd +
+ "' to field '" + fieldUpd.getFieldPath() + "'", e);
}
}
- for (FieldUpdate fieldUpd : upd.fieldUpdates()) {
- Field field = fieldUpd.getField();
- for (ValueUpdate valueUpd : fieldUpd.getValueUpdates()) {
+ for (FieldUpdate fieldUpdate : upd.fieldUpdates()) {
+ Field field = fieldUpdate.getField();
+ for (ValueUpdate valueUpdate : fieldUpdate.getValueUpdates()) {
try {
- if (FieldUpdateHelper.isComplete(field, valueUpd)) {
- FieldUpdateHelper.applyUpdate(field, valueUpd, complete);
+ if (FieldUpdateHelper.isComplete(field, valueUpdate)) {
+ FieldUpdateHelper.applyUpdate(field, valueUpdate, complete);
} else {
- Document partial = FieldUpdateHelper.newPartialDocument(docType, docId, field, valueUpd);
- ret.add(FieldUpdateAdapter.fromPartialUpdate(expressionSelector.selectExpression(docType, field.getName()), newDocumentAdapter(partial, true), valueUpd));
+ Document partial = FieldUpdateHelper.newPartialDocument(docType, docId, field, valueUpdate);
+ ret.add(FieldUpdateAdapter.fromPartialUpdate(expressionSelector.selectExpression(docType, field.getName()),
+ newDocumentAdapter(partial, true),
+ valueUpdate));
}
} catch (NullPointerException e) {
- throw new IllegalArgumentException("Exception during handling of update '" + valueUpd + "' to field '" + field + "'", e);
+ throw new IllegalArgumentException("Exception during handling of update '" + valueUpdate +
+ "' to field '" + field + "'", e);
}
}
}
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/linguistics/AnnotatorConfig.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/linguistics/AnnotatorConfig.java
index 441ac711cc3..e42ac6479f8 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/linguistics/AnnotatorConfig.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/linguistics/AnnotatorConfig.java
@@ -97,10 +97,9 @@ public class AnnotatorConfig implements Cloneable {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof AnnotatorConfig)) {
+ if (!(obj instanceof AnnotatorConfig rhs)) {
return false;
}
- AnnotatorConfig rhs = (AnnotatorConfig)obj;
if (!language.equals(rhs.language)) {
return false;
}
diff --git a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/parser/IndexingInput.java b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/parser/IndexingInput.java
index 3646a9f2681..78c6a4bbf03 100644
--- a/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/parser/IndexingInput.java
+++ b/indexinglanguage/src/main/java/com/yahoo/vespa/indexinglanguage/parser/IndexingInput.java
@@ -11,4 +11,5 @@ public final class IndexingInput extends FastCharStream implements CharStream {
public IndexingInput(String input) {
super(input);
}
+
}