philo-he commented on code in PR #13149:
URL: https://github.com/apache/gluten/pull/13149#discussion_r4129874295


##########
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:
   It seems better to make this inline if no other places calling 
`isEnabledForThread`.
   ```
   Option(session.sparkContext.getLocalProperty(GLUTEN_ENABLE_FOR_THREAD_KEY))
   .map(_.toBoolean)
    .getOrElse(
           throw new IllegalArgumentException(
             s"Invalid boolean config for key: 
${GlutenConf.NATIVE_ENABLED_KEY}"))
   ```



##########
gluten-core/src/test/scala/org/apache/gluten/extension/GlutenSessionExtensionsSuite.scala:
##########
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.gluten.extension
+
+import org.scalatest.funsuite.AnyFunSuite
+
+class GlutenSessionExtensionsSuite extends AnyFunSuite {
+
+  test("per-thread enable flag accepts boolean values") {
+    assert(GlutenSessionExtensions.isEnabledForThread("true"))
+    assert(!GlutenSessionExtensions.isEnabledForThread("false"))
+  }
+
+  test("per-thread enable flag names the property and value when not a 
boolean") {
+    val exception = intercept[IllegalArgumentException] {
+      GlutenSessionExtensions.isEnabledForThread("yes")
+    }
+    
assert(exception.getMessage.contains(GlutenSessionExtensions.GLUTEN_ENABLE_FOR_THREAD_KEY))
+    assert(exception.getMessage.contains("yes"))
+  }

Review Comment:
   It seems better to use `spark.sparkContext.setLocalProperty` for testing 
different cases?



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