Skip to content

Compute ScalarFunction's return_field on creation #20290

@Trikooo

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.

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