Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support UNNEST as table function (UDTF) #14801

Open
waynexia opened this issue Feb 21, 2025 · 2 comments
Open

Support UNNEST as table function (UDTF) #14801

waynexia opened this issue Feb 21, 2025 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@waynexia
Copy link
Member

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

@waynexia waynexia added the enhancement New feature or request label Feb 21, 2025
@jonahgao
Copy link
Member

That's a great proposal; I plan to try it.

@jonahgao jonahgao self-assigned this Feb 21, 2025
@waynexia
Copy link
Member Author

Thank you @jonahgao 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants