You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "viirya (via GitHub)" <gi...@apache.org> on 2024/06/04 00:34:29 UTC

[I] Circular relationship when determining state fields for AggregateUDF [datafusion]

viirya opened a new issue, #10785:
URL: https://github.com/apache/datafusion/issues/10785

   ### Is your feature request related to a problem or challenge?
   
   I'm trying to update Comet to latest DataFusion: https://github.com/apache/datafusion-comet/pull/403. One issue I found is about AggregateUDF.
   
   For some aggregate expressions, their implementation moves to `AggregateUDF`, e.g., `FirstValue` and `LastValue`.
   
   To create a `AggregateFunctionExpr` for them, we need to call `create_aggregate_expr` by providing some arguments like `input_phy_exprs`. `input_phy_exprs` is used to determine the UDF's return return type (i.e., `AggregateUDF.return_type`).
   
   To get the input physical expressions for each aggregate expression, we need to get slice of all input expressions which is the state fields of the aggregate expression. But the current design of `AggregateUDF` doesn't provide its state fields, but it relies on `AggregateFunctionExpr` to call `AggregateUDF.state_fields` with `StateFieldsArgs`.
   
   So it is a circular relationship for someone to create a `AggregateFunctionExpr` for a `AggregateUDF`:
   
   1. Create a `AggregateUDF`
   2. Call `create_aggregate_expr` to create `AggregateFunctionExpr`, by providing `input_phy_exprs`
   3. In order to get `input_phy_exprs`, we need to know how to slice input expressions, i.e., how many state fields for the UDF. Call `AggregateUDF.state_fields`. `AggregateUDF.state_fields` requires `StateFieldsArgs` from `AggregateFunctionExpr`, so we need to create `AggregateFunctionExpr` first (step 2).
   
   I think this is an issue in the current design. `AggregateUDF` should determine its state fields by itself instead relying on `AggregateFunctionExpr` which is a wrapper of it.
   
   
   
   
   
   
   
   
   
   
   
   ### Describe the solution you'd like
   
   _No response_
   
   ### Describe alternatives you've considered
   
   _No response_
   
   ### Additional context
   
   _No response_


-- 
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: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Circular relationship when determining state fields for AggregateUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #10785:
URL: https://github.com/apache/datafusion/issues/10785#issuecomment-2153393932

   I am hoping this will get easier once we remove the built in aggregates (which are confusingly called `AggregateFunction` in several places


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Circular relationship when determining state fields for AggregateUDF [datafusion]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on issue #10785:
URL: https://github.com/apache/datafusion/issues/10785#issuecomment-2148099529

   I'm trying to fix this in Scala code. If it works, we don't need to change DataFusion.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Circular relationship when determining state fields for AggregateUDF [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #10785:
URL: https://github.com/apache/datafusion/issues/10785#issuecomment-2148200482

   FYI @jayzhan211  who I think was working on similar issues / untangling


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Circular relationship when determining state fields for AggregateUDF [datafusion]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya closed issue #10785: Circular relationship when determining state fields for AggregateUDF
URL: https://github.com/apache/datafusion/issues/10785


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Circular relationship when determining state fields for AggregateUDF [datafusion]

Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on issue #10785:
URL: https://github.com/apache/datafusion/issues/10785#issuecomment-2148799000

   `StateFieldsArgs ` can be constructed without AggregateFuncitonExpr.
   
   This is how we calculate state fields.
   ```
   fn state_fields(&self) -> Result<Vec<Field>> {
           let args = StateFieldsArgs {
               name: &self.name,
               input_type: &self.input_type,
               return_type: &self.data_type,
               ordering_fields: &self.ordering_fields,
               is_distinct: self.is_distinct,
           };
   
           self.fun.state_fields(args)
       }
   ```
   
   You can see `create_aggregate_expr` to know how these arguments are built.
   If the functions does not event need `ordering_fields`,  you can even set ordering_fields to `&[]`


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Circular relationship when determining state fields for AggregateUDF [datafusion]

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on issue #10785:
URL: https://github.com/apache/datafusion/issues/10785#issuecomment-2150394280

   I resolved this in Comet so don't need to change DataFusion now.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org