uranusjr commented on code in PR #68983:
URL: https://github.com/apache/airflow/pull/68983#discussion_r3488404322
##########
java-sdk/processor/src/main/kotlin/org/apache/airflow/sdk/BuilderProcessor.kt:
##########
@@ -203,6 +200,45 @@ private data class RequiredXCom(
val taskId: String,
)
+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 = CodeBlock.of($$"client.getXCom($S)", xcom.taskId)
+ val type = TypeName.get(xcom.paramType)
+ val accessor = NUMBER_ACCESSORS[type]
+ val number = ClassName.get(Number::class.java)
+ // Wire integers decode to Long and floats to Double, so a direct
(Integer)/(Float)
+ // cast throws ClassCastException; widen via Number instead.
+ return when {
+ accessor == null -> CodeBlock.of($$"($T) $L", if (type.isPrimitive)
type.box() else type, call)
+ // A primitive target cannot hold null; an absent XCom fails fast on
unboxing, as before.
Review Comment:
This comment should not exist. “as before” does not even mean anything after
this PR is merged to main.
--
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]