Class SpatialDocValuesExtraction
java.lang.Object
org.elasticsearch.xpack.esql.rule.Rule<AggregateExec,PhysicalPlan>
org.elasticsearch.xpack.esql.rule.ParameterizedRule<AggregateExec,PhysicalPlan,LocalPhysicalOptimizerContext>
org.elasticsearch.xpack.esql.optimizer.PhysicalOptimizerRules.ParameterizedOptimizerRule<AggregateExec,LocalPhysicalOptimizerContext>
org.elasticsearch.xpack.esql.optimizer.rules.physical.local.SpatialDocValuesExtraction
public class SpatialDocValuesExtraction
extends PhysicalOptimizerRules.ParameterizedOptimizerRule<AggregateExec,LocalPhysicalOptimizerContext>
This rule is responsible for marking spatial fields to be extracted from doc-values instead of source values.
This is a very specific optimization that is only used in the context of spatial aggregations.
Normally spatial fields are extracted from source values because this maintains original precision, but is very slow.
Simply loading from doc-values loses precision for points, and loses the geometry topological information for shapes.
For this reason we only consider loading from doc values under very specific conditions:
- The spatial data is consumed by a spatial aggregation (eg.
ST_CENTROIDS_AGG, negating the need for precision. - This aggregation is planned to run on the data node, so the doc-values Blocks are never transmit to the coordinator node.
- The data node index in question has doc-values stored for the field in question.
- The spatial aggregation function itself is marked using
withDocValues()to enable itstoEvaluator()method to produce the correct doc-values awareEvaluatorfunctions. - Any spatial functions called within
EVALcommands before the doc-values are consumed by the aggregation also need to be marked usingwithDocValues()so their evaluators are correct. - Any spatial functions used within filters,
WHEREcommands, are similarly marked for the same reason. - The
FieldExtractExecthat will extract the field is marked withwithDocValuesAttributes(...)so that it calls theFieldType.blockReader()method with the correctFieldExtractPreference
toEvaluator() instance method that is used to generates Block traversal code to call these runtime
implementations, based on some internal state of the instance of the function. In most cases this internal state contains information
determined during the logical planning phase, such as the field name and type, and whether it is a literal and can be folded.
In the case of spatial functions, the internal state also contains information about whether the function is using doc-values or not.
This knowledge is determined in the class being described here, and is only determined during local physical planning on each data
node. This is because the decision to use doc-values is based on the local data node's index configuration, and the local physical plan
is the only place where this information is available. This also means that the knowledge of the usage of doc-values does not need
to be serialized between nodes, and is only used locally.-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected PhysicalPlanrule(AggregateExec aggregate, LocalPhysicalOptimizerContext ctx) Methods inherited from class org.elasticsearch.xpack.esql.optimizer.PhysicalOptimizerRules.ParameterizedOptimizerRule
applyMethods inherited from class org.elasticsearch.xpack.esql.rule.ParameterizedRule
apply
-
Constructor Details
-
SpatialDocValuesExtraction
public SpatialDocValuesExtraction()
-
-
Method Details
-
rule
- Specified by:
rulein classPhysicalOptimizerRules.ParameterizedOptimizerRule<AggregateExec,LocalPhysicalOptimizerContext>
-