johannaojeling commented on code in PR #25558:
URL: https://github.com/apache/beam/pull/25558#discussion_r1112050138


##########
sdks/go/pkg/beam/runners/prism/internal/handlerunner.go:
##########
@@ -0,0 +1,298 @@
+// 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 internal
+
+import (
+       "bytes"
+       "fmt"
+       "io"
+       "reflect"
+       "sort"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/mtime"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/window"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/exec"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+       
"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/engine"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/urns"
+       
"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/worker"
+       "golang.org/x/exp/slog"
+       "google.golang.org/protobuf/encoding/prototext"
+       "google.golang.org/protobuf/proto"
+)
+
+// This file retains the logic for the pardo handler
+
+// RunnerCharacteristic holds the configuration for Runner based transforms,
+// such as GBKs, Flattens.
+type RunnerCharacteristic struct {
+       SDKFlatten bool // Sets whether we should force an SDK side flatten.
+       SDKGBK     bool // Sets whether the GBK should be handled by the SDK, 
if possible by the SDK.
+}
+
+func Runner(config any) *runner {
+       return &runner{config: config.(RunnerCharacteristic)}
+}
+
+// runner represents an instance of the runner transform handler.
+type runner struct {
+       config RunnerCharacteristic
+}
+
+// ConfigURN returns the name for combine in the configuration file.
+func (*runner) ConfigURN() string {
+       return "runner"
+}
+
+func (*runner) ConfigCharacteristic() reflect.Type {
+       return reflect.TypeOf((*RunnerCharacteristic)(nil)).Elem()
+}
+
+var _ transformExecuter = (*runner)(nil)
+
+func (*runner) ExecuteUrns() []string {
+       return []string{urns.TransformFlatten, urns.TransformGBK}
+}
+
+// ExecuteWith returns what environment the
+func (h *runner) ExecuteWith(t *pipepb.PTransform) string {
+       urn := t.GetSpec().GetUrn()
+       if urn == urns.TransformFlatten && !h.config.SDKFlatten {
+               return ""
+       }
+       if urn == urns.TransformGBK && !h.config.SDKGBK {
+               return ""
+       }
+       return t.GetEnvironmentId()
+}
+
+// ExecTransform handles special processing with respect to runner specific 
transforms

Review Comment:
   ```suggestion
   // ExecuteTransform handles special processing with respect to runner 
specific transforms
   ```



##########
sdks/go/pkg/beam/runners/prism/internal/handlepardo.go:
##########
@@ -0,0 +1,242 @@
+// 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 internal
+
+import (
+       "fmt"
+       "reflect"
+
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/urns"
+       "golang.org/x/exp/maps"
+       "google.golang.org/protobuf/proto"
+)
+
+// This file retains the logic for the pardo handler
+
+// ParDoCharacteristic holds the configuration for ParDos.
+type ParDoCharacteristic struct {
+       DisableSDF bool // Sets whether a pardo supports SDFs or not.
+}
+
+func ParDo(config any) *pardo {
+       return &pardo{config: config.(ParDoCharacteristic)}
+}
+
+// pardo represents an instance of the pardo handler.
+type pardo struct {
+       config ParDoCharacteristic
+}
+
+// ConfigURN returns the name for combine in the configuration file.
+func (*pardo) ConfigURN() string {
+       return "pardo"
+}
+
+func (*pardo) ConfigCharacteristic() reflect.Type {
+       return reflect.TypeOf((*ParDoCharacteristic)(nil)).Elem()
+}
+
+var _ transformPreparer = (*pardo)(nil)
+
+func (*pardo) PrepareUrns() []string {
+       return []string{urns.TransformParDo}
+}
+
+// PrepareTransform handles special processing with respect to ParDos, since 
their handling is dependant on supported features
+// and requirements.
+func (h *pardo) PrepareTransform(tid string, t *pipepb.PTransform, comps 
*pipepb.Components) (*pipepb.Components, []string) {
+
+       // ParDos are a pain in the butt.
+       // Combines, by comparison, are dramatically simpler.
+       // This is because for ParDos, how they are handled, and what kinds of 
transforms are in
+       // and around the ParDo, the actual shape of the graph will change.
+       // At their simplest, it's something a DoFn will handle on their own.
+       // At their most complex, they require intimate interaction with the 
subgraph
+       // bundling process, the data layer, state layers, and control layers.
+       // But unlike combines, which have a clear urn for composite + special 
payload,
+       // ParDos have the standard URN for composites with the standard 
payload.
+       // So always, we need to first unmarshal the payload.
+
+       pardoPayload := t.GetSpec().GetPayload()
+       pdo := &pipepb.ParDoPayload{}
+       if err := (proto.UnmarshalOptions{}).Unmarshal(pardoPayload, pdo); err 
!= nil {
+               panic(fmt.Sprintf("unable to decode ParDoPayload for 
transform[%v]", t.GetUniqueName()))
+       }
+
+       // Lets check for and remove anything that makes things less simple.
+       if pdo.OnWindowExpirationTimerFamilySpec == "" &&
+               !pdo.RequestsFinalization &&
+               !pdo.RequiresStableInput &&
+               !pdo.RequiresTimeSortedInput &&
+               //      len(pdo.SideInputs) == 0 &&
+               len(pdo.StateSpecs) == 0 &&
+               len(pdo.TimerFamilySpecs) == 0 &&
+               pdo.RestrictionCoderId == "" {
+               // At their simplest, we don't need to do anything special at 
pre-processing time, and simply pass through as normal.
+               return &pipepb.Components{
+                       Transforms: map[string]*pipepb.PTransform{
+                               tid: t,
+                       },
+               }, nil
+       }
+
+       // Side inputs add to topology and make fusion harder to deal with

Review Comment:
   You're right, I appreciate these comments!



##########
sdks/go/pkg/beam/runners/prism/internal/handlepardo.go:
##########
@@ -0,0 +1,242 @@
+// 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 internal
+
+import (
+       "fmt"
+       "reflect"
+
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/urns"
+       "golang.org/x/exp/maps"
+       "google.golang.org/protobuf/proto"
+)
+
+// This file retains the logic for the pardo handler
+
+// ParDoCharacteristic holds the configuration for ParDos.
+type ParDoCharacteristic struct {
+       DisableSDF bool // Sets whether a pardo supports SDFs or not.
+}
+
+func ParDo(config any) *pardo {
+       return &pardo{config: config.(ParDoCharacteristic)}
+}
+
+// pardo represents an instance of the pardo handler.
+type pardo struct {
+       config ParDoCharacteristic
+}
+
+// ConfigURN returns the name for combine in the configuration file.
+func (*pardo) ConfigURN() string {
+       return "pardo"
+}
+
+func (*pardo) ConfigCharacteristic() reflect.Type {
+       return reflect.TypeOf((*ParDoCharacteristic)(nil)).Elem()
+}
+
+var _ transformPreparer = (*pardo)(nil)
+
+func (*pardo) PrepareUrns() []string {
+       return []string{urns.TransformParDo}
+}
+
+// PrepareTransform handles special processing with respect to ParDos, since 
their handling is dependant on supported features
+// and requirements.
+func (h *pardo) PrepareTransform(tid string, t *pipepb.PTransform, comps 
*pipepb.Components) (*pipepb.Components, []string) {
+
+       // ParDos are a pain in the butt.
+       // Combines, by comparison, are dramatically simpler.
+       // This is because for ParDos, how they are handled, and what kinds of 
transforms are in
+       // and around the ParDo, the actual shape of the graph will change.
+       // At their simplest, it's something a DoFn will handle on their own.
+       // At their most complex, they require intimate interaction with the 
subgraph
+       // bundling process, the data layer, state layers, and control layers.
+       // But unlike combines, which have a clear urn for composite + special 
payload,
+       // ParDos have the standard URN for composites with the standard 
payload.
+       // So always, we need to first unmarshal the payload.
+
+       pardoPayload := t.GetSpec().GetPayload()
+       pdo := &pipepb.ParDoPayload{}
+       if err := (proto.UnmarshalOptions{}).Unmarshal(pardoPayload, pdo); err 
!= nil {
+               panic(fmt.Sprintf("unable to decode ParDoPayload for 
transform[%v]", t.GetUniqueName()))
+       }
+
+       // Lets check for and remove anything that makes things less simple.
+       if pdo.OnWindowExpirationTimerFamilySpec == "" &&
+               !pdo.RequestsFinalization &&
+               !pdo.RequiresStableInput &&
+               !pdo.RequiresTimeSortedInput &&
+               //      len(pdo.SideInputs) == 0 &&

Review Comment:
   Should this still be here?



##########
sdks/go/pkg/beam/runners/prism/internal/handlerunner.go:
##########
@@ -0,0 +1,298 @@
+// 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 internal
+
+import (
+       "bytes"
+       "fmt"
+       "io"
+       "reflect"
+       "sort"
+
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/coder"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/mtime"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/window"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/exec"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
+       pipepb "github.com/apache/beam/sdks/v2/go/pkg/beam/model/pipeline_v1"
+       
"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/engine"
+       "github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/urns"
+       
"github.com/apache/beam/sdks/v2/go/pkg/beam/runners/prism/internal/worker"
+       "golang.org/x/exp/slog"
+       "google.golang.org/protobuf/encoding/prototext"
+       "google.golang.org/protobuf/proto"
+)
+
+// This file retains the logic for the pardo handler
+
+// RunnerCharacteristic holds the configuration for Runner based transforms,
+// such as GBKs, Flattens.
+type RunnerCharacteristic struct {
+       SDKFlatten bool // Sets whether we should force an SDK side flatten.
+       SDKGBK     bool // Sets whether the GBK should be handled by the SDK, 
if possible by the SDK.
+}
+
+func Runner(config any) *runner {

Review Comment:
   The `Combine()`, `ParDo()` and `Runner()` functions are exported with an 
unexported return type, but you might have an intention with this?



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

Reply via email to