Skip to content

Commit fb35040

Browse files
committed
add flag for collecting dimensions
1 parent 4a38b0b commit fb35040

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,17 @@ public record PreAnalysisResult(
827827
EnrichResolution enrichResolution,
828828
Set<String> fieldNames,
829829
Set<String> wildcardJoinIndices,
830-
InferenceResolution inferenceResolution
830+
InferenceResolution inferenceResolution,
831+
boolean collectAllDimensions
831832
) {
832833

833-
public PreAnalysisResult(EnrichResolution enrichResolution, Set<String> fieldNames, Set<String> wildcardJoinIndices) {
834-
this(null, new HashMap<>(), enrichResolution, fieldNames, wildcardJoinIndices, InferenceResolution.EMPTY);
834+
public PreAnalysisResult(
835+
EnrichResolution enrichResolution,
836+
Set<String> fieldNames,
837+
Set<String> wildcardJoinIndices,
838+
boolean collectAllDimensions
839+
) {
840+
this(null, new HashMap<>(), enrichResolution, fieldNames, wildcardJoinIndices, InferenceResolution.EMPTY, collectAllDimensions);
835841
}
836842

837843
PreAnalysisResult withInferenceResolution(InferenceResolution newInferenceResolution) {
@@ -841,7 +847,8 @@ PreAnalysisResult withInferenceResolution(InferenceResolution newInferenceResolu
841847
enrichResolution(),
842848
fieldNames(),
843849
wildcardJoinIndices(),
844-
newInferenceResolution
850+
newInferenceResolution,
851+
collectAllDimensions()
845852
);
846853
}
847854

@@ -852,7 +859,8 @@ PreAnalysisResult withIndexResolution(IndexResolution newIndexResolution) {
852859
enrichResolution(),
853860
fieldNames(),
854861
wildcardJoinIndices(),
855-
inferenceResolution()
862+
inferenceResolution(),
863+
collectAllDimensions()
856864
);
857865
}
858866

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ public class FieldNameUtils {
5959
public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichResolution enrichResolution) {
6060

6161
// we need the match_fields names from enrich policies and THEN, with an updated list of fields, we call field_caps API
62-
var enrichPolicyMatchFields = enrichResolution.resolvedEnrichPolicies()
62+
Set<String> enrichPolicyMatchFields = enrichResolution.resolvedEnrichPolicies()
6363
.stream()
6464
.map(ResolvedEnrichPolicy::matchField)
6565
.collect(Collectors.toSet());
6666

6767
// get the field names from the parsed plan combined with the ENRICH match fields from the ENRICH policy
6868
List<LogicalPlan> inlinestats = parsed.collect(InlineStats.class::isInstance);
6969
Set<Aggregate> inlinestatsAggs = new HashSet<>();
70-
for (var i : inlinestats) {
70+
for (LogicalPlan i : inlinestats) {
7171
inlinestatsAggs.add(((InlineStats) i).aggregate());
7272
}
7373

7474
if (false == parsed.anyMatch(p -> shouldCollectReferencedFields(p, inlinestatsAggs))) {
7575
// no explicit columns selection, for example "from employees"
7676
// also, inlinestats only adds columns to the existent output, its Aggregate shouldn't interfere with potentially using "*"
77-
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of());
77+
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of(), false);
7878
}
7979

8080
Holder<Boolean> projectAll = new Holder<>(false);
@@ -86,7 +86,7 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
8686
});
8787

8888
if (projectAll.get()) {
89-
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of());
89+
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of(), false);
9090
}
9191

9292
var referencesBuilder = new Holder<>(AttributeSet.builder());
@@ -221,7 +221,7 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
221221
parsed.forEachDownMayReturnEarly(forEachDownProcessor.get());
222222

223223
if (projectAll.get()) {
224-
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of());
224+
return new PreAnalysisResult(enrichResolution, IndexResolver.ALL_FIELDS, Set.of(), false);
225225
}
226226

227227
// Add JOIN ON column references afterward to avoid Alias removal
@@ -235,12 +235,12 @@ public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichReso
235235

236236
if (fieldNames.isEmpty() && enrichPolicyMatchFields.isEmpty()) {
237237
// there cannot be an empty list of fields, we'll ask the simplest and lightest one instead: _index
238-
return new PreAnalysisResult(enrichResolution, IndexResolver.INDEX_METADATA_FIELD, wildcardJoinIndices);
238+
return new PreAnalysisResult(enrichResolution, IndexResolver.INDEX_METADATA_FIELD, wildcardJoinIndices, false);
239239
} else {
240240
fieldNames.addAll(subfields(fieldNames));
241241
fieldNames.addAll(enrichPolicyMatchFields);
242242
fieldNames.addAll(subfields(enrichPolicyMatchFields));
243-
return new PreAnalysisResult(enrichResolution, fieldNames, wildcardJoinIndices);
243+
return new PreAnalysisResult(enrichResolution, fieldNames, wildcardJoinIndices, false);
244244
}
245245
}
246246

0 commit comments

Comments
 (0)