dtenedor commented on code in PR #52334:
URL: https://github.com/apache/spark/pull/52334#discussion_r2395324460


##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkParserUtils.scala:
##########
@@ -234,4 +276,71 @@ trait SparkParserUtils {
   }
 }
 
-object SparkParserUtils extends SparkParserUtils
+object SparkParserUtils extends SparkParserUtils {
+
+  /**
+   * Callback type for parameter substitution integration.
+   *
+   * This callback allows the parameter substitution system to provide origin 
adjustment without
+   * creating circular dependencies between modules.
+   *
+   * @param startToken
+   *   The start token from substituted SQL
+   * @param stopToken
+   *   The stop token from substituted SQL
+   * @param substitutedSql
+   *   The substituted SQL text
+   * @param objectType
+   *   The object type
+   * @param objectName
+   *   The object name
+   * @return
+   *   Some(origin) if parameter substitution should be applied, None otherwise
+   */
+  type ParameterSubstitutionCallback =
+    (Token, Token, String, Option[String], Option[String]) => Option[Origin]
+
+  /**
+   * Thread-local callback for parameter substitution integration. This is set 
by the parameter
+   * handler when parameter substitution occurs.
+   */
+  private val parameterSubstitutionCallbackStorage =
+    new ThreadLocal[Option[ParameterSubstitutionCallback]]() {

Review Comment:
   I wonder if there is any way we can set the callback using the parsing API 
rather than a thread local like this. This could make it more complex to 
support parallel parsing later, for example. If the parsing entry point is the 
`parsePlan` method of AbstractSqlParser, that introduces a call site with stack 
frames creating state, currently starting with the SQL string to parse. Is 
there any way we could pass this callback as part of that state into the stack 
frames instead of using a thread local?



##########
sql/api/src/main/scala/org/apache/spark/sql/catalyst/util/SparkParserUtils.scala:
##########
@@ -234,4 +276,71 @@ trait SparkParserUtils {
   }
 }
 
-object SparkParserUtils extends SparkParserUtils
+object SparkParserUtils extends SparkParserUtils {
+
+  /**
+   * Callback type for parameter substitution integration.
+   *
+   * This callback allows the parameter substitution system to provide origin 
adjustment without
+   * creating circular dependencies between modules.
+   *
+   * @param startToken
+   *   The start token from substituted SQL
+   * @param stopToken
+   *   The stop token from substituted SQL
+   * @param substitutedSql
+   *   The substituted SQL text
+   * @param objectType
+   *   The object type
+   * @param objectName
+   *   The object name
+   * @return
+   *   Some(origin) if parameter substitution should be applied, None otherwise
+   */
+  type ParameterSubstitutionCallback =
+    (Token, Token, String, Option[String], Option[String]) => Option[Origin]
+
+  /**
+   * Thread-local callback for parameter substitution integration. This is set 
by the parameter
+   * handler when parameter substitution occurs.
+   */
+  private val parameterSubstitutionCallbackStorage =
+    new ThreadLocal[Option[ParameterSubstitutionCallback]]() {
+      override def initialValue(): Option[ParameterSubstitutionCallback] = None
+    }
+
+  /**
+   * Get the current parameter substitution callback.
+   */
+  def parameterSubstitutionCallback: Option[ParameterSubstitutionCallback] = {
+    parameterSubstitutionCallbackStorage.get()
+  }
+
+  /**
+   * Set the parameter substitution callback for the current thread. This 
should be called by
+   * parameter handlers before parsing.
+   */
+  def setParameterSubstitutionCallback(callback: 
ParameterSubstitutionCallback): Unit = {
+    parameterSubstitutionCallbackStorage.set(Some(callback))
+  }
+
+  /**
+   * Clear the parameter substitution callback for the current thread.
+   */
+  def clearParameterSubstitutionCallback(): Unit = {
+    parameterSubstitutionCallbackStorage.remove()
+  }
+
+  /**
+   * Execute a block with a parameter substitution callback set.
+   */
+  def withParameterSubstitutionCallback[T](

Review Comment:
   This is not used anywhere in the PR as of now?



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