Skip to content

Commit

Permalink
Update dimension field mapper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny committed Sep 9, 2024
1 parent 65ad357 commit 86b49df
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,11 @@ public void testDimensionMultiValuedFieldTSDB() throws IOException {
b.field("time_series_dimension", true);
}), IndexMode.TIME_SERIES);

Exception e = expectThrows(DocumentParsingException.class, () -> mapper.parse(source(b -> b.array("field", true, false))));
assertThat(e.getCause().getMessage(), containsString("Dimension field [field] cannot be a multi-valued field"));
ParsedDocument doc = mapper.parse(source(null, b -> {
b.array("field", true, false);
b.field("@timestamp", Instant.now());
}, TimeSeriesRoutingHashFieldMapper.encode(randomInt())));
assertThat(doc.docs().get(0).getFields("field"), hasSize(greaterThan(1)));
}

public void testDimensionMultiValuedFieldNonTSDB() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ public void testDimensionMultiValuedFieldTSDB() throws IOException {
b.field("time_series_dimension", true);
}), IndexMode.TIME_SERIES);

Exception e = expectThrows(
DocumentParsingException.class,
() -> mapper.parse(source(b -> b.array("field", "192.168.1.1", "192.168.1.1")))
);
assertThat(e.getCause().getMessage(), containsString("Dimension field [field] cannot be a multi-valued field"));
ParsedDocument doc = mapper.parse(source(null, b -> {
b.array("field", "192.168.1.1", "192.168.1.1");
b.field("@timestamp", Instant.now());
}, TimeSeriesRoutingHashFieldMapper.encode(randomInt())));
assertThat(doc.docs().get(0).getFields("field"), hasSize(greaterThan(1)));
}

public void testDimensionMultiValuedFieldNonTSDB() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,11 @@ public void testDimensionMultiValuedFieldTSDB() throws IOException {
b.field("time_series_dimension", true);
}), IndexMode.TIME_SERIES);

Exception e = expectThrows(DocumentParsingException.class, () -> mapper.parse(source(b -> b.array("field", "1234", "45678"))));
assertThat(e.getCause().getMessage(), containsString("Dimension field [field] cannot be a multi-valued field"));
ParsedDocument doc = mapper.parse(source(null, b -> {
b.array("field", "1234", "45678");
b.field("@timestamp", Instant.now());
}, TimeSeriesRoutingHashFieldMapper.encode(randomInt())));
assertThat(doc.docs().get(0).getFields("field"), hasSize(greaterThan(1)));
}

public void testDimensionMultiValuedFieldNonTSDB() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.index.mapper.MapperTestCase;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.mapper.TimeSeriesRoutingHashFieldMapper;
import org.elasticsearch.index.mapper.flattened.FlattenedFieldMapper.KeyedFlattenedFieldType;
import org.elasticsearch.index.mapper.flattened.FlattenedFieldMapper.RootFlattenedFieldType;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -199,11 +200,11 @@ public void testDimensionMultiValuedFieldTSDB() throws IOException {
b.field("time_series_dimensions", List.of("key1", "key2", "field3.key3"));
}), IndexMode.TIME_SERIES);

Exception e = expectThrows(
DocumentParsingException.class,
() -> mapper.parse(source(b -> b.array("field.key1", "value1", "value2")))
);
assertThat(e.getCause().getMessage(), containsString("Dimension field [field.key1] cannot be a multi-valued field"));
ParsedDocument doc = mapper.parse(source(null, b -> {
b.array("field.key1", "value1", "value2");
b.field("@timestamp", Instant.now());
}, TimeSeriesRoutingHashFieldMapper.encode(randomInt())));
assertThat(doc.docs().get(0).getFields("field"), hasSize(greaterThan(1)));
}

public void testDimensionMultiValuedFieldNonTSDB() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ public void testDimensionMultiValuedFieldTSDB() throws IOException {
b.field("time_series_dimension", true);
}), IndexMode.TIME_SERIES);

Exception e = expectThrows(
DocumentParsingException.class,
() -> mapper.parse(source(b -> b.array("field", randomNumber(), randomNumber(), randomNumber())))
);
assertThat(e.getCause().getMessage(), containsString("Dimension field [field] cannot be a multi-valued field"));
ParsedDocument doc = mapper.parse(source(null, b -> {
b.array("field", randomNumber(), randomNumber(), randomNumber());
b.field("@timestamp", Instant.now());
}, TimeSeriesRoutingHashFieldMapper.encode(randomInt())));
assertThat(doc.docs().get(0).getFields("field"), hasSize(greaterThan(1)));
}

public void testDimensionMultiValuedFieldNonTSDB() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.elasticsearch.index.mapper.NumberTypeOutOfRangeSpec;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.index.mapper.TimeSeriesParams;
import org.elasticsearch.index.mapper.TimeSeriesRoutingHashFieldMapper;
import org.elasticsearch.index.mapper.WholeNumberFieldMapperTests;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -269,11 +270,11 @@ public void testDimensionMultiValuedFieldTSDB() throws IOException {
b.field("time_series_dimension", true);
}), IndexMode.TIME_SERIES);

Exception e = expectThrows(
DocumentParsingException.class,
() -> mapper.parse(source(b -> b.array("field", randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong())))
);
assertThat(e.getCause().getMessage(), containsString("Dimension field [field] cannot be a multi-valued field"));
ParsedDocument doc = mapper.parse(source(null, b -> {
b.array("field", randomNonNegativeLong(), randomNonNegativeLong(), randomNonNegativeLong());
b.field("@timestamp", Instant.now());
}, TimeSeriesRoutingHashFieldMapper.encode(randomInt())));
assertThat(doc.docs().get(0).getFields("field"), hasSize(greaterThan(1)));
}

public void testDimensionMultiValuedFieldNonTSDB() throws IOException {
Expand Down

0 comments on commit 86b49df

Please sign in to comment.