FrankYang0529 commented on code in PR #68983:
URL: https://github.com/apache/airflow/pull/68983#discussion_r3485530855


##########
java-sdk/processor/src/main/kotlin/org/apache/airflow/sdk/BuilderProcessor.kt:
##########
@@ -201,8 +197,42 @@ private data class RequiredXCom(
   val paramType: TypeMirror,
   val paramName: String,
   val taskId: String,
+  val key: String,
 )
 
+// Default xcom key like Client.XCOM_RETURN_KEY
+private const val XCOM_RETURN_KEY = "return_value"
+
+private val NUMBER_ACCESSORS: Map<TypeName, String> =
+  buildMap {
+    mapOf(
+      TypeName.BYTE to "byteValue",
+      TypeName.SHORT to "shortValue",
+      TypeName.INT to "intValue",
+      TypeName.LONG to "longValue",
+      TypeName.FLOAT to "floatValue",
+      TypeName.DOUBLE to "doubleValue",
+    ).forEach { (primitive, accessor) ->
+      put(primitive, accessor)
+      put(primitive.box(), accessor)
+    }
+  }
+
+private fun xcomAccess(xcom: RequiredXCom): CodeBlock {
+  val call =
+    if (xcom.key == XCOM_RETURN_KEY) {
+      CodeBlock.of($$"client.getXCom($S)", xcom.taskId)
+    } else {
+      CodeBlock.of($$"client.getXCom($S, $S)", xcom.key, xcom.taskId)
+    }
+  val type = TypeName.get(xcom.paramType)
+  // Wire integers decode to Long and floats to Double, so a direct (Integer) 
or
+  // (Float) cast on the boxed value throws ClassCastException; widen via 
Number.
+  return NUMBER_ACCESSORS[type]?.let { accessor ->

Review Comment:
   Good catch. Updated the function to handle null case.



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

Reply via email to