[
https://issues.apache.org/jira/browse/BEAM-12548?focusedWorklogId=621085&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-621085
]
ASF GitHub Bot logged work on BEAM-12548:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 09/Jul/21 17:18
Start Date: 09/Jul/21 17:18
Worklog Time Spent: 10m
Work Description: lostluck commented on a change in pull request #15136:
URL: https://github.com/apache/beam/pull/15136#discussion_r667100654
##########
File path: sdks/go/pkg/beam/testing/passert/floats.go
##########
@@ -0,0 +1,63 @@
+// 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 passert
+
+import (
+ "fmt"
+ "reflect"
+ "strings"
+
+ "github.com/apache/beam/sdks/go/pkg/beam"
+ "github.com/apache/beam/sdks/go/pkg/beam/core/util/reflectx"
+ "github.com/apache/beam/sdks/go/pkg/beam/internal/errors"
+)
+
+// AllWithinBounds checks that a PCollection of numeric types is within the
bounds
+// [lo, high]. Checks for case where bounds are flipped and swaps them so the
bounds
+// passed to the doFn are always lo <= hi.
+func AllWithinBounds(s beam.Scope, col beam.PCollection, lo, hi float64) {
+ t := beam.ValidateNonCompositeType(col)
+ if !reflectx.IsNumber(t.Type()) || reflectx.IsComplex(t.Type()) {
+ panic(fmt.Sprintf("type must be a non-complex number: %v", t))
+ }
+ if lo > hi {
+ lo, hi = hi, lo
+ }
+ s = s.Scope(fmt.Sprintf("passert.AllWithinBounds([%v, %v])", lo, hi))
+ beam.ParDo0(s, &boundsFn{lo: lo, hi: hi}, beam.Impulse(s),
beam.SideInput{Input: col})
+}
+
+type boundsFn struct {
+ lo, hi float64
+}
+
+func (f *boundsFn) ProcessElement(_ []byte, col func(*beam.T) bool) error {
+ errorStrings := []string{}
+ var input beam.T
+ for col(&input) {
+ val :=
reflect.ValueOf(input.(interface{})).Convert(reflectx.Float64).Interface().(float64)
+ if val < f.lo {
+ errorStrings = append(errorStrings, fmt.Sprintf("value
%v too low", input))
+ } else if val > f.hi {
+ errorStrings = append(errorStrings, fmt.Sprintf("value
%v too high", input))
Review comment:
Pre-doing the error strings like this will lead to very verbose and tall
error messages. Also, since PCollections are in arbitrary orders, no-two runs
are guaranteed to be the same, which makes it harder to read the messages or
when debugging a specific issue.
Consider instead keeping two slices `var tooLow, tooHigh []float64` and
appending qualifying values to them. Then, sort the two lists so the error
messages are deterministic. And then only include the low/high if the slice is
non empty. Eg for low: say they were too low, what the low threshold was, then
print the slice of values. It's OK if they're all float converted at this point.
This is more verbose in the single bad value case, but makes the affected
bound clear, and is far more readable in the multiple value case.
--
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: 621085)
Time Spent: 5h (was: 4h 50m)
> [Go SDK] PAssert improvements
> -----------------------------
>
> Key: BEAM-12548
> URL: https://issues.apache.org/jira/browse/BEAM-12548
> Project: Beam
> Issue Type: Improvement
> Components: sdk-go
> Reporter: Robert Burke
> Assignee: Jack McCluskey
> Priority: P2
> Time Spent: 5h
> Remaining Estimate: 0h
>
> The Go SDK Passert package could be more helpful.
> It could haveĀ GoDoc examples for correct and less clear use of each of the
> functions (like both the variadic and PCollection approaches forĀ
> passert.Equals).
> There could be better/more sophisticated handling for floating point values,
> eg with thresholds.
> There could be special/magic handling for synthetic KV types that could then
> be used for handling Equals against KV PCollections.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)