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

ExprPlanner not propagated to SqlToRel #11477

Closed
wjones127 opened this issue Jul 15, 2024 · 7 comments · Fixed by #11485
Closed

ExprPlanner not propagated to SqlToRel #11477

wjones127 opened this issue Jul 15, 2024 · 7 comments · Fixed by #11485
Labels
bug Something isn't working

Comments

@wjones127
Copy link
Member

wjones127 commented Jul 15, 2024

Describe the bug

When upgrading to DataFusion 40, I kept on encountering this error:

Internal error: Expected a simplified result, but none was found.

This happened when parsing a array literal. It seems in order to parse it, we need to register the proper ExprPlanner on the SessionState. We use SessionState::default(), which registers it for us. But then it's not being propagated to SqlToRel, so it fails. (Note the planners: vec![])

pub fn new_with_options(context_provider: &'a S, options: ParserOptions) -> Self {
let normalize = options.enable_ident_normalization;
SqlToRel {
context_provider,
options,
normalizer: IdentNormalizer::new(normalize),
planners: vec![],

To Reproduce

No response

Expected behavior

I'm not sure I understand the design, but it seems odd we don't propagate these. At the very least, we should provide a warning in the docs.

Additional context

Current workaround:

for planner in context_provider.state.expr_planners() {
    sql_to_rel = sql_to_rel.with_user_defined_planner(planner.clone());
}
@wjones127 wjones127 added the bug Something isn't working label Jul 15, 2024
@wjones127
Copy link
Member Author

@jayzhan211 could you confirm what the intended behavior is for this?

@jayzhan211
Copy link
Contributor

We assume planner should exist, at least with datafusion's builtin one, otherwise we don't know how to handle it thus throws error for the case.

@jayzhan211
Copy link
Contributor

After #11403, I think you can easily get the default planners with

SessionStateBuilder::new()
            .with_default_features()
            .build()

@wjones127
Copy link
Member Author

We assume planner should exist, at least with datafusion's builtin one, otherwise we don't know how to handle it thus throws error for the case.

I'm not sure I understand your answer. When we call SessionState::default(), all the correct planners are registered. For example, it already has the ArrayFunctionPlanner it should need to parse array literals.

What I'm confused by is that I have to do this additional step to propagate it to SqlToRel:

let session_state: SessionState = ...;
let mut sql_to_rel = SqlToRel::new(...);
for planner in session_state.expr_planners() {
    sql_to_rel = sql_to_rel.with_user_defined_planner(planner.clone());
}

Why do I have to do that? Why doesn't SqlToRel copy the expression planners from the ContextProvider that was passed in?

@jayzhan211

This comment was marked as outdated.

@jayzhan211
Copy link
Contributor

I see. Let me see if it is possible to avoid the additional copied

@alamb
Copy link
Contributor

alamb commented Jul 16, 2024

Cross referencing -- a related discussion on #11180 #11180 (comment)

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants