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

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

                Author: ASF GitHub Bot
            Created on: 29/Nov/18 19:31
            Start Date: 29/Nov/18 19:31
    Worklog Time Spent: 10m 
      Work Description: lostluck commented on a change in pull request #7161: 
[BEAM-3612] Closurize method invocations
URL: https://github.com/apache/beam/pull/7161#discussion_r237628172
 
 

 ##########
 File path: sdks/go/pkg/beam/core/util/reflectx/structs.go
 ##########
 @@ -0,0 +1,73 @@
+// 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 reflectx
+
+import (
+       "context"
+       "reflect"
+       "sync"
+
+       "github.com/apache/beam/sdks/go/pkg/beam/log"
+)
+
+var (
+       structFuncs   = make(map[string]func(interface{}) map[string]Func)
+       structFuncsMu sync.Mutex
+)
+
+// RegisterStructWrapper takes in the reflect.Type of a structural DoFn, and
+// a wrapping function that will take an instance of that struct type and
+// produce a map of method names to of closured Funcs that call the method
+// on the instance of the struct.
+//
+// The goal is to avoid the implicit reflective method invocation penalty
+// that occurs when passing a method through the reflect package.
+func RegisterStructWrapper(t reflect.Type, wrapper func(interface{}) 
map[string]Func) {
+       structFuncsMu.Lock()
+       defer structFuncsMu.Unlock()
+
+       if t.Kind() != reflect.Struct {
+               log.Fatalf(context.Background(), "RegisterStructWrapper for %v 
should be a struct type, but was %v", t, t.Kind())
 
 Review comment:
   No, we could be more strict here. The generator does lifecycle method 
filtering so only the life cycle methods have code generated for them. Beam at 
pipeline construction time should be doing that required method checking at 
construction time anyway.
   
   Short of always using the tool, the development flow would be using the 
reflection based paths, so one hopes that beam catches those errors then.
   
   Finally, I'd rather have any more dedicated checks in a vetting runner of 
some kind, to catch typos and the like, rather than in the code generation code.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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: 170784)
    Time Spent: 7h 40m  (was: 7.5h)

> Make it easy to generate type-specialized Go SDK reflectx.Funcs
> ---------------------------------------------------------------
>
>                 Key: BEAM-3612
>                 URL: https://issues.apache.org/jira/browse/BEAM-3612
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-go
>            Reporter: Henning Rohde
>            Assignee: Robert Burke
>            Priority: Major
>          Time Spent: 7h 40m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to