damccorm commented on code in PR #26861: URL: https://github.com/apache/beam/pull/26861#discussion_r1242203026
########## learning/tour-of-beam/learning-content/final-challenge/final-challenge-2/go-solution/main.go: ########## @@ -0,0 +1,185 @@ +/* + * 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. + */ + +// beam-playground: +// name: FinalSolution2 +// description: Final challenge solution 2. +// multifile: true +// files: +// - name: analysis.csv +// context_line: 54 +// categories: +// - Quickstart +// complexity: ADVANCED +// tags: +// - hellobeam + +package main + +import ( + "context" + "fmt" + "strings" + "time" + + "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/window" + "github.com/apache/beam/sdks/v2/go/pkg/beam/core/graph/window/trigger" + "github.com/apache/beam/sdks/v2/go/pkg/beam" + "github.com/apache/beam/sdks/v2/go/pkg/beam/io/textio" + "github.com/apache/beam/sdks/v2/go/pkg/beam/log" + "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter" + "github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/stats" + "github.com/apache/beam/sdks/v2/go/pkg/beam/x/beamx" + "github.com/apache/beam/sdks/v2/go/pkg/beam/x/debug" +) + +type Analysis struct { + Word string + Negative string + Positive string + Uncertainty string + Litigious string + Strong string + Weak string + Constraining string +} + +func (a Analysis) toString() string { + return fmt.Sprintf("Word: %s, Negative: %s, Positive: %s, Uncertainty: %s, Litigious: %s, Strong: %s, Weak: %s, Constraining: %s", + a.Word, a.Negative, a.Positive, a.Uncertainty, a.Litigious, a.Strong, a.Weak, a.Constraining) +} + +func main() { + + ctx := context.Background() + + beam.Init() + + p := beam.NewPipeline() + s := p.Root() + + shakespeare := textio.Read(s, "gs://apache-beam-samples/shakespeare/kinglear.txt") + shakespeareWords := getWords(s, shakespeare) + analysis := textio.Read(s, "analysis.csv") + analysisRecords := parseAnalysis(s, analysis) + + trigger := trigger.AfterEndOfWindow(). + EarlyFiring(trigger.AfterProcessingTime(). + PlusDelay(5 * time.Second)) + + fixedWindowedItems := beam.WindowInto(s, window.NewFixedWindows(30*time.Second), shakespeareWords, + beam.Trigger(trigger), + beam.AllowedLateness(30*time.Second), + beam.PanesDiscard(), + ) Review Comment: > If the file is large, divide it into parts and do calculations for each portion. If the file is too large, Beam will automatically handle splitting the count with combiner lifting (doing the combine function with a subset of the words, then combining those results on the eventual target machine). So this shouldn't be an issue. > And a good case of using a "non global-window" with other transformers, since they cause different solutions to the problem. I don't think we should force this since it doesn't really fit the use case. I'd prefer we not do this windowing. If we're going to do it, it should be explicitly called out as a requirement in the challenge. -- 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]
