Skip to content

Fix: Infer placeholder type from subquery#22436

Merged
adriangb merged 2 commits into
apache:mainfrom
HairstonE:fix/15979-placeholder-in-subquery
May 21, 2026
Merged

Fix: Infer placeholder type from subquery#22436
adriangb merged 2 commits into
apache:mainfrom
HairstonE:fix/15979-placeholder-in-subquery

Conversation

@HairstonE
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #15979.

Rationale for this change

$1 IN (SELECT ...) left the placeholder untyped because infer_placeholder_types had no arm for InSubquery and made get_parameter_types() return None for these placeholders.

What changes are included in this PR?

Adds the InSubquery arm to infer_placeholder_types, reading the type from the subquery's projected column. Covers both IN and NOT IN.

How are these changes tested?

Unit tests for IN and NOT IN placeholder inference, plus end-to-end sqllogictests with PREPARE/EXECUTE.

Are there any user-facing changes?

No.

@github-actions github-actions Bot added logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels May 21, 2026
Comment thread datafusion/expr/src/expr.rs Outdated
}) => {
let subquery_schema = subquery.subquery.schema();
let column = Expr::Column(Column::new_unqualified(
subquery_schema.fields()[0].name().clone(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should we verify the contract of len = 1 here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I can add that check. Would we want to throw an error if the length was not 1 or just have it do nothing?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

an error would be better than a panic, certainly

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since you’ll address it i removed from the queue, let me know once you’ve swapped for an error and i’ll add it back

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added a match to ensure the length is 1 or return an error.

Copy link
Copy Markdown
Contributor

@neilconway neilconway left a comment

Choose a reason for hiding this comment

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

Looks good overall! Thanks for working on this.

Can we handle SetComparison (ANY/ALL) while we're at it?

Personally I find the unit tests a little unnecesary if we have SLT, but I guess having both matches the convention here.

Copy link
Copy Markdown
Contributor

@adriangb adriangb left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good!

I would personally prefer to open a tracking issue for ANY/ALL and tackle it in another PR. The well defined boundaries of this PR make it easy to review (and revert if there are issues down the road).

Comment thread datafusion/sqllogictest/test_files/prepare.slt
@adriangb adriangb added this pull request to the merge queue May 21, 2026
@adriangb adriangb removed this pull request from the merge queue due to a manual request May 21, 2026
@adriangb adriangb enabled auto-merge May 21, 2026 21:42
@adriangb adriangb added this pull request to the merge queue May 21, 2026
Merged via the queue into apache:main with commit 3d45e42 May 21, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Placeholder datatype not inferred for Expr::InSubquery

3 participants