[ 
https://issues.apache.org/jira/browse/BEAM-9616?focusedWorklogId=491509&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-491509
 ]

ASF GitHub Bot logged work on BEAM-9616:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Sep/20 03:18
            Start Date: 26/Sep/20 03:18
    Worklog Time Spent: 10m 
      Work Description: youngoli commented on a change in pull request #12903:
URL: https://github.com/apache/beam/pull/12903#discussion_r495407788



##########
File path: sdks/go/pkg/beam/core/runtime/genx/genx.go
##########
@@ -0,0 +1,172 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements.  See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//    http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package genx is a convenience package to better support the code
+// generator. It can be depended on by the user facing beam package
+// and be refered to by generated code.
+//
+// Similarly, it can depend on beam internals and access the canonical
+// method list in the graph package, or other packages to filter out
+// types that aren't necessary for registration (like context.Context).
+package genx
+
+import (
+       "reflect"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/core/funcx"
+       "github.com/apache/beam/sdks/go/pkg/beam/core/graph"
+       "github.com/apache/beam/sdks/go/pkg/beam/core/runtime"
+)
+
+// RegisterDoFn is a convenience function for registering DoFns.
+// Differs from RegisterFunction and RegisterType by introspecting
+// all parameters and returns of Lifecycle methods on the dofn,
+// and registers those types for you.
+//
+// Panics if not passed a dofn.
+func RegisterDoFn(dofn interface{}) {
+       f, ts, err := registerDoFn(dofn)
+       if err != nil {
+               panic(err)
+       }
+       if f != nil {
+               runtime.RegisterFunction(f)
+       }
+       for _, t := range ts {
+               runtime.RegisterType(t)
+       }
+}
+
+// registerDoFn returns all types associated with the provided DoFn.
+// If passed a functional DoFn, the first return is a Function to
+// register with runtime.RegisterFunction.
+// The second return is all types to register with runtime.RegisterType.
+// Returns an error if the passed in values are not DoFns.
+func registerDoFn(dofn interface{}) (interface{}, []reflect.Type, error) {
+       if rt, ok := dofn.(reflect.Type); ok {
+               if rt.Kind() == reflect.Ptr {
+                       rt = rt.Elem()
+               }
+               dofn = reflect.New(rt).Interface()

Review comment:
       Oh, duh. I had a brain-fart that this statement only happens if the dofn 
is a reflect.Type. I was imagining turning an actual DoFn instance into a 
reflect.Type and back. Makes complete sense now.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 491509)
    Time Spent: 2.5h  (was: 2h 20m)

> [Go SDK] starcgen improvements
> ------------------------------
>
>                 Key: BEAM-9616
>                 URL: https://issues.apache.org/jira/browse/BEAM-9616
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Robert Burke
>            Assignee: Robert Burke
>            Priority: P3
>              Labels: golang
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> The starcgen code generator works OK, but could do with some improvements.
>  * Uniquifying imports (handling multiple imports with same short suffix)
>  * Generating multiple iterNatives (eg when the normal symbol is already 
> taken).
>  * Keying off of beam.Register* calls rather than command line.
>  **  Avoids duplicating lists of identifiers, and improves default behavior.
>  ** Possibly have a new beam.RegisterDoFn which can take a list of DoFn and 
> struct types a function or a struct, and key off those, reducing boiler plate 
> somewhat.
>  * Perhaps having a specific single import alias package for components 
> required for import, rather than the current 3-4.
>  * Generate efficient Beam Schema coders for registered types?
>  * Handle SplittableDoFns properly.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to