cloud-fan commented on code in PR #52334:
URL: https://github.com/apache/spark/pull/52334#discussion_r2436034193
##########
sql/core/src/main/scala/org/apache/spark/sql/classic/SparkSession.scala:
##########
@@ -488,15 +573,36 @@ class SparkSession private(
args: Map[String, Any],
tracker: QueryPlanningTracker): DataFrame =
withActive {
- val plan = tracker.measurePhase(QueryPlanningTracker.PARSING) {
- val parsedPlan = sessionState.sqlParser.parsePlan(sqlText)
- if (args.nonEmpty) {
- NameParameterizedQuery(parsedPlan, args.transform((_, v) =>
lit(v).expr))
- } else {
- parsedPlan
+ // Always set parameter context if we have actual parameters
+ if (args.nonEmpty) {
+ // Resolve and validate parameters first
+ val resolvedParams = resolveAndValidateParameters(args.transform((_,
v) => lit(v).expr))
+ val paramContext = NamedParameterContext(resolvedParams)
+ val plan = tracker.measurePhase(QueryPlanningTracker.PARSING) {
+ val parsedPlan =
sessionState.sqlParser.parsePlanWithParameters(sqlText, paramContext)
+ // In legacy mode, wrap the parsed plan with NameParameterizedQuery
+ // so that the BindParameters analyzer rule can bind the parameters
+ if (sessionState.conf.legacyParameterSubstitutionConstantsOnly) {
+ NameParameterizedQuery(parsedPlan, paramContext.params)
+ } else {
+ parsedPlan
+ }
+ }
+
+ Dataset.ofRows(self, plan, tracker)
+ } else {
+ // Reset position mapper to prevent contamination from previous
parameterized sql() calls
Review Comment:
I think this is no longer needed, as we reset it right after the parsing:
https://github.com/apache/spark/pull/52334/files#diff-77a9aad2da3dc60210a2c4d2f3165d5f1d0acd54ca4811072a053225170ed748R153
--
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]