Skip to content

Commit

Permalink
[Transform] HLRC cleanups (elastic#78909)
Browse files Browse the repository at this point in the history
removes some "data frame" leftovers in transform code, no functional changes
  • Loading branch information
Hendrik Muhs authored Oct 11, 2021
1 parent 0a6b6d9 commit fd4dca8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ final class TransformRequestConverters {
private TransformRequestConverters() {}

static Request putTransform(PutTransformRequest putRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
.addPathPart(putRequest.getConfig().getId())
.build();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform")
.addPathPart(putRequest.getConfig().getId())
.build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
request.setEntity(createEntity(putRequest, REQUEST_BODY_CONTENT_TYPE));
if (putRequest.getDeferValidation() != null) {
Expand All @@ -50,25 +49,23 @@ static Request putTransform(PutTransformRequest putRequest) throws IOException {
return request;
}

static Request updateTransform(UpdateTransformRequest updateDataFrameTransformRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
.addPathPart(updateDataFrameTransformRequest.getId())
static Request updateTransform(UpdateTransformRequest updateTransformRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform")
.addPathPart(updateTransformRequest.getId())
.addPathPart("_update")
.build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
request.setEntity(createEntity(updateDataFrameTransformRequest, REQUEST_BODY_CONTENT_TYPE));
if (updateDataFrameTransformRequest.getDeferValidation() != null) {
request.addParameter(DEFER_VALIDATION, Boolean.toString(updateDataFrameTransformRequest.getDeferValidation()));
request.setEntity(createEntity(updateTransformRequest, REQUEST_BODY_CONTENT_TYPE));
if (updateTransformRequest.getDeferValidation() != null) {
request.addParameter(DEFER_VALIDATION, Boolean.toString(updateTransformRequest.getDeferValidation()));
}
return request;
}

static Request getTransform(GetTransformRequest getRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
.addPathPart(Strings.collectionToCommaDelimitedString(getRequest.getId()))
.build();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform")
.addPathPart(Strings.collectionToCommaDelimitedString(getRequest.getId()))
.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
if (getRequest.getPageParams() != null && getRequest.getPageParams().getFrom() != null) {
request.addParameter(PageParams.FROM.getPreferredName(), getRequest.getPageParams().getFrom().toString());
Expand All @@ -86,10 +83,7 @@ static Request getTransform(GetTransformRequest getRequest) {
}

static Request deleteTransform(DeleteTransformRequest deleteRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
.addPathPart(deleteRequest.getId())
.build();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform").addPathPart(deleteRequest.getId()).build();
Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
if (deleteRequest.getForce() != null) {
request.addParameter(FORCE, Boolean.toString(deleteRequest.getForce()));
Expand All @@ -98,11 +92,10 @@ static Request deleteTransform(DeleteTransformRequest deleteRequest) {
}

static Request startTransform(StartTransformRequest startRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
.addPathPart(startRequest.getId())
.addPathPartAsIs("_start")
.build();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform")
.addPathPart(startRequest.getId())
.addPathPartAsIs("_start")
.build();
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params();
if (startRequest.getTimeout() != null) {
Expand All @@ -113,8 +106,7 @@ static Request startTransform(StartTransformRequest startRequest) {
}

static Request stopTransform(StopTransformRequest stopRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform")
.addPathPart(stopRequest.getId())
.addPathPartAsIs("_stop")
.build();
Expand Down Expand Up @@ -151,11 +143,10 @@ static Request previewTransform(PreviewTransformRequest previewRequest) throws I
}

static Request getTransformStats(GetTransformStatsRequest statsRequest) {
String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_transform")
.addPathPart(statsRequest.getId())
.addPathPartAsIs("_stats")
.build();
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_transform")
.addPathPart(statsRequest.getId())
.addPathPartAsIs("_stats")
.build();
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
if (statsRequest.getPageParams() != null && statsRequest.getPageParams().getFrom() != null) {
request.addParameter(PageParams.FROM.getPreferredName(), statsRequest.getPageParams().getFrom().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
import org.elasticsearch.client.transform.transforms.pivot.PivotConfig;
import org.elasticsearch.client.transform.transforms.pivot.TermsGroupSource;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentType;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.XContentType;
import org.junit.After;

import java.io.IOException;
Expand Down Expand Up @@ -177,7 +177,7 @@ public void testCreateDelete() throws IOException {
createIndex(sourceIndex);

String id = "test-crud";
TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest");
TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest");

TransformClient client = highLevelClient().transform();
AcknowledgedResponse ack = execute(new PutTransformRequest(transform), client::putTransform, client::putTransformAsync);
Expand All @@ -199,7 +199,7 @@ public void testUpdate() throws IOException {
createIndex(sourceIndex);

String id = "test-update";
TransformConfig transform = validDataFrameTransformConfigBuilder(id, sourceIndex, "pivot-dest").setSyncConfig(
TransformConfig transform = validTransformConfigBuilder(id, sourceIndex, "pivot-dest").setSyncConfig(
TimeSyncConfig.builder().setField("timestamp").setDelay(TimeValue.timeValueSeconds(60)).build()
).build();

Expand Down Expand Up @@ -227,7 +227,7 @@ public void testCreateDeleteWithDefer() throws IOException {
String sourceIndex = "missing-source-index";

String id = "test-with-defer";
TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest");
TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest");
TransformClient client = highLevelClient().transform();
PutTransformRequest request = new PutTransformRequest(transform);
request.setDeferValidation(true);
Expand All @@ -243,7 +243,7 @@ public void testGetTransform() throws IOException {
createIndex(sourceIndex);

String id = "test-get";
TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest");
TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest");

TransformClient client = highLevelClient().transform();
putTransform(transform);
Expand All @@ -261,10 +261,10 @@ public void testGetAllAndPageTransforms() throws IOException {

TransformClient client = highLevelClient().transform();

TransformConfig transform = validDataFrameTransformConfig("test-get-all-1", sourceIndex, "pivot-dest-1");
TransformConfig transform = validTransformConfig("test-get-all-1", sourceIndex, "pivot-dest-1");
putTransform(transform);

transform = validDataFrameTransformConfig("test-get-all-2", sourceIndex, "pivot-dest-2");
transform = validTransformConfig("test-get-all-2", sourceIndex, "pivot-dest-2");
putTransform(transform);

GetTransformRequest getRequest = new GetTransformRequest("_all");
Expand Down Expand Up @@ -299,7 +299,7 @@ public void testStartStop() throws IOException {
createIndex(sourceIndex);

String id = "test-stop-start";
TransformConfig transform = validDataFrameTransformConfig(id, sourceIndex, "pivot-dest");
TransformConfig transform = validTransformConfig(id, sourceIndex, "pivot-dest");

TransformClient client = highLevelClient().transform();
putTransform(transform);
Expand Down Expand Up @@ -341,11 +341,14 @@ public void testPreview() throws IOException {
createIndex(sourceIndex);
indexData(sourceIndex);

TransformConfig transform = validDataFrameTransformConfig("test-preview", sourceIndex, null);
TransformConfig transform = validTransformConfig("test-preview", sourceIndex, null);

TransformClient client = highLevelClient().transform();
PreviewTransformResponse preview =
execute(new PreviewTransformRequest(transform), client::previewTransform, client::previewTransformAsync);
PreviewTransformResponse preview = execute(
new PreviewTransformRequest(transform),
client::previewTransform,
client::previewTransformAsync
);
assertExpectedPreview(preview);
}

Expand All @@ -355,12 +358,15 @@ public void testPreviewById() throws IOException {
indexData(sourceIndex);

String transformId = "test-preview-by-id";
TransformConfig transform = validDataFrameTransformConfig(transformId, sourceIndex, "pivot-dest");
TransformConfig transform = validTransformConfig(transformId, sourceIndex, "pivot-dest");
putTransform(transform);

TransformClient client = highLevelClient().transform();
PreviewTransformResponse preview =
execute(new PreviewTransformRequest(transformId), client::previewTransform, client::previewTransformAsync);
PreviewTransformResponse preview = execute(
new PreviewTransformRequest(transformId),
client::previewTransform,
client::previewTransformAsync
);
assertExpectedPreview(preview);
}

Expand All @@ -383,11 +389,11 @@ private static void assertExpectedPreview(PreviewTransformResponse preview) {
assertThat(fields.get("avg_rating"), equalTo(Map.of("type", "double")));
}

private TransformConfig validDataFrameTransformConfig(String id, String source, String destination) {
return validDataFrameTransformConfigBuilder(id, source, destination).build();
private TransformConfig validTransformConfig(String id, String source, String destination) {
return validTransformConfigBuilder(id, source, destination).build();
}

private TransformConfig.Builder validDataFrameTransformConfigBuilder(String id, String source, String destination) {
private TransformConfig.Builder validTransformConfigBuilder(String id, String source, String destination) {
GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build();
AggregatorFactories.Builder aggBuilder = new AggregatorFactories.Builder();
aggBuilder.addAggregator(AggregationBuilders.avg("avg_rating").field("stars"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import org.elasticsearch.client.transform.transforms.TransformConfigUpdateTests;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.XContentParser;
import org.elasticsearch.xcontent.json.JsonXContent;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.test.ESTestCase;

import java.io.IOException;
import java.util.Collections;
Expand All @@ -58,9 +58,8 @@ protected NamedXContentRegistry xContentRegistry() {
return new NamedXContentRegistry(namedXContents);
}

public void testPutDataFrameTransform() throws IOException {
PutTransformRequest putRequest = new PutTransformRequest(
TransformConfigTests.randomTransformConfig());
public void testPutTransform() throws IOException {
PutTransformRequest putRequest = new PutTransformRequest(TransformConfigTests.randomTransformConfig());
Request request = TransformRequestConverters.putTransform(putRequest);
assertThat(request.getParameters(), not(hasKey("defer_validation")));
assertEquals(HttpPut.METHOD_NAME, request.getMethod());
Expand All @@ -75,11 +74,12 @@ public void testPutDataFrameTransform() throws IOException {
assertThat(request.getParameters(), hasEntry("defer_validation", Boolean.toString(putRequest.getDeferValidation())));
}

public void testUpdateDataFrameTransform() throws IOException {
public void testUpdateTransform() throws IOException {
String transformId = randomAlphaOfLength(10);
UpdateTransformRequest updateDataFrameTransformRequest = new UpdateTransformRequest(
TransformConfigUpdateTests.randomTransformConfigUpdate(),
transformId);
transformId
);
Request request = TransformRequestConverters.updateTransform(updateDataFrameTransformRequest);
assertThat(request.getParameters(), not(hasKey("defer_validation")));
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
Expand All @@ -91,11 +91,13 @@ public void testUpdateDataFrameTransform() throws IOException {
}
updateDataFrameTransformRequest.setDeferValidation(true);
request = TransformRequestConverters.updateTransform(updateDataFrameTransformRequest);
assertThat(request.getParameters(),
hasEntry("defer_validation", Boolean.toString(updateDataFrameTransformRequest.getDeferValidation())));
assertThat(
request.getParameters(),
hasEntry("defer_validation", Boolean.toString(updateDataFrameTransformRequest.getDeferValidation()))
);
}

public void testDeleteDataFrameTransform() {
public void testDeleteTransform() {
DeleteTransformRequest deleteRequest = new DeleteTransformRequest("foo");
Request request = TransformRequestConverters.deleteTransform(deleteRequest);

Expand All @@ -110,7 +112,7 @@ public void testDeleteDataFrameTransform() {
assertThat(request.getParameters(), hasEntry("force", "true"));
}

public void testStartDataFrameTransform() {
public void testStartTransform() {
String id = randomAlphaOfLength(10);
TimeValue timeValue = null;
if (randomBoolean()) {
Expand All @@ -130,7 +132,7 @@ public void testStartDataFrameTransform() {
}
}

public void testStopDataFrameTransform() {
public void testStopTransform() {
String id = randomAlphaOfLength(10);
Boolean waitForCompletion = null;
if (randomBoolean()) {
Expand Down Expand Up @@ -177,7 +179,7 @@ public void testStopDataFrameTransform() {
assertEquals(stopRequest.getAllowNoMatch(), Boolean.parseBoolean(request.getParameters().get(ALLOW_NO_MATCH)));
}

public void testPreviewDataFrameTransform() throws IOException {
public void testPreviewTransform() throws IOException {
PreviewTransformRequest previewRequest = new PreviewTransformRequest(TransformConfigTests.randomTransformConfig());
Request request = TransformRequestConverters.previewTransform(previewRequest);

Expand All @@ -190,7 +192,7 @@ public void testPreviewDataFrameTransform() throws IOException {
}
}

public void testPreviewDataFrameTransformById() throws IOException {
public void testPreviewTransformById() throws IOException {
String transformId = randomAlphaOfLengthBetween(1, 10);
PreviewTransformRequest previewRequest = new PreviewTransformRequest(transformId);
Request request = TransformRequestConverters.previewTransform(previewRequest);
Expand All @@ -200,7 +202,7 @@ public void testPreviewDataFrameTransformById() throws IOException {
assertThat(request.getEntity(), nullValue());
}

public void testGetDataFrameTransformStats() {
public void testGetTransformStats() {
GetTransformStatsRequest getStatsRequest = new GetTransformStatsRequest("foo");
Request request = TransformRequestConverters.getTransformStats(getStatsRequest);

Expand Down Expand Up @@ -230,7 +232,7 @@ public void testGetDataFrameTransformStats() {
assertThat(request.getParameters(), hasEntry("allow_no_match", "false"));
}

public void testGetDataFrameTransform() {
public void testGetTransform() {
GetTransformRequest getRequest = new GetTransformRequest("bar");
Request request = TransformRequestConverters.getTransform(getRequest);

Expand Down Expand Up @@ -260,7 +262,7 @@ public void testGetDataFrameTransform() {
assertThat(request.getParameters(), hasEntry("allow_no_match", "false"));
}

public void testGetDataFrameTransform_givenMulitpleIds() {
public void testGetTransform_givenMulitpleIds() {
GetTransformRequest getRequest = new GetTransformRequest("foo", "bar", "baz");
Request request = TransformRequestConverters.getTransform(getRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
import org.elasticsearch.client.transform.transforms.pivot.PivotConfig;
import org.elasticsearch.client.transform.transforms.pivot.TermsGroupSource;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.index.query.MatchAllQueryBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.After;

import java.io.IOException;
Expand Down Expand Up @@ -445,7 +445,7 @@ public void onFailure(Exception e) {
}
}

public void testDeleteDataFrameTransform() throws IOException, InterruptedException {
public void testDeleteTransform() throws IOException, InterruptedException {
createIndex("source-data");

RestHighLevelClient client = highLevelClient();
Expand Down Expand Up @@ -670,7 +670,7 @@ public void onFailure(Exception e) {
}
}

public void testGetDataFrameTransform() throws IOException, InterruptedException {
public void testGetTransform() throws IOException, InterruptedException {
createIndex("source-data");

GroupConfig groupConfig = GroupConfig.builder().groupBy("reviewer", TermsGroupSource.builder().setField("user_id").build()).build();
Expand Down
Loading

0 comments on commit fd4dca8

Please sign in to comment.