Skip to content

Compute ScalarFunction's return_field on creation #20290

Closed as duplicate
Closed as duplicate

Description

@Trikooo

Is your feature request related to a problem or challenge?

Related to #20012

Currently, the return field of ScalarFunctions is being computed three times during the query's lifecycle, during which the query's expression might change.
for example when a udf needs to implicitly cast a literal, it wraps that literal in a cast and recomputes the return field again after initial computation without the cast, leading to inconsistent results.

Describe the solution you'd like

Calculate the return_type during creation.

#[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)]
pub struct ScalarFunction {
    /// The function
    pub func: Arc<crate::ScalarUDF>,
    /// List of expressions to feed to the functions as arguments
    pub args: Vec<Expr>,

    /// Return field of the function
    return_field: FieldRef, 
}

Not sure if a new constructor ScalarFunction::new_udf_with_return_field should be created or change the original ScalarFunction::new_udf

Describe alternatives you've considered

No response

Additional context

#13825 proposed a similar approach.

Activity

  1. added theissue type on Feb 11, 2026
  2. Trikooo commented on Feb 11, 2026

    @Trikooo
    Author

    take

  3. Trikooo commented on Feb 12, 2026

    @Trikooo
    Author

    Right, I didn't thoroughly read that they suggested the return Field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions