Class PushExpressionsToFieldLoad


public class PushExpressionsToFieldLoad extends ParameterizedRule<PhysicalPlan,PhysicalPlan,LocalPhysicalOptimizerContext>
Replaces Expressions that can be pushed to field loading with a field attribute that calculates the expression during value loading. See BlockLoaderExpression for more about how these loads are implemented and why we do this.

This rule runs in one downward (aka output-to-read) pass, making three sorts of transformations:

  • When we see a use of a new pushable function we build an attribute for the function, record that attribute, and discard it after use. For example, EVAL l = LENGTH(message) becomes EVAL l = $$message$LENGTH$1324$$ | DROP $$message$LENGTH$1324$$ . We need the DROP so we don't change the output schema.
  • When we see a use of pushable function for which we already have an attribute we just use it. This looks like the l attribute in EVAL l = LENGTH(message) | EVAL l2 = LENGTH(message)
  • When we see a PROJECT, add any new attributes to the projection so we can use them on previously visited nodes. So KEEP foo | EVAL l = LENGTH(message) becomes
    
               | KEEP foo, $$message$LENGTH$1324$$
               | EVAL l = $$message$LENGTH$1324$$
               | DROP $$message$LENGTH$1324$$
             

The actual loading of pushed attributes is handled by InsertFieldExtraction, which runs after this rule. It sees the new FieldAttribute references (backed by FunctionEsField) and inserts FieldExtractExec nodes that create the appropriate block loaders.