Skip to content

Commit ada3b48

Browse files
committed
remove unnecessary changes to FieldNameUtils
1 parent dc6c618 commit ada3b48

File tree

3 files changed

+12
-53
lines changed

3 files changed

+12
-53
lines changed

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -786,17 +786,11 @@ public record PreAnalysisResult(
786786
EnrichResolution enrichResolution,
787787
Set<String> fieldNames,
788788
Set<String> wildcardJoinIndices,
789-
InferenceResolution inferenceResolution,
790-
boolean collectAllDimensions
789+
InferenceResolution inferenceResolution
791790
) {
792791

793-
public PreAnalysisResult(
794-
EnrichResolution enrichResolution,
795-
Set<String> fieldNames,
796-
Set<String> wildcardJoinIndices,
797-
boolean collectAllDimensions
798-
) {
799-
this(null, new HashMap<>(), enrichResolution, fieldNames, wildcardJoinIndices, InferenceResolution.EMPTY, collectAllDimensions);
792+
public PreAnalysisResult(EnrichResolution enrichResolution, Set<String> fieldNames, Set<String> wildcardJoinIndices) {
793+
this(null, new HashMap<>(), enrichResolution, fieldNames, wildcardJoinIndices, InferenceResolution.EMPTY);
800794
}
801795

802796
PreAnalysisResult withInferenceResolution(InferenceResolution newInferenceResolution) {
@@ -806,8 +800,7 @@ PreAnalysisResult withInferenceResolution(InferenceResolution newInferenceResolu
806800
enrichResolution(),
807801
fieldNames(),
808802
wildcardJoinIndices(),
809-
newInferenceResolution,
810-
collectAllDimensions()
803+
newInferenceResolution
811804
);
812805
}
813806

@@ -818,8 +811,7 @@ PreAnalysisResult withIndexResolution(IndexResolution newIndexResolution) {
818811
enrichResolution(),
819812
fieldNames(),
820813
wildcardJoinIndices(),
821-
inferenceResolution(),
822-
collectAllDimensions()
814+
inferenceResolution()
823815
);
824816
}
825817

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,10 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
7070
inlinestatsAggs.add(((InlineStats) i).aggregate());
7171
}
7272

73-
boolean shouldCollectAllDimensions = false;
74-
// Detect if we are in TS mode
75-
List<LogicalPlan> relations = parsed.collect(UnresolvedRelation.class::isInstance);
76-
for (LogicalPlan i : relations) {
77-
if (((UnresolvedRelation) i).isTimeSeriesMode()) {
78-
shouldCollectAllDimensions = true;
79-
}
80-
}
81-
8273
if (false == parsed.anyMatch(p -> shouldCollectReferencedFields(p, inlinestatsAggs))) {
8374
// no explicit columns selection, for example "from employees"
8475
// also, inlinestats only adds columns to the existent output, its Aggregate shouldn't interfere with potentially using "*"
85-
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of(), shouldCollectAllDimensions);
76+
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of());
8677
}
8778

8879
Holder<Boolean> projectAll = new Holder<>(false);
@@ -94,7 +85,7 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
9485
});
9586

9687
if (projectAll.get()) {
97-
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of(), shouldCollectAllDimensions);
88+
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of());
9889
}
9990

10091
var referencesBuilder = new Holder<>(AttributeSet.builder());
@@ -229,7 +220,7 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
229220
parsed.forEachDownMayReturnEarly(forEachDownProcessor.get());
230221

231222
if (projectAll.get()) {
232-
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of(), shouldCollectAllDimensions);
223+
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of());
233224
}
234225

235226
// Add JOIN ON column references afterward to avoid Alias removal
@@ -243,17 +234,12 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
243234

244235
if (fieldNames.isEmpty() && enrichPolicyMatchFields.isEmpty()) {
245236
// there cannot be an empty list of fields, we'll ask the simplest and lightest one instead: _index
246-
return new PreAnalysisResult(
247-
enrichResolution,
248-
IndexResolver.INDEX_METADATA_FIELD,
249-
wildcardJoinIndices,
250-
shouldCollectAllDimensions
251-
);
237+
return new PreAnalysisResult(enrichResolution, IndexResolver.INDEX_METADATA_FIELD, wildcardJoinIndices);
252238
} else {
253239
fieldNames.addAll(subfields(fieldNames));
254240
fieldNames.addAll(enrichPolicyMatchFields);
255241
fieldNames.addAll(subfields(enrichPolicyMatchFields));
256-
return new PreAnalysisResult(enrichResolution, fieldNames, wildcardJoinIndices, shouldCollectAllDimensions);
242+
return new PreAnalysisResult(enrichResolution, fieldNames, wildcardJoinIndices);
257243
}
258244
}
259245

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

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

20-
import java.util.HashSet;
2120
import java.util.List;
2221
import java.util.Map;
2322
import java.util.Set;
@@ -1613,7 +1612,7 @@ public void testMetrics() {
16131612
assertThat(e.getMessage(), containsString("line 1:1: mismatched input 'TS' expecting {"));
16141613
return;
16151614
}
1616-
assertTsFieldNames(
1615+
assertFieldNames(
16171616
query,
16181617
Set.of(
16191618
"@timestamp",
@@ -2996,27 +2995,9 @@ private void assertFieldNames(String query, Set<String> expected, Set<String> wi
29962995
}
29972996

29982997
private void assertFieldNames(String query, EnrichResolution enrichResolution, Set<String> expected, Set<String> wildCardIndices) {
2999-
EsqlSession.PreAnalysisResult preAnalysisResult = FieldNameUtils.resolveFieldNames(
3000-
parser.createStatement(query, EsqlTestUtils.TEST_CFG),
3001-
enrichResolution
3002-
);
2998+
var preAnalysisResult = FieldNameUtils.resolveFieldNames(parser.createStatement(query, EsqlTestUtils.TEST_CFG), enrichResolution);
30032999
assertThat("Query-wide field names", preAnalysisResult.fieldNames(), equalTo(expected));
30043000
assertThat("Lookup Indices that expect wildcard lookups", preAnalysisResult.wildcardJoinIndices(), equalTo(wildCardIndices));
3005-
assertThat(preAnalysisResult.collectAllDimensions(), equalTo(false));
3006-
}
3007-
3008-
private void assertTsFieldNames(String query, Set<String> expected) {
3009-
// Expected may be unmodifiable
3010-
Set<String> tsExpected = new HashSet<>(expected);
3011-
tsExpected.add("@timestamp");
3012-
tsExpected.add("@timestamp.*");
3013-
3014-
EsqlSession.PreAnalysisResult preAnalysisResult = FieldNameUtils.resolveFieldNames(
3015-
parser.createStatement(query, EsqlTestUtils.TEST_CFG),
3016-
new EnrichResolution()
3017-
);
3018-
assertThat("Query-wide field names", preAnalysisResult.fieldNames(), equalTo(tsExpected));
3019-
assertThat("TS mode query should collect all dimensions", preAnalysisResult.collectAllDimensions(), equalTo(true));
30203001
}
30213002

30223003
private static EnrichResolution enrichResolutionWith(String enrichPolicyMatchField) {

0 commit comments

Comments
 (0)