-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[ML-Dataframe] Data frame transforms config HLRC objects #39691
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d1b22db
some config objs
davidkyle 4466a1b
Remove unused getter + other feedback
davidkyle ce08a38
Lenient parsing for GroupConfig
davidkyle 31b3b9f
Allow unknown group types in lenient parser
davidkyle cfae00f
Fix test error where 2 aggs can have the same name
davidkyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
...src/main/java/org/elasticsearch/client/dataframe/transforms/DataFrameTransformConfig.java
This file contains hidden or 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,163 @@ | ||
/* | ||
* 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.transforms; | ||
|
||
import org.elasticsearch.client.dataframe.transforms.pivot.PivotConfig; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
public class DataFrameTransformConfig implements ToXContentObject { | ||
|
||
public static final ParseField ID = new ParseField("id"); | ||
public static final ParseField SOURCE = new ParseField("source"); | ||
public static final ParseField DEST = new ParseField("dest"); | ||
public static final ParseField QUERY = new ParseField("query"); | ||
// types of transforms | ||
public static final ParseField PIVOT_TRANSFORM = new ParseField("pivot"); | ||
|
||
private final String id; | ||
private final String source; | ||
private final String dest; | ||
private final QueryConfig queryConfig; | ||
private final PivotConfig pivotConfig; | ||
|
||
private static final ConstructingObjectParser<DataFrameTransformConfig, String> PARSER = | ||
new ConstructingObjectParser<>("data_frame_transform", true, | ||
(args) -> { | ||
String id = (String) args[0]; | ||
String source = (String) args[1]; | ||
String dest = (String) args[2]; | ||
QueryConfig queryConfig = (QueryConfig) args[3]; | ||
PivotConfig pivotConfig = (PivotConfig) args[4]; | ||
return new DataFrameTransformConfig(id, source, dest, queryConfig, pivotConfig); | ||
}); | ||
|
||
static { | ||
PARSER.declareString(constructorArg(), ID); | ||
PARSER.declareString(constructorArg(), SOURCE); | ||
PARSER.declareString(constructorArg(), DEST); | ||
PARSER.declareObject(optionalConstructorArg(), (p, c) -> QueryConfig.fromXContent(p), QUERY); | ||
PARSER.declareObject(optionalConstructorArg(), (p, c) -> PivotConfig.fromXContent(p), PIVOT_TRANSFORM); | ||
} | ||
|
||
public static DataFrameTransformConfig fromXContent(final XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
|
||
public DataFrameTransformConfig(final String id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note I've taken the headers out of this class |
||
final String source, | ||
final String dest, | ||
final QueryConfig queryConfig, | ||
final PivotConfig pivotConfig) { | ||
this.id = Objects.requireNonNull(id); | ||
this.source = Objects.requireNonNull(source); | ||
this.dest = Objects.requireNonNull(dest); | ||
this.queryConfig = queryConfig; | ||
this.pivotConfig = pivotConfig; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public String getSource() { | ||
return source; | ||
} | ||
|
||
public String getDestination() { | ||
return dest; | ||
} | ||
|
||
public PivotConfig getPivotConfig() { | ||
return pivotConfig; | ||
} | ||
|
||
public QueryConfig getQueryConfig() { | ||
return queryConfig; | ||
} | ||
|
||
public boolean isValid() { | ||
if (queryConfig != null && queryConfig.isValid() == false) { | ||
return false; | ||
} | ||
|
||
if (pivotConfig == null || pivotConfig.isValid() == false) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { | ||
builder.startObject(); | ||
builder.field(ID.getPreferredName(), id); | ||
builder.field(SOURCE.getPreferredName(), source); | ||
builder.field(DEST.getPreferredName(), dest); | ||
if (queryConfig != null) { | ||
builder.field(QUERY.getPreferredName(), queryConfig); | ||
} | ||
if (pivotConfig != null) { | ||
builder.field(PIVOT_TRANSFORM.getPreferredName(), pivotConfig); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
final DataFrameTransformConfig that = (DataFrameTransformConfig) other; | ||
|
||
return Objects.equals(this.id, that.id) | ||
&& Objects.equals(this.source, that.source) | ||
&& Objects.equals(this.dest, that.dest) | ||
&& Objects.equals(this.queryConfig, that.queryConfig) | ||
&& Objects.equals(this.pivotConfig, that.pivotConfig); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, source, dest, queryConfig, pivotConfig); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Strings.toString(this, true, true); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...t-high-level/src/main/java/org/elasticsearch/client/dataframe/transforms/QueryConfig.java
This file contains hidden or 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,77 @@ | ||
/* | ||
* 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.transforms; | ||
|
||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.query.AbstractQueryBuilder; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class QueryConfig implements ToXContentObject { | ||
|
||
private final QueryBuilder query; | ||
|
||
public static QueryConfig fromXContent(XContentParser parser) throws IOException { | ||
QueryBuilder query = AbstractQueryBuilder.parseInnerQueryBuilder(parser); | ||
return new QueryConfig(query); | ||
} | ||
|
||
public QueryConfig(QueryBuilder query) { | ||
this.query = query; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
query.toXContent(builder, params); | ||
return builder; | ||
} | ||
|
||
public QueryBuilder getQuery() { | ||
return query; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(query); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
final QueryConfig that = (QueryConfig) other; | ||
|
||
return Objects.equals(this.query, that.query); | ||
} | ||
|
||
public boolean isValid() { | ||
return this.query != null; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
.../src/main/java/org/elasticsearch/client/dataframe/transforms/pivot/AggregationConfig.java
This file contains hidden or 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,80 @@ | ||
/* | ||
* 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.transforms.pivot; | ||
|
||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.search.aggregations.AggregationBuilder; | ||
import org.elasticsearch.search.aggregations.AggregatorFactories; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Objects; | ||
|
||
public class AggregationConfig implements ToXContentObject { | ||
private final AggregatorFactories.Builder aggregations; | ||
|
||
public static AggregationConfig fromXContent(XContentParser parser) throws IOException { | ||
if (parser.currentToken() == null) { | ||
parser.nextToken(); | ||
} | ||
AggregatorFactories.Builder aggregations = AggregatorFactories.parseAggregators(parser); | ||
return new AggregationConfig(aggregations); | ||
} | ||
|
||
public AggregationConfig(AggregatorFactories.Builder aggregations) { | ||
this.aggregations = aggregations; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
aggregations.toXContent(builder, params); | ||
return builder; | ||
} | ||
|
||
public Collection<AggregationBuilder> getAggregatorFactories() { | ||
return aggregations.getAggregatorFactories(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(aggregations); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
|
||
final AggregationConfig that = (AggregationConfig) other; | ||
|
||
return Objects.equals(this.aggregations, that.aggregations); | ||
} | ||
|
||
public boolean isValid() { | ||
return this.aggregations != null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, it would be nice for this class to provide a fluent builder API.