cloud-fan commented on code in PR #52334:
URL: https://github.com/apache/spark/pull/52334#discussion_r2436025457


##########
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:
   shall we do this reset in all the `def sql` overloads?



-- 
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