Skip to content

Avoid breaking changes for table function args #22952

@lewiszlw

Description

@lewiszlw

Describe the bug

We encountered several breaking changes for table function arguments. These changes break user-facing SQL.

We have some table functions like tbf(a='x', b='x').

Last time someone added a simplifier to simplify argument expressions. This time someone added a change to coerce argument expressions #19915 (Our table functions will throw error during coercing). These changes break our table functions and we have to change our table function synatx and break our user-facing sql.

fn get_table_function_source(
&self,
name: &str,
args: Vec<Expr>,
) -> datafusion_common::Result<Arc<dyn TableSource>> {
use datafusion_catalog::TableFunctionArgs;
let tbl_func = self
.state
.table_functions
.get(name)
.cloned()
.ok_or_else(|| plan_datafusion_err!("table function '{name}' not found"))?;
let simplify_context = SimplifyContext::builder()
.with_config_options(Arc::clone(self.state.config_options()))
.with_query_execution_start_time(
self.state.execution_props().query_execution_start_time,
)
.build();
let simplifier = ExprSimplifier::new(simplify_context);
let schema = DFSchema::empty();
let args = args
.into_iter()
.map(|arg| {
simplifier
.coerce(arg, &schema)
.and_then(|e| simplifier.simplify(e))
})
.collect::<datafusion_common::Result<Vec<_>>>()?;
let provider = tbl_func
.create_table_provider_with_args(TableFunctionArgs::new(&args, self.state))?;
Ok(provider_as_source(provider))
}

It seems these changes could be moved into the table function implementation or a method of TableFunctionArgs::simplified_args(). We could pass the original argument expressions into the TableFunctionImpl::call() method and let users to choose whether to simplify args.

To Reproduce

No response

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions