-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Data Frame HLRC Get API (#40509)
- Loading branch information
Showing
13 changed files
with
668 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...-level/src/main/java/org/elasticsearch/client/dataframe/GetDataFrameTransformRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.dataframe; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.ValidationException; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class GetDataFrameTransformRequest implements Validatable { | ||
|
||
private final List<String> ids; | ||
private Integer from; | ||
private Integer size; | ||
|
||
/** | ||
* Helper method to create a request that will get ALL Data Frame Transforms | ||
* @return new {@link GetDataFrameTransformRequest} object for the id "_all" | ||
*/ | ||
public static GetDataFrameTransformRequest getAllDataFrameTransformsRequest() { | ||
return new GetDataFrameTransformRequest("_all"); | ||
} | ||
|
||
public GetDataFrameTransformRequest(String... ids) { | ||
this.ids = Arrays.asList(ids); | ||
} | ||
|
||
public List<String> getId() { | ||
return ids; | ||
} | ||
|
||
public Integer getFrom() { | ||
return from; | ||
} | ||
|
||
public void setFrom(Integer from) { | ||
this.from = from; | ||
} | ||
|
||
public Integer getSize() { | ||
return size; | ||
} | ||
|
||
public void setSize(Integer size) { | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { | ||
if (ids == null || ids.isEmpty()) { | ||
ValidationException validationException = new ValidationException(); | ||
validationException.addValidationError("data frame transform id must not be null"); | ||
return Optional.of(validationException); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(ids); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetDataFrameTransformRequest other = (GetDataFrameTransformRequest) obj; | ||
return Objects.equals(ids, other.ids); | ||
} | ||
} |
142 changes: 142 additions & 0 deletions
142
...level/src/main/java/org/elasticsearch/client/dataframe/GetDataFrameTransformResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.dataframe; | ||
|
||
import org.elasticsearch.client.dataframe.transforms.DataFrameTransformConfig; | ||
import org.elasticsearch.common.Nullable; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
public class GetDataFrameTransformResponse { | ||
|
||
public static final ParseField TRANSFORMS = new ParseField("transforms"); | ||
public static final ParseField INVALID_TRANSFORMS = new ParseField("invalid_transforms"); | ||
public static final ParseField COUNT = new ParseField("count"); | ||
|
||
@SuppressWarnings("unchecked") | ||
static final ConstructingObjectParser<InvalidTransforms, Void> INVALID_TRANSFORMS_PARSER = | ||
new ConstructingObjectParser<>("invalid_transforms", true, args -> new InvalidTransforms((List<String>) args[0])); | ||
|
||
@SuppressWarnings("unchecked") | ||
static final ConstructingObjectParser<GetDataFrameTransformResponse, Void> PARSER = new ConstructingObjectParser<>( | ||
"get_data_frame_transform", true, args -> new GetDataFrameTransformResponse( | ||
(List<DataFrameTransformConfig>) args[0], (int) args[1], (InvalidTransforms) args[2])); | ||
static { | ||
// Discard the count field which is the size of the transforms array | ||
INVALID_TRANSFORMS_PARSER.declareInt((a, b) -> {}, COUNT); | ||
INVALID_TRANSFORMS_PARSER.declareStringArray(constructorArg(), TRANSFORMS); | ||
|
||
PARSER.declareObjectArray(constructorArg(), DataFrameTransformConfig.PARSER::apply, TRANSFORMS); | ||
PARSER.declareInt(constructorArg(), COUNT); | ||
PARSER.declareObject(optionalConstructorArg(), INVALID_TRANSFORMS_PARSER::apply, INVALID_TRANSFORMS); | ||
} | ||
|
||
public static GetDataFrameTransformResponse fromXContent(final XContentParser parser) { | ||
return GetDataFrameTransformResponse.PARSER.apply(parser, null); | ||
} | ||
|
||
private List<DataFrameTransformConfig> transformConfigurations; | ||
private int count; | ||
private InvalidTransforms invalidTransforms; | ||
|
||
public GetDataFrameTransformResponse(List<DataFrameTransformConfig> transformConfigurations, | ||
int count, | ||
@Nullable InvalidTransforms invalidTransforms) { | ||
this.transformConfigurations = transformConfigurations; | ||
this.count = count; | ||
this.invalidTransforms = invalidTransforms; | ||
} | ||
|
||
@Nullable | ||
public InvalidTransforms getInvalidTransforms() { | ||
return invalidTransforms; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
|
||
public List<DataFrameTransformConfig> getTransformConfigurations() { | ||
return transformConfigurations; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(transformConfigurations, count, invalidTransforms); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
final GetDataFrameTransformResponse that = (GetDataFrameTransformResponse) other; | ||
return Objects.equals(this.transformConfigurations, that.transformConfigurations) | ||
&& Objects.equals(this.count, that.count) | ||
&& Objects.equals(this.invalidTransforms, that.invalidTransforms); | ||
} | ||
|
||
static class InvalidTransforms { | ||
private final List<String> transformIds; | ||
|
||
InvalidTransforms(List<String> transformIds) { | ||
this.transformIds = transformIds; | ||
} | ||
|
||
public int getCount() { | ||
return transformIds.size(); | ||
} | ||
|
||
public List<String> getTransformIds() { | ||
return transformIds; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(transformIds); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
final InvalidTransforms that = (InvalidTransforms) other; | ||
return Objects.equals(this.transformIds, that.transformIds); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.