shunping commented on code in PR #39595:
URL: https://github.com/apache/beam/pull/39595#discussion_r3723534599
##########
sdks/go/container/tools/pipeline_options.go:
##########
@@ -42,3 +46,179 @@ func MakePipelineOptionsFileAndEnvVar(options string) error
{
os.Setenv("PIPELINE_OPTIONS_FILE", f.Name())
return nil
}
+
+// PipelineOptions represents parsed pipeline options as a normalized map.
+type PipelineOptions struct {
+ options map[string]any
+ experiments map[string]string
+}
+
+// ParseOptionsFromProto creates normalized PipelineOptions directly from a
protobuf Struct.
+func ParseOptionsFromProto(opt *structpb.Struct, sdkNamespace string)
*PipelineOptions {
+ if opt == nil {
+ return &PipelineOptions{options: make(map[string]any),
experiments: make(map[string]string)}
+ }
+ raw := opt.AsMap()
+ flat := make(map[string]any)
+
+ // 1. Extract nested options if present (Dataflow runner uses this
structure)
+ if optsVal, ok := raw["options"]; ok {
+ if optsMap, ok := optsVal.(map[string]any); ok {
+ for k, v := range optsMap {
+ flat[k] = v
+ }
+ }
+ }
+
+ // 2. Extract standard URN keys (Portable runners use this structure)
+ for k, v := range raw {
+ if k == "options" || k == "display_data" {
+ continue
+ }
+ if strings.HasPrefix(k, "beam:option:") && strings.HasSuffix(k,
":v1") {
Review Comment:
Since we're checking specifically for the :v1 suffix here, I'm slightly
worried about scenarios where we might bump a URN to v2 or so. Should we
future-proof this by matching any version suffix instead?
--
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]