spark-test commented on code in PR #60719:
URL: https://github.com/apache/spark/pull/60719#discussion_r4636378439


##########
sql/core/src/test/resources/sql-tests/inputs/subquery/scalar-subquery/scalar-subquery-select.sql:
##########
@@ -343,3 +343,39 @@ SELECT (SELECT t1.* FROM (SELECT 3 AS col1) AS t1 LIMIT 1) 
FROM VALUES(1) AS t1(
 
 -- Outer star expansion through a derived table wrapper
 SELECT (SELECT * FROM (SELECT t1.* FROM VALUES(2) AS t2(col1) LIMIT 1)) FROM 
VALUES(1) AS t1(col1);
+
+-- Functions rewritten into an expression that references an argument more 
than once (nullif,
+-- between, decode) over scalar subqueries, aggregates, windows and lambdas.
+set spark.sql.alwaysInlineCommonExpr=true;
+
+-- expected 3
+select nullif((select max(id) from range(1, 4)), 0);

Review Comment:
   **Nit (P3):** This subquery reads from `range(1, 4)`, which parses to an 
`UnresolvedTableValuedFunction`. The single-pass resolver's guard has no case 
for that node (`ResolverGuard.scala:163-164`), so `HybridAnalyzer` resolves the 
query with the fixed-point analyzer alone, and the dual run that tests enable 
by default never checks the single-pass resolver on it. The `decode` case at 
line 355 and the control at line 377 are the same, so `decode` gets no 
single-pass coverage at all and `nullif` over an uncorrelated subquery gets 
none with `spark.sql.alwaysInlineCommonExpr` on or off, although both are 
`InheritAnalysisRules` replacements whose duplicated argument goes through the 
second resolution that SPARK-62083 describes 
(`FunctionResolver.scala:181-186`). A later single-pass change on that path, 
whether a fix or a regression, would pass these golden files unnoticed.
   
   Reading the subquery from an inline table, as the correlated cases already 
do, for example `select nullif((select max(c) from values (1), (2), (3) as 
t(c)), 0);`, would put all three cases under the dual run and keep their 
recorded values 3, three and 3; both golden files then need regenerating.
   
   The window and `transform` cases skip the dual run too, but there the guard 
rejects the expressions they test, so no fixture change helps; the dual run 
will cover them as they are once the guard accepts those expressions.
   
   **Verification:**
   - **Regression:** For each rewritten query without a dual-run opt-out, 
confirm that the single-pass resolver's guard admits it, whereas it rejects the 
range(1, 4) version as an unsupported UnresolvedTableValuedFunction, and that 
the single-pass resolver resolves it, for example with the checkResolverGuard 
helper in ResolverGuardSuite.scala under the spark.sql.alwaysInlineCommonExpr 
value the case runs with.
   - **Behavior:** Regenerate and rerun the scalar-subquery SELECT golden tests 
and confirm that the three rewritten cases still return their commented values, 
3, three and 3, in the execution golden output and in its Thrift server replay, 
that neither golden file records a HYBRID_ANALYZER_EXCEPTION error for a case 
without a dual-run opt-out, and that the analyzer golden output lists their 
subquery plan over the inline table twice for the cases run with 
spark.sql.alwaysInlineCommonExpr set to true and once for the case run with it 
set to false.
   - **Inspection:** If a rewritten case needed a dual-run opt-out, check that 
the set of spark.sql.analyzer.singlePassResolver.dualRunWithLegacy to false 
applies to that case alone, is reset right after it, and sits under a comment 
naming SPARK-62083.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to