lostluck commented on a change in pull request #13889:
URL: https://github.com/apache/beam/pull/13889#discussion_r574021329



##########
File path: sdks/go/pkg/beam/transforms/stats/quantiles.go
##########
@@ -0,0 +1,710 @@
+// 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 stats
+
+// Approximate quantiles is implemented based on 
https://arxiv.org/pdf/1907.00236.pdf.
+
+import (
+       "bytes"
+       "container/heap"
+       "context"
+       "encoding/gob"
+       "encoding/json"
+       "hash/crc32"
+       "io"
+       "math"
+       "reflect"
+       "sort"
+
+       "github.com/apache/beam/sdks/go/pkg/beam"
+       "github.com/apache/beam/sdks/go/pkg/beam/core/util/reflectx"
+)
+
+func init() {
+       compactorsType := reflect.TypeOf((**compactors)(nil)).Elem()
+       weightedElementType := reflect.TypeOf((*weightedElement)(nil)).Elem()
+       beam.RegisterType(compactorsType)
+       beam.RegisterType(weightedElementType)
+       
beam.RegisterType(reflect.TypeOf((*approximateQuantilesInputFn)(nil)).Elem())
+       
beam.RegisterType(reflect.TypeOf((*approximateQuantilesMergeOnlyFn)(nil)).Elem())
+       
beam.RegisterType(reflect.TypeOf((*approximateQuantilesOutputFn)(nil)).Elem())
+       beam.RegisterType(reflect.TypeOf((*shardElementsFn)(nil)).Elem())
+       beam.RegisterCoder(compactorsType, encodeCompactors, decodeCompactors)
+       beam.RegisterCoder(weightedElementType, encodeWeightedElement, 
decodeWeightedElement)
+}
+
+// Opts contains settings used to configure how approximate quantiles are 
computed.
+type Opts struct {
+       // Controls the memory used and approximation error (difference between 
the quantile returned and the true quantile.)
+       K int
+       // Number of quantiles to return. The algorithm will return 
NumQuantiles - 1 numbers
+       NumQuantiles int
+       // For extremely large datasets, runners may have issues with out of 
memory errors or taking too long to finish.
+       // If ApproximateQuantiles is failing, you can use this option to tune 
how the data is sharded internally.
+       // This parameter is optional. If unspecified, Beam will compact all 
elements into a single compactor at once using a single machine.

Review comment:
       I think the only issue I have with this comment is that it doesn't have 
an intuitive use. Consider explaining or have a small example of what a given 
slice will do to change the behavior of the DoFns.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to