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

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

                Author: ASF GitHub Bot
            Created on: 03/May/22 14:18
            Start Date: 03/May/22 14:18
    Worklog Time Spent: 10m 
      Work Description: damccorm commented on code in PR #17429:
URL: https://github.com/apache/beam/pull/17429#discussion_r863830365


##########
sdks/go/pkg/beam/registration/registration.tmpl:
##########
@@ -0,0 +1,252 @@
+{{define "BuildWrapper_StartFinishBundle"}}
+{{$lowerName := "unknown"}}{{$upperName := "unknown"}}{{if (eq .func 
"startBundle")}}{{$lowerName = "startBundle"}}{{$upperName = 
"StartBundle"}}{{end}}{{if (eq .func "finishBundle")}}{{$lowerName = 
"finishBundle"}}{{$upperName = "FinishBundle"}}{{end}}{{$startFinishBundleMaxIn 
:= .startFinishBundleMaxIn}}{{$processElementMaxIn := .processElementMaxIn}}
+{{range $numParams := upto $processElementMaxIn}}
+func build{{$upperName}}Wrapper{{$numParams}}{{(genericTypingRepresentation 
$numParams 0 true)}}(doFn interface{}) func(interface{}) reflectx.Func {
+    {{$lowerName}}In := -1
+       {{$lowerName}}Out := -1
+       {{$lowerName}}Method := 
reflect.ValueOf(doFn).MethodByName("{{$upperName}}")
+       if {{$lowerName}}Method.IsValid() {
+               {{$lowerName}}In = {{$lowerName}}Method.Type().NumIn()
+               {{$lowerName}}Out = {{$lowerName}}Method.Type().NumOut()
+           switch {
+{{range $funcIn := upto $startFinishBundleMaxIn}}
+    case {{$lowerName}}In == {{$funcIn}}:
+            switch { {{range $funcOut := upto 2}}{{$possibleCombos := 
(possibleBundleLifecycleParameterCombos $funcIn $numParams)}}{{if 
$possibleCombos}}
+            case {{$lowerName}}Out == {{$funcOut}}:
+{{$first := true}}{{range $funcCombo := $possibleCombos}}{{if $first}}{{$first 
= false}}                {{else}} else {{end}}if _, ok := 
doFn.({{$lowerName}}{{$funcIn}}x{{$funcOut}}{{if (or $funcIn 
$funcOut)}}[{{(join $funcCombo ", ")}}{{if $funcOut}}{{if $funcIn}}, 
{{end}}error{{end}}]{{end}}); ok {
+                    reflectx.RegisterFunc(reflect.TypeOf((*func({{(join 
$funcCombo ", ")}}){{if $funcOut}} error{{end}})(nil)).Elem(), func(fn 
interface{}) reflectx.Func { return &caller{{$funcIn}}x{{$funcOut}}{{if (or 
$funcIn $funcOut)}}[{{(join $funcCombo ", ")}}{{if $funcOut}}{{if $funcIn}}, 
{{end}}error{{end}}]{{end}}{fn: fn.(func({{(join $funcCombo ", ")}}){{if 
$funcOut}} error{{end}})} })
+                    {{$funcRegister := (makeStructRegisterEntry $lowerName 
$upperName $funcCombo (list))}}{{if $funcOut}}{{$funcRegister = 
(makeStructRegisterEntry $lowerName $upperName $funcCombo (list 
"error"))}}{{end}}
+                    return func(fn interface{}) reflectx.Func { return 
{{$funcRegister}} }
+                } {{end}}{{end}}{{end}}
+            default:
+                panic("Invalid signature for {{$upperName}}")
+            }
+{{end}}
+        default:
+            panic("Invalid signature for {{$upperName}}")
+        }
+    }
+    return nil
+}
+{{end}}{{end}}{{define "BuildWrapper_SetupTeardown"}}
+{{$lowerName := "unknown"}}{{$upperName := "unknown"}}{{if (eq .func 
"setup")}}{{$lowerName = "setup"}}{{$upperName = "Setup"}}{{end}}{{if (eq .func 
"teardown")}}{{$lowerName = "teardown"}}{{$upperName = "Teardown"}}{{end}}
+func build{{$upperName}}Wrapper(doFn interface{}) func(interface{}) 
reflectx.Func {
+    if _, ok := doFn.({{$lowerName}}0x0); ok {
+        {{$lowerName}}Caller := func(fn interface{}) reflectx.Func {
+            f := fn.(func())
+            return &caller0x0{fn: f}
+        }
+        reflectx.RegisterFunc(reflect.TypeOf((*func())(nil)).Elem(), 
{{$lowerName}}Caller)
+
+        return func(fn interface{}) reflectx.Func {
+            return reflectx.MakeFunc(func() {
+                fn.({{$lowerName}}0x0).{{$upperName}}()
+            })
+        }
+    } else if _, ok := doFn.({{$lowerName}}1x0); ok {
+        {{$lowerName}}Caller := func(fn interface{}) reflectx.Func {
+            f := fn.(func(context.Context))
+            return &caller1x0[context.Context]{fn: f}
+        }
+        
reflectx.RegisterFunc(reflect.TypeOf((*func(context.Context))(nil)).Elem(), 
{{$lowerName}}Caller)
+
+        return func(fn interface{}) reflectx.Func {
+            return reflectx.MakeFunc(func(a0 context.Context) {
+                fn.({{$lowerName}}1x0).{{$upperName}}(a0)
+            })
+        }
+    } else if _, ok := doFn.({{$lowerName}}0x1); ok {
+        {{$lowerName}}Caller := func(fn interface{}) reflectx.Func {
+            f := fn.(func() error)
+            return &caller0x1[error]{fn: f}
+        }
+        reflectx.RegisterFunc(reflect.TypeOf((*func() error)(nil)).Elem(), 
{{$lowerName}}Caller)
+
+        return func(fn interface{}) reflectx.Func {
+            return reflectx.MakeFunc(func() error {
+                return fn.({{$lowerName}}0x1).{{$upperName}}()
+            })
+        }
+    } else if _, ok := doFn.({{$lowerName}}1x1); ok {
+        {{$lowerName}}Caller := func(fn interface{}) reflectx.Func {
+            f := fn.(func(context.Context) error)
+            return &caller1x1[context.Context, error]{fn: f}
+        }
+        reflectx.RegisterFunc(reflect.TypeOf((*func(context.Context) 
error)(nil)).Elem(), {{$lowerName}}Caller)
+
+        return func(fn interface{}) reflectx.Func {
+            return reflectx.MakeFunc(func(a0 context.Context) error {
+                return fn.({{$lowerName}}1x1).{{$upperName}}(a0)
+            })
+        }
+    }
+
+    return nil
+}
+{{end}}
+// 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.
+
+// Code generated from registration.tmpl. DO NOT EDIT.
+
+package beam

Review Comment:
   Oop - good catch!





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

    Worklog Id:     (was: 765466)
    Time Spent: 3.5h  (was: 3h 20m)

> [Go SDK] Allow users to optimize DoFns with a single generic registration 
> function
> ----------------------------------------------------------------------------------
>
>                 Key: BEAM-14347
>                 URL: https://issues.apache.org/jira/browse/BEAM-14347
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-go
>            Reporter: Danny McCormick
>            Assignee: Danny McCormick
>            Priority: P2
>          Time Spent: 3.5h
>  Remaining Estimate: 0h
>
> Right now, to optimize DoFn execution, users have to use the code generator. 
> This updates to allow them to use generics instead.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to