Skip to content

Commit abf4d35

Browse files
committed
start of tests
1 parent cbfbbbb commit abf4d35

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/analysis/IgnoreNullMetrics.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,12 @@ private Set<Attribute> collectMetrics(LogicalPlan logicalPlan) {
7878
* Scans the given {@link LogicalPlan} to see if it is a "metrics mode" query
7979
*/
8080
private static boolean isMetricsQuery(LogicalPlan logicalPlan) {
81-
List<LogicalPlan> tsNodes = logicalPlan.collect(n -> {
82-
if (n instanceof EsRelation r) {
83-
return r.indexMode() == IndexMode.TIME_SERIES;
84-
}
85-
if (n instanceof UnresolvedRelation r) {
86-
return r.indexMode() == IndexMode.TIME_SERIES;
87-
}
88-
return false;
89-
});
90-
return tsNodes.isEmpty() == false;
81+
if (logicalPlan instanceof EsRelation r) {
82+
return r.indexMode() == IndexMode.TIME_SERIES;
83+
}
84+
if (logicalPlan instanceof UnresolvedRelation r) {
85+
return r.indexMode() == IndexMode.TIME_SERIES;
86+
}
87+
return false;
9188
}
9289
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/index/EsIndex.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
public record EsIndex(
2323
String name,
24+
/** Map of field names to {@link EsField} instances representing that field */
2425
Map<String, EsField> mapping,
2526
Map<String, IndexMode> indexNameWithModes,
2627
/** Fields mapped only in some (but *not* all) indices. Since this is only used by the analyzer, it is not serialized. */

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/IgnoreNullMetricsTests.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,73 @@
77

88
package org.elasticsearch.xpack.esql.analysis;
99

10+
import org.elasticsearch.index.IndexMode;
1011
import org.elasticsearch.test.ESTestCase;
12+
import org.elasticsearch.xpack.esql.EsqlTestUtils;
13+
import org.elasticsearch.xpack.esql.core.tree.Source;
14+
import org.elasticsearch.xpack.esql.core.type.DataType;
15+
import org.elasticsearch.xpack.esql.core.type.EsField;
16+
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
17+
import org.elasticsearch.xpack.esql.expression.predicate.nulls.IsNotNull;
18+
import org.elasticsearch.xpack.esql.index.EsIndex;
19+
import org.elasticsearch.xpack.esql.index.IndexResolution;
20+
import org.elasticsearch.xpack.esql.parser.EsqlParser;
21+
import org.elasticsearch.xpack.esql.plan.logical.Aggregate;
22+
import org.elasticsearch.xpack.esql.plan.logical.Filter;
23+
import org.elasticsearch.xpack.esql.plan.logical.Limit;
24+
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
1125

26+
import java.util.Map;
27+
28+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.TEST_VERIFIER;
29+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.as;
30+
import static org.elasticsearch.xpack.esql.EsqlTestUtils.emptyInferenceResolution;
31+
import static org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils.defaultLookupResolution;
32+
33+
/**
34+
* Tests desi
35+
*/
1236
public class IgnoreNullMetricsTests extends ESTestCase {
1337

38+
private Analyzer analyzer;
39+
40+
private LogicalPlan analyze(String query) {
41+
EsqlParser parser = new EsqlParser();
42+
EnrichResolution enrichResolution = new EnrichResolution();
43+
AnalyzerTestUtils.loadEnrichPolicyResolution(enrichResolution, "languages_idx", "id", "languages_idx", "mapping-languages.json");
44+
45+
Map<String, EsField> mapping = Map.of(
46+
"dimension_1",
47+
new EsField("dimension_1", DataType.KEYWORD, Map.of(), true, EsField.TimeSeriesFieldType.DIMENSION),
48+
"metric_1",
49+
new EsField("metric_1", DataType.LONG, Map.of(), true, EsField.TimeSeriesFieldType.METRIC)
50+
);
51+
EsIndex test = new EsIndex("test", mapping, Map.of("test", IndexMode.TIME_SERIES));
52+
IndexResolution getIndexResult = IndexResolution.valid(test);
53+
analyzer = new Analyzer(
54+
new AnalyzerContext(
55+
EsqlTestUtils.TEST_CFG,
56+
new EsqlFunctionRegistry(),
57+
getIndexResult,
58+
defaultLookupResolution(),
59+
enrichResolution,
60+
emptyInferenceResolution()
61+
),
62+
TEST_VERIFIER
63+
);
64+
65+
return analyzer.analyze(parser.createStatement(query, EsqlTestUtils.TEST_CFG));
66+
}
67+
68+
public void testSimple() {
69+
LogicalPlan actual = analyze("""
70+
TS test
71+
| STATS max(max_over_time(metric_1))
72+
""");
73+
Limit limit = as(actual, Limit.class);
74+
Aggregate agg = as(limit.child(), Aggregate.class);
75+
Filter filter = as(agg.child(), Filter.class);
76+
IsNotNull condition = as(filter.condition(), IsNotNull.class);
77+
78+
}
1479
}

0 commit comments

Comments
 (0)