Skip to content

Commit 74fa6a8

Browse files
committed
fix tests
1 parent 5ff350c commit 74fa6a8

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/UnresolvedRelation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,6 @@ public String toString() {
172172
* which changes a number of behaviors in the planner.
173173
*/
174174
public boolean isTimeSeriesMode() {
175-
return commandName.equalsIgnoreCase("TS");
175+
return indexMode == IndexMode.TIME_SERIES;
176176
}
177177
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/FieldNameUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
172172
}
173173
} else {
174174
referencesBuilder.get().addAll(p.references());
175-
if (p instanceof UnresolvedRelation ur && ur.indexMode() == IndexMode.TIME_SERIES) {
175+
if (p instanceof UnresolvedRelation ur && ur.isTimeSeriesMode()) {
176176
// METRICS aggs generally rely on @timestamp without the user having to mention it.
177177
referencesBuilder.get().add(new UnresolvedAttribute(ur.source(), MetadataAttribute.TIMESTAMP_FIELD));
178178
}

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/session/FieldNameUtilsTests.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import org.elasticsearch.xpack.esql.parser.ParsingException;
1818
import org.elasticsearch.xpack.esql.plan.logical.Enrich;
1919

20+
import java.util.HashSet;
2021
import java.util.List;
21-
import java.util.Locale;
2222
import java.util.Map;
2323
import java.util.Set;
2424

@@ -1613,7 +1613,7 @@ public void testMetrics() {
16131613
assertThat(e.getMessage(), containsString("line 1:1: mismatched input 'TS' expecting {"));
16141614
return;
16151615
}
1616-
assertFieldNames(
1616+
assertTsFieldNames(
16171617
query,
16181618
Set.of(
16191619
"@timestamp",
@@ -2977,15 +2977,19 @@ private void assertFieldNames(String query, EnrichResolution enrichResolution, S
29772977
assertThat("Query-wide field names", preAnalysisResult.fieldNames(), equalTo(expected));
29782978
assertThat("Lookup Indices that expect wildcard lookups", preAnalysisResult.wildcardJoinIndices(), equalTo(wildCardIndices));
29792979
assertThat(preAnalysisResult.collectAllDimensions(), equalTo(false));
2980+
}
29802981

2981-
// try again with TS command
2982-
String tsQuery = query.toLowerCase(Locale.ROOT).replaceFirst("^from", "ts");
2983-
if (tsQuery.equals(query)) {
2984-
return;
2985-
}
2986-
preAnalysisResult = FieldNameUtils.resolveFieldNames(parser.createStatement(tsQuery, EsqlTestUtils.TEST_CFG), enrichResolution);
2987-
assertThat("Query-wide field names", preAnalysisResult.fieldNames(), equalTo(expected));
2988-
assertThat("Lookup Indices that expect wildcard lookups", preAnalysisResult.wildcardJoinIndices(), equalTo(wildCardIndices));
2982+
private void assertTsFieldNames(String query, Set<String> expected) {
2983+
// Expected may be unmodifiable
2984+
Set<String> tsExpected = new HashSet<>(expected);
2985+
tsExpected.add("@timestamp");
2986+
tsExpected.add("@timestamp.*");
2987+
2988+
EsqlSession.PreAnalysisResult preAnalysisResult = FieldNameUtils.resolveFieldNames(
2989+
parser.createStatement(query, EsqlTestUtils.TEST_CFG),
2990+
new EnrichResolution()
2991+
);
2992+
assertThat("Query-wide field names", preAnalysisResult.fieldNames(), equalTo(tsExpected));
29892993
assertThat(preAnalysisResult.collectAllDimensions(), equalTo(true));
29902994
}
29912995

0 commit comments

Comments
 (0)