Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoreValuesSourceType no longer implements Writable #51276

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.time.DateFormatter;
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.IndexGeoPointFieldData;
Expand All @@ -37,7 +34,6 @@
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;

import java.io.IOException;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Locale;
Expand All @@ -46,7 +42,7 @@
/**
* {@link CoreValuesSourceType} holds the {@link ValuesSourceType} implementations for the core aggregations package.
*/
public enum CoreValuesSourceType implements Writeable, ValuesSourceType {
public enum CoreValuesSourceType implements ValuesSourceType {
ANY(EquivalenceType.STRING) {
// ANY still has a lot of special handling in ValuesSourceConfig, and as such doesn't adhere to this interface yet
@Override
Expand Down Expand Up @@ -342,16 +338,6 @@ public static ValuesSourceType fromString(String name) {
return valueOf(name.trim().toUpperCase(Locale.ROOT));
}

public static ValuesSourceType fromStream(StreamInput in) throws IOException {
return in.readEnum(CoreValuesSourceType.class);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
CoreValuesSourceType state = this;
out.writeEnum(state);
}

public String value() {
return name().toLowerCase(Locale.ROOT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,12 @@

package org.elasticsearch.search.aggregations.support;

import org.elasticsearch.common.io.stream.AbstractWriteableEnumTestCase;

import java.io.IOException;
import org.elasticsearch.test.ESTestCase;

import static org.hamcrest.Matchers.equalTo;

public class CoreValuesSourceTypeTests extends AbstractWriteableEnumTestCase {

public CoreValuesSourceTypeTests() {
super(CoreValuesSourceType::fromStream);
}

@Override
public void testValidOrdinals() {
assertThat(CoreValuesSourceType.ANY.ordinal(), equalTo(0));
assertThat(CoreValuesSourceType.NUMERIC.ordinal(), equalTo(1));
assertThat(CoreValuesSourceType.BYTES.ordinal(), equalTo(2));
assertThat(CoreValuesSourceType.GEOPOINT.ordinal(), equalTo(3));
assertThat(CoreValuesSourceType.RANGE.ordinal(), equalTo(4));
assertThat(CoreValuesSourceType.HISTOGRAM.ordinal(), equalTo(5));
}
public class CoreValuesSourceTypeTests extends ESTestCase {

@Override
public void testFromString() {
assertThat(CoreValuesSourceType.fromString("any"), equalTo(CoreValuesSourceType.ANY));
assertThat(CoreValuesSourceType.fromString("numeric"), equalTo(CoreValuesSourceType.NUMERIC));
Expand All @@ -55,24 +38,4 @@ public void testFromString() {
equalTo("No enum constant org.elasticsearch.search.aggregations.support.CoreValuesSourceType.DOES_NOT_EXIST"));
expectThrows(NullPointerException.class, () -> CoreValuesSourceType.fromString(null));
}

@Override
public void testReadFrom() throws IOException {
assertReadFromStream(0, CoreValuesSourceType.ANY);
assertReadFromStream(1, CoreValuesSourceType.NUMERIC);
assertReadFromStream(2, CoreValuesSourceType.BYTES);
assertReadFromStream(3, CoreValuesSourceType.GEOPOINT);
assertReadFromStream(4, CoreValuesSourceType.RANGE);
assertReadFromStream(5, CoreValuesSourceType.HISTOGRAM);
}

@Override
public void testWriteTo() throws IOException {
assertWriteToStream(CoreValuesSourceType.ANY, 0);
assertWriteToStream(CoreValuesSourceType.NUMERIC, 1);
assertWriteToStream(CoreValuesSourceType.BYTES, 2);
assertWriteToStream(CoreValuesSourceType.GEOPOINT, 3);
assertWriteToStream(CoreValuesSourceType.RANGE, 4);
assertWriteToStream(CoreValuesSourceType.HISTOGRAM, 5);
}
}