pepijnve commented on issue #27631:
URL: https://github.com/apache/datafusion/issues/27631#issuecomment-7077943386

   I fed all my notes and confusion into Claude and got back what I think is a 
useful analysis. At least it helps me better understand things. Does this 
analysis sound right?
   
   **Claude**
   
   I'd rename the enum to describe where an expression's value comes from, not 
where it should go. The names should then stop implying cost, as "keep in 
place" and "move towards leaf nodes" do today.
   
   ```  
┌─────────────────────────┬──────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
     │          Today          │     Proposed     │                             
                    Meaning                                                  │
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ ExpressionPlacement     │ ExprProvenance   │ Where the value comes from, 
in terms the optimizer can act on. Says nothing about cost.                  │
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ Literal                 │ Constant         │ Known at planning time, the 
same for every row.                                                          │
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ Column                  │ InputColumn      │ A plain reference to a 
column of the node's input, possibly aliased. Moving or copying it costs 
nothing. │
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ MoveTowardsLeafNodes    │ SourceProvidable │ The data source can produce 
this value as if it were a column, e.g. a struct field or file metadata.     │
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ KeepInPlace             │ Computed         │ The engine has to evaluate 
this. It's the default and makes no claim about cost or placement.            │
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ should_push_to_leaves() │ is_column_like() │ True for InputColumn and 
SourceProvidable, the two kinds every merge guard treats as free to copy.       
│
     
├─────────────────────────┼──────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────┤
     │ placement()             │ provenance()     │ Same change on Expr, 
PhysicalExpr and ScalarUDFImpl.                                                 
    │
     
└─────────────────────────┴──────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
   ```
   
   Why these names
   
     - Constant, not Literal: consumers mean "a value known at planning time." 
get_field needs constant keys, and the alias case already looks through to the
       inner expression. Literal names one particular syntax; this is about 
behaviour.
     - InputColumn, not Column: #25329 happened because __common_expr_1 is a 
column too, but it's bound to an expensive UDF. The name should make clear the 
claim
       is only "this refers to an input column," not "this is cheap base-table 
data."
     - SourceProvidable, not MoveTowardsLeafNodes:
       - It states the actual claim and covers both kinds of in-tree user: 
get_field on a column, and input_file_name/file_row_index, which must be 
produced by
         the source.
       - The optimizer's handling (extract it, push it towards the scan, don't 
deduplicate it, don't inline it into pushed filters) follows from the claim, so 
it
         belongs in the docs, not the name.
       - Alternatives: VirtualColumn (the industry term for file metadata, but 
awkward for struct fields) or SourceColumn (shorter, but easily confused with
         InputColumn).
     - Computed, not KeepInPlace: this is the change that matters most. Today's 
name and docs ("an expensive expression") are why #25388, #25456 and #27631 all
       ended up reading it as a cost tier. Computed says only that the engine 
has to evaluate it.
       - Opaque is a reasonable alternative if you want to stress "the 
optimizer knows nothing more."
       - Either way, the docs should say outright that a + 1 and CAST(c) fall 
here, and that duplication cost is a separate question.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to