-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
- Loading branch information
Showing
15 changed files
with
377 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
...g/opensearch/plugin/insights/rules/model/queryshape/aggregations/SumAggregationShape.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,28 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.aggregations; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.AggregationShape; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class SumAggregationShape extends AggregationShape { | ||
String fieldName; | ||
List<? extends AggregationShape> subAggregations; | ||
|
||
@Override | ||
public int hashCode() { | ||
if (subAggregations != null) { | ||
Collections.sort(subAggregations); | ||
} | ||
return Objects.hash(fieldName, subAggregations); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...opensearch/plugin/insights/rules/model/queryshape/aggregations/TermsAggregationShape.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,28 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.aggregations; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.AggregationShape; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class TermsAggregationShape extends AggregationShape { | ||
String fieldName; | ||
List<? extends AggregationShape> subAggregations; | ||
|
||
@Override | ||
public int hashCode() { | ||
if (subAggregations != null) { | ||
Collections.sort(subAggregations); | ||
} | ||
return Objects.hash(fieldName, subAggregations); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/org/opensearch/plugin/insights/rules/model/queryshape/core/AggregationFullShape.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,25 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.core; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.AggregationShape; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
class AggregationFullShape { | ||
List<? extends AggregationShape> aggregations; | ||
|
||
@Override | ||
public int hashCode() { | ||
Collections.sort(aggregations); | ||
return Objects.hash(aggregations); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../org/opensearch/plugin/insights/rules/model/queryshape/core/PipelineAggregationShape.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,23 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.core; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
class PipelineAggregationShape { | ||
List<String> pipelineAggregations; | ||
|
||
@Override | ||
public int hashCode() { | ||
Collections.sort(pipelineAggregations); | ||
return Objects.hash(pipelineAggregations); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ava/org/opensearch/plugin/insights/rules/model/queryshape/core/QueryBuilderFullShape.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,22 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.core; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape; | ||
|
||
import java.util.Objects; | ||
|
||
class QueryBuilderFullShape { | ||
QueryBuilderShape queryBuilderShape; | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(queryBuilderShape); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.../src/main/java/org/opensearch/plugin/insights/rules/model/queryshape/core/QueryShape.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,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.core; | ||
|
||
import org.opensearch.index.query.QueryBuilder; | ||
import org.opensearch.search.builder.SearchSourceBuilder; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Representation of a Query Shape primarily used to group Top N queries by latency and resource usage. | ||
* https://github.com/opensearch-project/OpenSearch/issues/13357 | ||
* @opensearch.internal | ||
*/ | ||
public class QueryShape { | ||
private QueryBuilderFullShape queryBuilderFullShape; | ||
private SortShape sortShape; | ||
private AggregationFullShape aggregationFullShape; | ||
private PipelineAggregationShape pipelineAggregationShape; | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(queryBuilderFullShape, sortShape, aggregationFullShape, pipelineAggregationShape); | ||
} | ||
|
||
public void parse(SearchSourceBuilder source) { | ||
// Parse the QueryBuilder to QueryShape | ||
// Populate QueryBuilderFullShape, SortShape, AggregationFullShape, PipelineAggregationShape | ||
} | ||
|
||
public String getStringQueryShape() { | ||
// Provide the String Query Shape | ||
return null; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/src/main/java/org/opensearch/plugin/insights/rules/model/queryshape/core/SortShape.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,23 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.core; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.SortShapeField; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
class SortShape { | ||
List<SortShapeField> sortShapeFields; | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(sortShapeFields); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ain/java/org/opensearch/plugin/insights/rules/model/queryshape/misc/AggregationShape.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,17 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.misc; | ||
|
||
public abstract class AggregationShape implements Comparable<AggregationShape> { | ||
@Override | ||
public int compareTo(AggregationShape other) { | ||
return this.getClass().getName().compareTo(other.getClass().getName()); | ||
} | ||
} | ||
|
17 changes: 17 additions & 0 deletions
17
...in/java/org/opensearch/plugin/insights/rules/model/queryshape/misc/QueryBuilderShape.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,17 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.misc; | ||
|
||
public abstract class QueryBuilderShape implements Comparable<QueryBuilderShape> { | ||
|
||
@Override | ||
public int compareTo(QueryBuilderShape other) { | ||
return this.getClass().getName().compareTo(other.getClass().getName()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../main/java/org/opensearch/plugin/insights/rules/model/queryshape/misc/SortShapeField.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,21 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.misc; | ||
|
||
import java.util.Objects; | ||
|
||
public class SortShapeField { | ||
String fieldName; | ||
String sortOrder; | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fieldName, sortOrder); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
.../org/opensearch/plugin/insights/rules/model/queryshape/queries/BoolQueryBuilderShape.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,44 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.queries; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class BoolQueryBuilderShape extends QueryBuilderShape { | ||
List<? extends QueryBuilderShape> filterClause; | ||
List<? extends QueryBuilderShape> mustClause; | ||
List<? extends QueryBuilderShape> mustNotClause; | ||
List<? extends QueryBuilderShape> shouldClause; | ||
|
||
@Override | ||
public int hashCode() { | ||
// Sort the lists before calculating the hash code | ||
sortLists(); | ||
return Objects.hash(filterClause, mustClause, mustNotClause, shouldClause); | ||
} | ||
|
||
private void sortLists() { | ||
if (filterClause != null) { | ||
Collections.sort(filterClause); | ||
} | ||
if (mustClause != null) { | ||
Collections.sort(mustClause); | ||
} | ||
if (mustNotClause != null) { | ||
Collections.sort(mustNotClause); | ||
} | ||
if (shouldClause != null) { | ||
Collections.sort(shouldClause); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...rg/opensearch/plugin/insights/rules/model/queryshape/queries/ExistsQueryBuilderShape.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,22 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.queries; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape; | ||
|
||
import java.util.Objects; | ||
|
||
public class ExistsQueryBuilderShape extends QueryBuilderShape { | ||
String fieldName; | ||
String fieldValue; | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fieldName, fieldValue); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...org/opensearch/plugin/insights/rules/model/queryshape/queries/MatchQueryBuilderShape.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,22 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.queries; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape; | ||
|
||
import java.util.Objects; | ||
|
||
public class MatchQueryBuilderShape extends QueryBuilderShape { | ||
String fieldName; | ||
String fieldValue; | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fieldName, fieldValue); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../org/opensearch/plugin/insights/rules/model/queryshape/queries/MustQueryBuilderShape.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,22 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.queries; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape; | ||
|
||
import java.util.Objects; | ||
|
||
public class MustQueryBuilderShape extends QueryBuilderShape { | ||
String fieldName; | ||
String fieldValue; | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fieldName, fieldValue); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
.../org/opensearch/plugin/insights/rules/model/queryshape/queries/TermQueryBuilderShape.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,22 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.rules.model.queryshape.queries; | ||
|
||
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape; | ||
|
||
import java.util.Objects; | ||
|
||
public class TermQueryBuilderShape extends QueryBuilderShape { | ||
String fieldName; | ||
String fieldValue; | ||
@Override | ||
public int hashCode() { | ||
return Objects.hash(fieldName, fieldValue); | ||
} | ||
} |