You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "HairstonE (via GitHub)" <gi...@apache.org> on 2026/05/26 19:43:24 UTC

[PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

HairstonE opened a new pull request, #22545:
URL: https://github.com/apache/datafusion/pull/22545

   ## Which issue does this PR close?
   
   Closes #22475.
   
   ## Rationale for this change
   
   `$1 = ANY (SELECT ...)` and `$1 <> ALL (SELECT ...)` left the placeholder untyped because `infer_placeholder_types` had no arm for `SetComparison`.
   
   ## What changes are included in this PR?
   
   Adds the `SetComparison` arm to `infer_placeholder_types`, reading the type from the subquery's projected column. Covers all quantifiers (`ANY`, `ALL`) and comparison operators.
   
   ## How are these changes tested?
   
   Unit tests for `ANY` and `ALL` placeholder inference, plus end-to-end sqllogictests with `PREPARE`/`EXECUTE`.
   
   ## Are there any user-facing changes?
   
   No.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #22545:
URL: https://github.com/apache/datafusion/pull/22545


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#discussion_r3331527378


##########
datafusion/expr/src/expr.rs:
##########
@@ -3945,6 +3972,112 @@ mod test {
         }
     }
 
+    #[test]

Review Comment:
   > The slt tests would fail because of https://github.com/apache/datafusion/issues/22477 
   
   Would it be possible to work on #22477 first?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "HairstonE (via GitHub)" <gi...@apache.org>.
HairstonE commented on PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#issuecomment-4549540032

   @Omega359 Thanks for the review. I ran into the same Schema Error on main when looking into this. The slt tests would fail because of #22477 , so I stuck with unit tests to verify the implementation. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on code in PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#discussion_r3331520112


##########
datafusion/expr/src/expr.rs:
##########
@@ -3945,6 +3972,112 @@ mod test {
         }
     }
 
+    #[test]

Review Comment:
   This regression is visible through SQL (`PREPARE ... WHERE $1 = ANY/<> ALL (SELECT ...)`), but the added coverage is currently limited to direct `Expr::infer_placeholder_types` unit tests.
   
   That verifies the expression-level behavior, but it doesn't confirm that the parser/planner prepared-statement path actually constructs `SetComparison`, runs placeholder inference, and executes correctly with a bound value.
   
   Could we add end-to-end sqllogictest coverage in `datafusion/sqllogictest/test_files/prepare.slt`, near the existing `$1 IN (SELECT age FROM person)` cases, for both `$1 = ANY (SELECT age FROM person)` and `$1 <> ALL (SELECT age FROM person)`?



##########
datafusion/expr/src/expr.rs:
##########
@@ -2212,6 +2212,33 @@ impl Expr {
                           }
                       }
                 }
+                Expr::SetComparison(SetComparison {

Review Comment:
   `InSubquery` and `SetComparison` now contain very similar logic for rewriting placeholders based on a single-column subquery schema.
   
   As a follow-up, it might be worth extracting a small helper such as `rewrite_placeholder_from_subquery_expr(kind, expr, subquery)?` so the one-column invariant and associated error formatting stay centralized.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "HairstonE (via GitHub)" <gi...@apache.org>.
HairstonE commented on code in PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#discussion_r3560982746


##########
datafusion/expr/src/expr.rs:
##########
@@ -3945,6 +3972,112 @@ mod test {
         }
     }
 
+    #[test]

Review Comment:
   That issue is cleared up now. I've also added slt coverage.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "HairstonE (via GitHub)" <gi...@apache.org>.
HairstonE commented on code in PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#discussion_r3560986836


##########
datafusion/expr/src/expr.rs:
##########
@@ -2212,6 +2212,33 @@ impl Expr {
                           }
                       }
                 }
+                Expr::SetComparison(SetComparison {

Review Comment:
   Good call! I've extracted the similar logic now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#issuecomment-4549218901

   I do not see any slt tests as part of this pr? I had codex write some and they seem to fail on the branch with "Schema error: Schema contains duplicate unqualified field name mark" in optimize_projections.
   
   ```
   # Allow prepare $1 = ANY (subquery)
   statement ok
   PREPARE my_plan AS SELECT id FROM person WHERE $1 = ANY (SELECT age FROM person);
   
   query I rowsort
   EXECUTE my_plan(20);
   ----
   1
   
   query I rowsort
   EXECUTE my_plan(99);
   ----
   
   statement ok
   DEALLOCATE my_plan
   
   # Allow prepare $1 <> ALL (subquery)
   statement ok
   PREPARE my_plan AS SELECT id FROM person WHERE $1 <> ALL (SELECT age FROM person);
   
   query I rowsort
   EXECUTE my_plan(99);
   ----
   1
   
   query I rowsort
   EXECUTE my_plan(20);
   ----
   
   statement ok
   DEALLOCATE my_plan
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "HairstonE (via GitHub)" <gi...@apache.org>.
HairstonE commented on PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#issuecomment-4595269378

   @kosiew Hi, thank you for the review! I think it makes the most sense to tackle #22477 before this. I'll try my hand at that issue then come back to this and work in your suggestions. I will draft this for now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Infer placeholder type from ANY/ALL subquery, unit tests [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #22545:
URL: https://github.com/apache/datafusion/pull/22545#issuecomment-4981193489

   Thanks @HairstonE and @kosiew 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org