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

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

                Author: ASF GitHub Bot
            Created on: 11/Oct/21 18:51
            Start Date: 11/Oct/21 18:51
    Worklog Time Spent: 10m 
      Work Description: htyleo commented on a change in pull request #15698:
URL: https://github.com/apache/beam/pull/15698#discussion_r726502148



##########
File path: sdks/go/pkg/beam/core/runtime/xlangx/registry.go
##########
@@ -0,0 +1,317 @@
+// 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 xlangx
+
+import (
+       "context"
+       "fmt"
+       "net/url"
+       "strings"
+       "sync"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/graphx"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/pipelinex"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
+       jobpb 
"github.com/apache/beam/sdks/v2/go/pkg/beam/model/jobmanagement_v1"
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+)
+
+var defaultReg = newRegistry()
+
+// RegisterHandler associates a namespace with a HandlerFunc which can be used 
to
+// replace calls to a Beam ExpansionService.
+//
+// Then, expansion addresses of the forms
+//   "<namespace>" or
+//   "<namespace>:<configuration>"
+// can be used with beam.CrossLanguage. Any configuration after the separator 
is
+// provided to the HandlerFunc on call for the handler func to use at it's 
leisure.
+func RegisterHandler(namespace string, handler HandlerFunc) {
+       if err := defaultReg.RegisterHandler(namespace, handler); err != nil {
+               panic(err)
+       }
+}
+
+// RegisterExpansionForUrn overrides which expansion address is used to
+// expand a specific transform URN. The expansion address must be a URL
+// or be a namespaced handler registered with RegisterHandler.
+//
+// When the expansion address is for a handler, it may take the forms
+//  "<namespace>" or
+//  "<namespace>:<configuration>"
+func RegisterOverrideForUrn(urn, expansionAddr string) {
+       if err := defaultReg.RegisterOverrideForUrn(urn, expansionAddr); err != 
nil {
+               panic(err)
+       }
+}
+
+// HandlerParams is the parameter to an expansion service handler.
+type HandlerParams struct {
+       // Additional parameterization string, if any.
+       Config string
+
+       Req *jobpb.ExpansionRequest
+
+       // Additional pipeline graph information for custom handling
+       // Not exported to avoid mutation.
+       edge *graph.MultiEdge
+       ext  *graph.ExternalTransform
+}
+
+// CoderMarshaller returns a coder marshaller initialized with the request's 
namespace.
+func (p *HandlerParams) CoderMarshaller() *graphx.CoderMarshaller {
+       cm := graphx.NewCoderMarshaller()
+       cm.Namespace = p.Req.Namespace
+       return cm
+}
+
+// OutputPCollections returns the local identifiers for expected outputs
+// for this expansion service request.
+//
+// If no collections are returned, none are currently expected.
+func (p *HandlerParams) OutputPCollections() []string {
+       var out []string
+       for local := range p.ext.OutputsMap {
+               out = append(out, local)
+       }
+       return out
+}
+
+// InputPCollections returns the local identifiers for expected outputs
+// for this expansion service request.
+//
+// If no collections are returned, none are currently expected.
+func (p *HandlerParams) InputPCollections() []string {
+       var out []string
+       for local := range p.ext.InputsMap {
+               out = append(out, local)
+       }
+       return out
+}
+
+func (p *HandlerParams) panicIfMissing(m map[string]int, local string) int {
+       i, ok := m[local]
+       if !ok {
+               panic(fmt.Errorf("unknown local output identifier provided: 
%v", local))
+       }
+       return i
+}
+
+// OutputCoder returns the coder for the associated output PCollection.
+// Panics if local is not returned by OutputPCollections.
+func (p *HandlerParams) OutputCoder(local string) *coder.Coder {
+       i := p.panicIfMissing(p.ext.OutputsMap, local)
+       return p.edge.Output[i].To.Coder
+}
+
+// OutputType returns the full type for the associated output PCollection.
+// Panics if local is not returned by OutputPCollections.
+func (p *HandlerParams) OutputType(local string) typex.FullType {
+       i := p.panicIfMissing(p.ext.OutputsMap, local)
+       return p.edge.Output[i].Type
+}
+
+// OutputBounded returns whether the associated output PCollection is bounded.
+// Panics if local is not returned by OutputPCollections.
+func (p *HandlerParams) OutputBounded(local string) pipepb.IsBounded_Enum {
+       i := p.panicIfMissing(p.ext.OutputsMap, local)
+       return pipelinex.BoolToBounded(p.edge.Output[i].To.Bounded())
+}
+
+// OutputWindowingStrategy returns the windowing strategy for the associated 
output PCollection.
+// Panics if local is not returned by OutputPCollections.
+func (p *HandlerParams) OutputWindowingStrategy(local string, cm 
*graphx.CoderMarshaller) *pipepb.WindowingStrategy {
+       i := p.panicIfMissing(p.ext.OutputsMap, local)
+       wspb, err := graphx.MarshalWindowingStrategy(cm, 
p.edge.Output[i].To.WindowingStrategy())
+       if err != nil {
+               panic(fmt.Errorf("unable to marshal windowing strategy for 
output %v: %w", local, err))
+       }
+       return wspb
+}
+
+// OutputCoder returns the coder for the associated output PCollection.
+// Panics if local is not returned by InputPCollections.
+func (p *HandlerParams) InputCoder(local string) *coder.Coder {
+       i := p.panicIfMissing(p.ext.InputsMap, local)
+       return p.edge.Input[i].From.Coder
+}
+
+// InputType returns the full type for the associated output PCollection.
+// Panics if local is not returned by InputPCollections.
+func (p *HandlerParams) InputType(local string) typex.FullType {
+       i := p.panicIfMissing(p.ext.OutputsMap, local)
+       return p.edge.Output[i].Type

Review comment:
       Output[i] -> Input[i]




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


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

    Worklog Id:     (was: 663714)
    Time Spent: 0.5h  (was: 20m)

> Extend expansion service handling to allow overrides/conveniences.
> ------------------------------------------------------------------
>
>                 Key: BEAM-13013
>                 URL: https://issues.apache.org/jira/browse/BEAM-13013
>             Project: Beam
>          Issue Type: Sub-task
>          Components: sdk-go
>            Reporter: Robert Burke
>            Assignee: Robert Burke
>            Priority: P2
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Described in the BeamSQL for the Go SDK document: 
> https://s.apache.org/beam-go-sql-api



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

Reply via email to