test(ppl): remove invalid Spark SQL assertions from correlated-aggregate subquery tests#5594
Open
gingeekrishna wants to merge 1 commit into
Conversation
…ate subquery tests (opensearch-project#5470) The verifyPPLToSparkSQL assertions in testCorrelatedScalarSubqueryInWhere and testCorrelatedScalarSubqueryInSelect pin SQL that Spark (4.1) refuses to execute: SALGRADE has no SAL or EMPNO column, so those references bind to the outer EMP table as correlated outer references. The SQL serializer emits AVG(`EMP`.`SAL`) and MIN(`EMP`.`EMPNO`) inside subquery aggregate functions. Spark rejects this with UNSUPPORTED_SUBQUERY_EXPRESSION_CATEGORY.CORRELATED_REFERENCE because outer-column references in aggregate functions are not supported outside WHERE/HAVING clauses. Changes: * testCorrelatedScalarSubqueryInWhere: remove verifyPPLToSparkSQL; keep verifyLogical (the logical plan correctly models the correlated semantics per SQL-92 scoping rules) * testCorrelatedScalarSubqueryInSelect: same — remove verifyPPLToSparkSQL; keep verifyLogical * Remove testCorrelatedScalarSubqueryInWhereMaxOut: exact duplicate of testCorrelatedScalarSubqueryInWhere (same PPL, same expected logical, same invalid SQL) The disjunctive tests (testDisjunctiveCorrelatedScalarSubqueryInWhere*) are unaffected: their COUNT() aggregate does not reference outer columns, so the generated Spark SQL is valid. Fixes opensearch-project#5470 Signed-off-by: Radhakrishnan Pachyappan <gingeekrishna@gmail.com>
Contributor
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5470.
The
verifyPPLToSparkSQLassertions intestCorrelatedScalarSubqueryInWhereandtestCorrelatedScalarSubqueryInSelectpin SQL that Spark 4.1 rejects.SALGRADEhas noSALorEMPNOcolumn, so those names bind to the outerEMPtable as correlated outer references per SQL-92 scoping rules. The SQL serializer correctly emitsAVG(EMP.SAL)andMIN(EMP.EMPNO)inside the subquery aggregates — but Spark refuses to execute them:The logical plans (verified by
verifyLogical) are correct and match the correlated semantics. Only theverifyPPLToSparkSQLcall is misleading —verifyPPLToSparkSQLonly compares the serialized SQL string; it never executes against a real Spark engine, so the test passed while pinning invalid SQL.Changes:
testCorrelatedScalarSubqueryInWhere: removeverifyPPLToSparkSQL; keepverifyLogical; add comment explaining the omissiontestCorrelatedScalarSubqueryInSelect: same treatment — same root cause (MIN(EMP.EMPNO)in aggregate)testCorrelatedScalarSubqueryInWhereMaxOut: it is an exact duplicate oftestCorrelatedScalarSubqueryInWhere(same PPL, same expected logical plan, same invalid expected SQL)Tests not touched: The disjunctive tests (
testDisjunctiveCorrelatedScalarSubqueryInWhere*) useCOUNT()which does not reference any outer column; their correlated reference lives only in theWHEREclause of the subquery. Spark supports correlatedWHERE-clause references, so thoseverifyPPLToSparkSQLassertions remain valid and are untouched.Test plan
./gradlew :ppl:test --tests "*CalcitePPLScalarSubqueryTest*"—BUILD SUCCESSFUL; all remaining tests pass./gradlew spotlessApply— no formatting violations