chris-twiner commented on code in PR #34558:
URL: https://github.com/apache/spark/pull/34558#discussion_r1993925656


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/higherOrderFunctions.scala:
##########
@@ -235,6 +256,53 @@ trait HigherOrderFunction extends Expression with 
ExpectsInputTypes {
     val canonicalizedChildren = cleaned.children.map(_.canonicalized)
     withNewChildren(canonicalizedChildren)
   }
+
+
+  protected def assignAtomic(atomicRef: String, value: String, isNull: String 
= FalseLiteral,
+      nullable: Boolean = false) = {
+    if (nullable) {
+      s"""
+        if ($isNull) {
+          $atomicRef.set(null);
+        } else {
+          $atomicRef.set($value);
+        }
+      """
+    } else {
+      s"$atomicRef.set($value);"
+    }
+  }
+
+  protected def assignArrayElement(ctx: CodegenContext, arrayName: String, 
elementCode: ExprCode,
+      elementVar: NamedLambdaVariable, index: String): String = {
+    val elementType = elementVar.dataType
+    val elementAtomic = ctx.addReferenceObj(elementVar.name, elementVar.value)
+    val extractElement = CodeGenerator.getValue(arrayName, elementType, index)

Review Comment:
   > Finally got back around to this, added tests showing why the atomic 
reference is needed in case of `CodegenFallback` inside a lambda expression
   
   FYI - In [my 
testing](https://github.com/sparkutils/quality/blob/temp/fabric_0.1.3.1_rc6_map_with_issues/src/main/scala/org/apache/spark/sql/qualityFunctions/LambdaCompilation.scala#L21)
 you can seemingly, at codegen time, swap out the 
AtomicReference/NamedLambdaVariable in all cases to a simple set/get wrapper 
around a field for the eval CodegenFallback case.
   
   Per [the original NamedLambdaVariable 
PR](https://github.com/apache/spark/pull/21954#discussion_r207162167) the 
AtomicReference only seems to be needed for proper tree transformations, so you 
can swap out at compilation time to squeeze a little bit [more perf 
out](https://brooker.co.za/blog/2012/09/10/volatile.html) (lower memory usage, 
no need for volatile read/memory barriers on write etc. this only really makes 
a difference if the code is HOF heavy of course, like Quality tends to be).



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to