Skip to content

Commit d56c5fe

Browse files
committed
Basic query shape related classes
Signed-off-by: Siddhant Deshmukh <deshsid@amazon.com>
1 parent defbd60 commit d56c5fe

15 files changed

+377
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.aggregations;
10+
11+
import org.opensearch.plugin.insights.rules.model.queryshape.misc.AggregationShape;
12+
13+
import java.util.Collections;
14+
import java.util.List;
15+
import java.util.Objects;
16+
17+
public class SumAggregationShape extends AggregationShape {
18+
String fieldName;
19+
List<? extends AggregationShape> subAggregations;
20+
21+
@Override
22+
public int hashCode() {
23+
if (subAggregations != null) {
24+
Collections.sort(subAggregations);
25+
}
26+
return Objects.hash(fieldName, subAggregations);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.aggregations;
10+
11+
import org.opensearch.plugin.insights.rules.model.queryshape.misc.AggregationShape;
12+
13+
import java.util.Collections;
14+
import java.util.List;
15+
import java.util.Objects;
16+
17+
public class TermsAggregationShape extends AggregationShape {
18+
String fieldName;
19+
List<? extends AggregationShape> subAggregations;
20+
21+
@Override
22+
public int hashCode() {
23+
if (subAggregations != null) {
24+
Collections.sort(subAggregations);
25+
}
26+
return Objects.hash(fieldName, subAggregations);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.core;
10+
11+
import org.opensearch.plugin.insights.rules.model.queryshape.misc.AggregationShape;
12+
13+
import java.util.Collections;
14+
import java.util.List;
15+
import java.util.Objects;
16+
17+
class AggregationFullShape {
18+
List<? extends AggregationShape> aggregations;
19+
20+
@Override
21+
public int hashCode() {
22+
Collections.sort(aggregations);
23+
return Objects.hash(aggregations);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.core;
10+
11+
import java.util.Collections;
12+
import java.util.List;
13+
import java.util.Objects;
14+
15+
class PipelineAggregationShape {
16+
List<String> pipelineAggregations;
17+
18+
@Override
19+
public int hashCode() {
20+
Collections.sort(pipelineAggregations);
21+
return Objects.hash(pipelineAggregations);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.core;
10+
11+
import org.opensearch.plugin.insights.rules.model.queryshape.misc.QueryBuilderShape;
12+
13+
import java.util.Objects;
14+
15+
class QueryBuilderFullShape {
16+
QueryBuilderShape queryBuilderShape;
17+
18+
@Override
19+
public int hashCode() {
20+
return Objects.hash(queryBuilderShape);
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.core;
10+
11+
import org.opensearch.index.query.QueryBuilder;
12+
import org.opensearch.search.builder.SearchSourceBuilder;
13+
14+
import java.util.Objects;
15+
16+
/**
17+
* Representation of a Query Shape primarily used to group Top N queries by latency and resource usage.
18+
* https://github.com/opensearch-project/OpenSearch/issues/13357
19+
* @opensearch.internal
20+
*/
21+
public class QueryShape {
22+
private QueryBuilderFullShape queryBuilderFullShape;
23+
private SortShape sortShape;
24+
private AggregationFullShape aggregationFullShape;
25+
private PipelineAggregationShape pipelineAggregationShape;
26+
27+
@Override
28+
public int hashCode() {
29+
return Objects.hash(queryBuilderFullShape, sortShape, aggregationFullShape, pipelineAggregationShape);
30+
}
31+
32+
public void parse(SearchSourceBuilder source) {
33+
// Parse the QueryBuilder to QueryShape
34+
// Populate QueryBuilderFullShape, SortShape, AggregationFullShape, PipelineAggregationShape
35+
}
36+
37+
public String getStringQueryShape() {
38+
// Provide the String Query Shape
39+
return null;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.core;
10+
11+
import org.opensearch.plugin.insights.rules.model.queryshape.misc.SortShapeField;
12+
13+
import java.util.List;
14+
import java.util.Objects;
15+
16+
class SortShape {
17+
List<SortShapeField> sortShapeFields;
18+
19+
@Override
20+
public int hashCode() {
21+
return Objects.hash(sortShapeFields);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.misc;
10+
11+
public abstract class AggregationShape implements Comparable<AggregationShape> {
12+
@Override
13+
public int compareTo(AggregationShape other) {
14+
return this.getClass().getName().compareTo(other.getClass().getName());
15+
}
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.misc;
10+
11+
public abstract class QueryBuilderShape implements Comparable<QueryBuilderShape> {
12+
13+
@Override
14+
public int compareTo(QueryBuilderShape other) {
15+
return this.getClass().getName().compareTo(other.getClass().getName());
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.rules.model.queryshape.misc;
10+
11+
import java.util.Objects;
12+
13+
public class SortShapeField {
14+
String fieldName;
15+
String sortOrder;
16+
17+
@Override
18+
public int hashCode() {
19+
return Objects.hash(fieldName, sortOrder);
20+
}
21+
}

0 commit comments

Comments
 (0)