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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala:
##########
@@ -1105,4 +1110,26 @@ abstract class SparkStrategies extends 
QueryPlanner[SparkPlan] {
       case _ => Nil
     }
   }
+
+  /**
+   * Extracts a user-friendly table name from a logical plan for error 
messages.
+   */
+  private def extractTableNameForError(table: LogicalPlan): String = {
+    val unwrapped = EliminateSubqueryAliases(table)
+    unwrapped match {
+      // Check specific types before NamedRelation since they extend it
+      case DataSourceV2Relation(_, _, catalog, Some(ident), _, _) =>
+        (catalog.map(_.name()).toSeq ++ 
ident.asMultipartIdentifier).mkString(".")
+      case LogicalRelation(_, _, Some(catalogTable), _, _) =>
+        catalogTable.identifier.unquotedString
+      case r: NamedRelation =>
+        r.name
+      case _ =>
+        // Try to get name from SubqueryAlias before unwrapping
+        table match {
+          case logical.SubqueryAlias(name, _) => name.toString
+          case _ => "table"

Review Comment:
   ```suggestion
             case _ => "unknown"
   ```



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkStrategies.scala:
##########
@@ -1105,4 +1110,26 @@ abstract class SparkStrategies extends 
QueryPlanner[SparkPlan] {
       case _ => Nil
     }
   }
+
+  /**
+   * Extracts a user-friendly table name from a logical plan for error 
messages.
+   */
+  private def extractTableNameForError(table: LogicalPlan): String = {
+    val unwrapped = EliminateSubqueryAliases(table)
+    unwrapped match {
+      // Check specific types before NamedRelation since they extend it
+      case DataSourceV2Relation(_, _, catalog, Some(ident), _, _) =>
+        (catalog.map(_.name()).toSeq ++ 
ident.asMultipartIdentifier).mkString(".")
+      case LogicalRelation(_, _, Some(catalogTable), _, _) =>
+        catalogTable.identifier.unquotedString
+      case r: NamedRelation =>
+        r.name
+      case _ =>
+        // Try to get name from SubqueryAlias before unwrapping
+        table match {
+          case logical.SubqueryAlias(name, _) => name.toString

Review Comment:
   how can we hit it? We call `EliminateSubqueryAliases` at the beginning



##########
sql/core/src/test/scala/org/apache/spark/sql/ParametersSuite.scala:
##########
@@ -2374,4 +2374,76 @@ class ParametersSuite extends QueryTest with 
SharedSparkSession {
       expectedStopPos = Some(46) // End of "nonexistent_table" in inner query
     )
   }
+
+  test("detect unbound named parameter with empty map") {
+    // When sql() is called with empty map, parameter markers should still be 
detected
+    val exception = intercept[AnalysisException] {
+      spark.sql("SELECT :param", Map.empty[String, Any])
+    }
+    checkError(
+      exception = exception,
+      condition = "UNBOUND_SQL_PARAMETER",
+      parameters = Map("name" -> "param"),
+      context = ExpectedContext(
+        fragment = ":param",
+        start = 7,
+        stop = 12))
+  }
+
+  test("detect unbound positional parameter with empty array") {
+    // When sql() is called with empty array, parameter markers should still 
be detected
+    val exception = intercept[AnalysisException] {
+      spark.sql("SELECT ?", Array.empty[Any])
+    }
+    checkError(
+      exception = exception,
+      condition = "UNBOUND_SQL_PARAMETER",
+      parameters = Map("name" -> "_7"),
+      context = ExpectedContext(
+        fragment = "?",
+        start = 7,
+        stop = 7))
+  }
+
+  test("detect unbound named parameter with no arguments") {
+    val exception = intercept[AnalysisException] {
+      spark.sql("SELECT :param")
+    }
+    checkError(
+      exception = exception,
+      condition = "UNBOUND_SQL_PARAMETER",
+      parameters = Map("name" -> "param"),
+      context = ExpectedContext(
+        fragment = ":param",
+        start = 7,
+        stop = 12))
+  }
+
+  test("detect unbound positional parameter with nop arguments") {

Review Comment:
   ```suggestion
     test("detect unbound positional parameter with no arguments") {
   ```



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