uranusjr commented on code in PR #76825:
URL: https://github.com/apache/airflow/pull/76825#discussion_r4599679929
##########
kubernetes-tests/lang_sdk/go_example/main.go:
##########
@@ -60,12 +63,43 @@ func goExtract(actx airflow.Context) (any, error) {
}
// goTransform reads the my_variable Airflow variable through the coordinator,
-// exercising a GetVariable round-trip over the Execution API.
+// exercising a GetVariable round-trip over the Execution API, and the result
of the
+// mapped python_fanout task, which is every instance's value in a list.
func goTransform(actx airflow.Context) error {
val, err := actx.Client().GetVariable(actx, "my_variable")
if err != nil {
return err
}
actx.Logger().InfoContext(actx, "go_transform obtained variable",
"my_variable", val)
+
+ ti := actx.TaskInstance()
+ fanout, err := actx.Client().GetXCom(
+ actx, ti.DagID, ti.RunID, "python_fanout", nil,
sdk.XComReturnValueKey, nil,
+ )
+ if err != nil {
+ return err
+ }
+ values, ok := fanout.([]any)
+ if !ok || len(values) != 3 {
+ return fmt.Errorf("python_fanout result is %#v, want []any{1,
2, 3}", fanout)
+ }
+ for i, v := range values {
+ if n, ok := asInt64(v); !ok || n != int64(i+1) {
+ return fmt.Errorf("python_fanout result is %#v, want
[]any{1, 2, 3}", fanout)
+ }
+ }
return nil
}
+
+// asInt64 returns v as an int64 if it is an integer. An integer XCom value
arrives
+// as a Go integer type whose width depends on the value.
+func asInt64(v any) (int64, bool) {
+ switch n := reflect.ValueOf(v); {
+ case n.CanInt():
+ return n.Int(), true
+ case n.CanUint():
+ return int64(n.Uint()), true
+ default:
+ return 0, false
+ }
+}
Review Comment:
`normalizeDecodedValue` isn’t on v3-4-test, and this PR gets backported
there. A cherry-picked `DeepEqual` would only fail at runtime in the k8s tests.
I’ll make this change in #76826 instead, since that one is main-only.
--
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]