Skip to content

Support UNNEST as table function (UDTF) #14801

@waynexia

Description

@waynexia

Is your feature request related to a problem or challenge?

UNNEST is implemented in two ways, SELECT UNNEST(...) is handled with other functions

// Build Unnest expression
if name.eq("unnest") {
let mut exprs = self.function_args_to_expr(args, schema, planner_context)?;
if exprs.len() != 1 {
return plan_err!("unnest() requires exactly one argument");
}
let expr = exprs.swap_remove(0);
Self::check_unnest_arg(&expr, schema)?;
return Ok(Expr::Unnest(Unnest::new(expr)));
}

And SELECT ... FROM UNNEST(...) is provided as TableFactory

TableFactor::UNNEST {
alias,
array_exprs,
with_offset: false,
with_offset_alias: None,
with_ordinality,
} => {

But those two ways are both non-generic, cases like substrait can't handle it properly, as the decoder will try to look for table function:

async fn roundtrip_unnest() -> Result<()> {
    roundtrip("SELECT * FROM unnest([1, 2, 3])").await
}

Describe the solution you'd like

Implement UNNEST as a table function, making it more general and reduce the complexity (and branches) of implementation

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions