LuciferYang commented on code in PR #13149:
URL: https://github.com/apache/gluten/pull/13149#discussion_r4130866912


##########
gluten-core/src/main/scala/org/apache/gluten/extension/GlutenSessionExtensions.scala:
##########
@@ -58,4 +58,15 @@ private[gluten] class GlutenSessionExtensions
 object GlutenSessionExtensions {
   val GLUTEN_SESSION_EXTENSION_NAME: String = 
classOf[GlutenSessionExtensions].getCanonicalName
   val GLUTEN_ENABLE_FOR_THREAD_KEY: String = "gluten.enabledForCurrentThread"
+
+  // Visible for testing. Parse the per-thread enable flag, naming the 
property and the
+  // offending value when it is not a boolean instead of surfacing a bare 
`toBoolean` failure.
+  private[gluten] def isEnabledForThread(value: String): Boolean = {
+    try value.toBoolean
+    catch {
+      case _: IllegalArgumentException =>
+        throw new IllegalArgumentException(
+          s"$GLUTEN_ENABLE_FOR_THREAD_KEY should be boolean, but was $value")

Review Comment:
   I kept it as a small method mainly so the invalid-value path can be 
unit-tested (`GlutenSessionExtensionsSuite` checks that the exception names 
both the key and the offending value) without standing up a session-extension 
harness. One note on the snippet: `Option(...).forall(isEnabledForThread)` 
defaults to enabled when the property is unset, whereas 
`.map(_.toBoolean).getOrElse(throw ...)` would throw when it is absent. I can 
inline it if you prefer, keeping a test on the inlined logic.



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