Skip to content

Commit

Permalink
Make StreamOutput.writeMap generic (#84593)
Browse files Browse the repository at this point in the history
The writeMap method currently is meant for a string to object map, and all
it does it delegate to writeGenericObject. This change converts existing
uses of writeMap to use writeGenericObject directly, and adds a new
generic version of writeMap to parallel the writeMap which takes key and
value writers.
  • Loading branch information
rjernst authored Mar 4, 2022
1 parent 8e8e53a commit ed5fc8b
Show file tree
Hide file tree
Showing 76 changed files with 104 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected final void doWriteTo(StreamOutput out) throws IOException {
out.writeGenericValue(fields);
out.writeOptionalWriteable(userValueTypeHint);
out.writeOptionalString(format);
out.writeMap(missingMap);
out.writeGenericMap(missingMap);
innerWriteTo(out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public void writeTo(StreamOutput out) throws IOException {
boolean hasParams = scriptParams != null;
out.writeBoolean(hasParams);
if (hasParams) {
out.writeMap(scriptParams);
out.writeGenericMap(scriptParams);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public void writeTo(StreamOutput out) throws IOException {
for (RatedDocument ratedDoc : ratedDocs) {
ratedDoc.writeTo(out);
}
out.writeMap(params);
out.writeGenericMap(params);
out.writeInt(summaryFields.size());
for (String fieldName : summaryFields) {
out.writeString(fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(includeGlobalState);
out.writeBoolean(waitForCompletion);
out.writeBoolean(partial);
out.writeMap(userMetadata);
out.writeGenericMap(userMetadata);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void writeTo(StreamOutput out) throws IOException {
OriginalIndices.writeOriginalIndices(originalIndices, out);
out.writeOptionalNamedWriteable(indexFilter);
out.writeLong(nowInMillis);
out.writeMap(runtimeFields);
out.writeGenericMap(runtimeFields);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(includeUnmapped);
out.writeOptionalNamedWriteable(indexFilter);
out.writeOptionalLong(nowInMillis);
out.writeMap(runtimeFields);
out.writeGenericMap(runtimeFields);
if (out.getVersion().onOrAfter(Version.V_8_2_0)) {
out.writeStringArray(filters);
out.writeStringArray(allowedTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ final class WriteableIngestDocument implements Writeable, ToXContentFragment {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeMap(ingestDocument.getSourceAndMetadata());
out.writeMap(ingestDocument.getIngestMetadata());
out.writeGenericMap(ingestDocument.getSourceAndMetadata());
out.writeGenericMap(ingestDocument.getIngestMetadata());
}

IngestDocument getIngestDocument() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeImmutableMap(shards);
out.writeLong(repositoryStateId);
out.writeOptionalString(failure);
out.writeMap(userMetadata);
out.writeGenericMap(userMetadata);
Version.writeVersion(version, out);
out.writeStringCollection(dataStreams);
out.writeOptionalWriteable(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(false);
} else {
out.writeBoolean(true);
out.writeMap(this.metadata);
out.writeGenericMap(this.metadata);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalStringCollection(this.componentTemplates);
out.writeOptionalVLong(this.priority);
out.writeOptionalVLong(this.version);
out.writeMap(this.metadata);
out.writeGenericMap(this.metadata);
out.writeOptionalWriteable(dataStreamTemplate);
out.writeOptionalBoolean(allowAutoCreate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public void writeTo(StreamOutput out) throws IOException {
timeStampField.writeTo(out);
out.writeList(indices);
out.writeVLong(generation);
out.writeMap(metadata);
out.writeGenericMap(metadata);
out.writeBoolean(hidden);
out.writeBoolean(replicated);
out.writeBoolean(system);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public boolean containsKey(Object key) {
@Override
@SuppressWarnings("unchecked")
public void writeTo(StreamOutput out) throws IOException {
out.writeMap((Map<String, Object>) (Map) innerMap);
out.writeGenericMap((Map<String, Object>) (Map) innerMap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void writeOptionalStringArray(@Nullable String[] array) throws IOExceptio
}
}

public void writeMap(@Nullable Map<String, Object> map) throws IOException {
public void writeGenericMap(@Nullable Map<String, Object> map) throws IOException {
writeGenericValue(map);
}

Expand Down Expand Up @@ -579,6 +579,13 @@ public final <K, V> void writeMapOfLists(final Map<K, List<V>> map, final Writer
});
}

/**
* Write a {@link Map} of {@code K}-type keys to {@code V}-type.
*/
public final <K extends Writeable, V extends Writeable> void writeMap(final Map<K, V> map) throws IOException {
writeMap(map, (o, k) -> k.writeTo(o), (o, v) -> v.writeTo(o));
}

/**
* Write a {@link Map} of {@code K}-type keys to {@code V}-type.
* <pre><code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(source);
@SuppressWarnings("unchecked")
Map<String, Object> options = (Map<String, Object>) (Map) this.options;
out.writeMap(options);
out.writeGenericMap(options);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected AbstractAggregationBuilder(StreamInput in) throws IOException {
public final void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
factoriesBuilder.writeTo(out);
out.writeMap(metadata);
out.writeGenericMap(metadata);
doWriteTo(out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
out.writeVInt(size);
out.writeBoolean(after != null);
if (after != null) {
out.writeMap(after);
out.writeGenericMap(after);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {
boolean hasParams = params != null;
out.writeBoolean(hasParams);
if (hasParams) {
out.writeMap(params);
out.writeGenericMap(params);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected AbstractPipelineAggregationBuilder(StreamInput in, String type) throws
public void writeTo(StreamOutput out) throws IOException {
out.writeString(name);
out.writeStringArray(bucketsPaths);
out.writeMap(metadata);
out.writeGenericMap(metadata);
doWriteTo(out);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(pointInTimeBuilder);
}
if (out.getVersion().onOrAfter(Version.V_7_11_0)) {
out.writeMap(runtimeMappings);
out.writeGenericMap(runtimeMappings);
} else {
if (false == runtimeMappings.isEmpty()) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public final void writeTo(StreamOutput out) throws IOException {
boolean hasOptions = options != null;
out.writeBoolean(hasOptions);
if (hasOptions) {
out.writeMap(options);
out.writeGenericMap(options);
}
out.writeOptionalBoolean(requireFieldMatch);
if (out.getVersion().onOrAfter(Version.V_7_12_0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ public void writeTo(final StreamOutput out) throws IOException {
out.writeBoolean(false);
}
out.writeOptionalBoolean(includeGlobalState);
out.writeMap(userMetadata);
out.writeGenericMap(userMetadata);
out.writeStringCollection(dataStreams);
out.writeList(featureStates);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public String getWriteableName() {
public void writeTo(StreamOutput out) throws IOException {
out.writeString(currentIndex);
out.writeString(currentFeature);
out.writeMap(featureCallbackMetadata);
out.writeGenericMap(featureCallbackMetadata);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeBoolean(available);
out.writeBoolean(enabled);
if (out.getVersion().before(Version.V_8_0_0)) {
out.writeMap(Collections.emptyMap());
out.writeGenericMap(Collections.emptyMap());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeString(url);
out.writeOptionalString(details);
out.writeBoolean(resolveDuringRollingUpgrade);
out.writeMap(meta);
out.writeGenericMap(meta);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void innerXContent(XContentBuilder builder, Params params) throws IOEx
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(stats);
out.writeGenericMap(stats);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeNamedWriteable(type);
out.writeString(name);
out.writeMap(phases, StreamOutput::writeString, (o, val) -> val.writeTo(o));
out.writeMap(this.metadata);
out.writeGenericMap(this.metadata);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public Version getMinimalSupportedVersion() {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(jobsUsage);
out.writeMap(datafeedsUsage);
out.writeMap(analyticsUsage);
out.writeMap(inferenceUsage);
out.writeGenericMap(jobsUsage);
out.writeGenericMap(datafeedsUsage);
out.writeGenericMap(analyticsUsage);
out.writeGenericMap(inferenceUsage);
out.writeInt(nodeCount);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public ActionRequestValidationException validate() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(deploymentId);
out.writeCollection(docs, StreamOutput::writeMap);
out.writeCollection(docs, StreamOutput::writeGenericMap);
out.writeOptionalNamedWriteable(update);
out.writeOptionalTimeValue(inferenceTimeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ActionRequestValidationException validate() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(modelId);
out.writeCollection(objectsToInfer, StreamOutput::writeMap);
out.writeCollection(objectsToInfer, StreamOutput::writeGenericMap);
out.writeNamedWriteable(update);
out.writeBoolean(previouslyLicensed);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Map<String, Object> getInfo() {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeMap(info);
out.writeGenericMap(info);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public List<Map<String, Object>> getFeatureValues() {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeCollection(featureValues, StreamOutput::writeMap);
out.writeCollection(featureValues, StreamOutput::writeGenericMap);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static AggProvider fromStream(StreamInput in) throws IOException {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeMap(aggs);
out.writeGenericMap(aggs);
out.writeOptionalWriteable(parsedAggs);
out.writeException(parsingException);
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalWriteable(delayedDataCheckConfig);
out.writeOptionalVInt(maxEmptySearches);
indicesOptions.writeIndicesOptions(out);
out.writeMap(runtimeMappings);
out.writeGenericMap(runtimeMappings);
}

@Override
Expand Down Expand Up @@ -844,7 +844,7 @@ public void writeTo(StreamOutput out) throws IOException {
if (indicesOptions != null) {
indicesOptions.writeIndicesOptions(out);
}
out.writeMap(runtimeMappings);
out.writeGenericMap(runtimeMappings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void writeTo(StreamOutput out) throws IOException {
}
if (this.runtimeMappings != null) {
out.writeBoolean(true);
out.writeMap(this.runtimeMappings);
out.writeGenericMap(this.runtimeMappings);
} else {
out.writeBoolean(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringArray(index);
queryProvider.writeTo(out);
out.writeOptionalWriteable(sourceFiltering);
out.writeMap(runtimeMappings);
out.writeGenericMap(runtimeMappings);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeInstant(createTime);
out.writeOptionalWriteable(definition);
out.writeCollection(tags, StreamOutput::writeString);
out.writeMap(metadata);
out.writeGenericMap(metadata);
input.writeTo(out);
out.writeVLong(modelSize);
out.writeVLong(estimatedOperations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalLong(modelSnapshotRetentionDays);
out.writeOptionalLong(dailyModelSnapshotRetentionAfterDays);
out.writeOptionalLong(resultsRetentionDays);
out.writeMap(customSettings);
out.writeGenericMap(customSettings);
out.writeOptionalString(modelSnapshotId);
if (modelSnapshotMinVersion != null) {
out.writeBoolean(true);
Expand Down Expand Up @@ -1070,7 +1070,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalLong(modelSnapshotRetentionDays);
out.writeOptionalLong(dailyModelSnapshotRetentionAfterDays);
out.writeOptionalLong(resultsRetentionDays);
out.writeMap(customSettings);
out.writeGenericMap(customSettings);
out.writeOptionalString(modelSnapshotId);
if (modelSnapshotMinVersion != null) {
out.writeBoolean(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeStringCollection(categorizationFilters);
}
out.writeOptionalWriteable(perPartitionCategorizationConfig);
out.writeMap(customSettings);
out.writeGenericMap(customSettings);
out.writeOptionalString(modelSnapshotId);
if (jobVersion != null) {
out.writeBoolean(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public QueryProvider(QueryProvider other) {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeMap(query);
out.writeGenericMap(query);
out.writeOptionalNamedWriteable(parsedQuery);
out.writeException(parsingException);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Map<String, Object> getExporters() {
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeMap(exporters);
out.writeGenericMap(exporters);
out.writeOptionalBoolean(collectionEnabled);
}

Expand Down
Loading

0 comments on commit ed5fc8b

Please sign in to comment.