Skip to content

Commit

Permalink
fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi committed Mar 27, 2024
1 parent 11112c4 commit 8fe9ed4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static org.elasticsearch.cluster.metadata.AliasMetadata.newAliasMetadataBuilder;
import static org.elasticsearch.cluster.metadata.IndexMetadataTests.randomFieldInferenceMetadata;
import static org.elasticsearch.cluster.metadata.IndexMetadataTests.randomInferenceFields;
import static org.elasticsearch.cluster.routing.RandomShardRoutingMutator.randomChange;
import static org.elasticsearch.cluster.routing.TestShardRouting.shardRoutingBuilder;
import static org.elasticsearch.cluster.routing.UnassignedInfoTests.randomUnassignedInfo;
Expand Down Expand Up @@ -587,7 +587,7 @@ public IndexMetadata randomChange(IndexMetadata part) {
builder.settings(Settings.builder().put(part.getSettings()).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0));
break;
case 3:
builder.fieldInferenceMetadata(randomFieldInferenceMetadata(true));
builder.putInferenceFields(randomInferenceFields());
break;
default:
throw new IllegalArgumentException("Shouldn't be here");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,10 @@ public static IndexMetadata readFrom(StreamInput in, @Nullable Function<String,
builder.putMapping(new MappingMetadata(in));
}
}
if (in.getTransportVersion().onOrAfter(TransportVersions.SEMANTIC_TEXT_FIELD_ADDED)) {
var fields = in.readCollectionAsImmutableList(InferenceFieldMetadata::new);
fields.stream().forEach(f -> builder.putInferenceField(f));
}
int inferenceFieldsSize = in.readVInt();
for (int i = 0; i < inferenceFieldsSize; i++) {
InferenceFieldMetadata fieldMd = new InferenceFieldMetadata(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testIndexMetadataSerialization() throws IOException {
IndexMetadataStats indexStats = randomBoolean() ? randomIndexStats(numShard) : null;
Double indexWriteLoadForecast = randomBoolean() ? randomDoubleBetween(0.0, 128, true) : null;
Long shardSizeInBytesForecast = randomBoolean() ? randomLongBetween(1024, 10240) : null;
Map<String, InferenceFieldMetadata> dynamicFields = randomDynamicFields();
Map<String, InferenceFieldMetadata> dynamicFields = randomInferenceFields();

IndexMetadata metadata = IndexMetadata.builder("foo")
.settings(indexSettings(numShard, numberOfReplicas).put("index.version.created", 1))
Expand Down Expand Up @@ -557,7 +557,7 @@ public void testDynamicFieldMetadata() {
IndexMetadata idxMeta1 = IndexMetadata.builder("test").settings(settings).build();
assertSame(idxMeta1.getInferenceFields(), Map.of());

Map<String, InferenceFieldMetadata> dynamicFields = randomDynamicFields();
Map<String, InferenceFieldMetadata> dynamicFields = randomInferenceFields();
IndexMetadata idxMeta2 = IndexMetadata.builder(idxMeta1).putInferenceFields(dynamicFields).build();
assertThat(idxMeta2.getInferenceFields(), equalTo(dynamicFields));
}
Expand All @@ -566,17 +566,17 @@ private static Settings indexSettingsWithDataTier(String dataTier) {
return indexSettings(IndexVersion.current(), 1, 0).put(DataTier.TIER_PREFERENCE, dataTier).build();
}

public static Map<String, InferenceFieldMetadata> randomDynamicFields() {
public static Map<String, InferenceFieldMetadata> randomInferenceFields() {
Map<String, InferenceFieldMetadata> map = new HashMap<>();
int numFields = randomIntBetween(0, 5);
for (int i = 0; i < numFields; i++) {
String field = randomAlphaOfLengthBetween(5, 10);
map.put(field, randomDynamicFieldMetadata(field));
map.put(field, randomInferenceFieldMetadata(field));
}
return map;
}

private static InferenceFieldMetadata randomDynamicFieldMetadata(String name) {
private static InferenceFieldMetadata randomInferenceFieldMetadata(String name) {
return new InferenceFieldMetadata(name, randomIdentifier(), randomSet(1, 5, ESTestCase::randomIdentifier).toArray(String[]::new));
}

Expand Down

0 comments on commit 8fe9ed4

Please sign in to comment.