alamb commented on issue #1468:
URL: https://github.com/apache/datafusion/issues/1468#issuecomment-2308275476

   > I run into this recently. When constructing VALUES via API, the Alias 
expression can be thought to allow aliasing the VALUES columns, but this didn't 
work, alias got (silently) ignored. From such "unpleasant surprise" 
perspective, I would consider this as a bug.
   
   I agree it sounds like a bug to me
   
   > 
   > To me, alias is not an expression at all. It's a feature of a select 
clause and would be best modeled as such.
   
   Theoretically I think this makes sense
   
   One thing that is different about DataFusion than other systems is that the 
schemas are based on name (rather than column order) and the names of the 
columns are derived from the expressions
   
   So the point is that an expression like `a + 5 + 1` will result in a column 
named approximately `"a + 5 + 1"` -- so when the optimizer passes rewrite 
expressions they need to preserve the output name, and they do so using 
`Expr::Alias`
   
   So in this case
   
   ```sql
   a + 5 + 1
   ```
   
   Becomes
   ```sql
   a + 6 as "a + 5 + 1"
   ```
   
   That rewrite can happen in multiple parts of the plan, not just the select 
list
   
   There are likely other ways to handle this than `Expr::Alias` (a separate 
list on `Projection`, for example) but I do think alias is used widely
   
   > > There are other Expr variants that only make sense in certain contexts 
as well. We can't have an Expr::Sort in a projection, for example.
   > 
   > That's a good point and good example. To me, in `ORDER BY <expr> 
[ASC/DESC] [NULLS FIRST/LAST]`, the `<expr>` part is an expression (any 
expression), and the other attributes (asc/desc, nulls first/last) are 
attributes of the sorting. They don't have to be modeled as "an expression".
   
   I think Sort would be an easier thing to remove / fix -- `Expr::Sort` as an 
expression is also bad as it means the signatures of `fn order_by(...)` are in 
terms of `Expr`, meaning the compiler can't ensure you are actually passing 
`Expr::Sort` when needed


-- 
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