Skip to content

Fix Infer prepare statement type tests #15743

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

brayanjuls
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

This intent to correct issues on the prepare statements infer type tests. Currently they are not correctly asserting the expected behavior specially when we try to validate types.

What changes are included in this PR?

  • Restore the original naming.
  • Include the "PREPARE" statement clause without type.
  • Update insta snapshots.
  • Pending: Get the inferred types part of the plan.

Are these changes tested?

Yes

Are there any user-facing changes?

No

@brayanjuls brayanjuls marked this pull request as draft April 17, 2025 03:06
@github-actions github-actions bot added the sql SQL Planner label Apr 17, 2025
Projection: person.id, person.age
Filter: person.age BETWEEN $1 AND $2
TableScan: person
Prepare: "my_plan" []
Copy link
Contributor Author

@brayanjuls brayanjuls Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently when the logical plan is created it does not include the type inferred, this result in some issues when we try to call the function plan.with_param_values(param_values) as it tries to extract the type from the plan but it is empty. Are we expecting the plan to contain the type at this time? if so probably there is another bug we need to investigate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb @qstommyshu any advice on where to look to debug why the plan is not properly generating the inferred type?

Copy link
Contributor

@qstommyshu qstommyshu Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @brayanjuls ,

the reason why this happen is there is no parameters being passed to the sql, but the sql itself contains positional arguments like $1 and $2, please refer to https://datafusion.apache.org/user-guide/sql/prepared_statements.html#inferred-types.

The simple way you can fix it is by adding the position arguments type to the sql like how it was done in test_prepare_statement_to_plan_one_param. If you want to dig into the details about it, you can check how planner parse PREPARE statement and transfer it into a logical plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but wouldn't that mean the type is not being inferred, but instead we are explicitly declaring it?

Thanks, I would check the planner parser.

Copy link
Contributor

@qstommyshu qstommyshu Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't check the details for parsing "PREPARE" statement yet, but I think the type inference behaviour depends on how the planner parser is implemented, it could be either way.

@brayanjuls brayanjuls marked this pull request as ready for review May 2, 2025 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix PREPARE statement tests
2 participants