{"action":"created","comment":{"url":"https://api.github.com/repos/apache/beam/pulls/comments/103357478","pull_request_review_id":24140930,"id":103357478,"diff_hunk":"@@ -0,0 +1,157 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.apache.beam.runners.flink.translation.functions;\n+\n+import com.google.common.collect.Iterables;\n+import com.google.common.collect.Lists;\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.Comparator;\n+import java.util.Iterator;\n+import java.util.Map;\n+import org.apache.beam.runners.core.DoFnRunner;\n+import org.apache.beam.runners.core.DoFnRunners;\n+import org.apache.beam.runners.core.InMemoryStateInternals;\n+import org.apache.beam.runners.core.StateInternals;\n+import org.apache.beam.runners.flink.translation.utils.SerializedPipelineOptions;\n+import org.apache.beam.sdk.options.PipelineOptions;\n+import org.apache.beam.sdk.transforms.DoFn;\n+import org.apache.beam.sdk.transforms.ParDo;\n+import org.apache.beam.sdk.transforms.reflect.DoFnInvoker;\n+import org.apache.beam.sdk.transforms.reflect.DoFnInvokers;\n+import org.apache.beam.sdk.util.WindowedValue;\n+import org.apache.beam.sdk.util.WindowingStrategy;\n+import org.apache.beam.sdk.values.KV;\n+import org.apache.beam.sdk.values.PCollectionView;\n+import org.apache.beam.sdk.values.TupleTag;\n+import org.apache.flink.api.common.functions.RichGroupReduceFunction;\n+import org.apache.flink.api.common.functions.RuntimeContext;\n+import org.apache.flink.configuration.Configuration;\n+import org.apache.flink.util.Collector;\n+\n+/**\n+ * A {@link RichGroupReduceFunction} for stateful {@link ParDo} in Flink Batch Runner.\n+ */\n+public class FlinkStatefulDoFnFunction<K, V, OutputT>\n+    extends RichGroupReduceFunction<WindowedValue<KV<K, V>>, WindowedValue<OutputT>> {\n+\n+  private final DoFn<KV<K, V>, OutputT> dofn;\n+  private final WindowingStrategy<?, ?> windowingStrategy;\n+  private final Map<PCollectionView<?>, WindowingStrategy<?, ?>> sideInputs;\n+  private final SerializedPipelineOptions serializedOptions;\n+  private final Map<TupleTag<?>, Integer> outputMap;\n+  private final TupleTag<OutputT> mainOutputTag;\n+  private transient DoFnInvoker doFnInvoker;\n+\n+  public FlinkStatefulDoFnFunction(\n+      DoFn<KV<K, V>, OutputT> dofn,\n+      WindowingStrategy<?, ?> windowingStrategy,\n+      Map<PCollectionView<?>, WindowingStrategy<?, ?>> sideInputs,\n+      PipelineOptions pipelineOptions,\n+      Map<TupleTag<?>, Integer> outputMap,\n+      TupleTag<OutputT> mainOutputTag) {\n+\n+    this.dofn = dofn;\n+    this.windowingStrategy = windowingStrategy;\n+    this.sideInputs = sideInputs;\n+    this.serializedOptions = new SerializedPipelineOptions(pipelineOptions);\n+    this.outputMap = outputMap;\n+    this.mainOutputTag = mainOutputTag;\n+  }\n+\n+  @Override\n+  public void reduce(\n+      Iterable<WindowedValue<KV<K, V>>> values,\n+      Collector<WindowedValue<OutputT>> out) throws Exception {\n+    RuntimeContext runtimeContext = getRuntimeContext();\n+\n+    DoFnRunners.OutputManager outputManager;\n+    if (outputMap == null) {\n+      outputManager = new FlinkDoFnFunction.DoFnOutputManager(out);\n+    } else {\n+      // it has some sideOutputs\n+      outputManager =\n+          new FlinkDoFnFunction.MultiDoFnOutputManager((Collector) out, outputMap);\n+    }\n+\n+    // get all elements so that we can sort them, has to fit into memory","path":"runners/flink/runner/src/main/java/org/apache/beam/runners/flink/translation/functions/FlinkStatefulDoFnFunction.java","position":92,"original_position":92,"commit_id":"879aacfba54c9771f624f271298393d829ea5e5b","original_commit_id":"879aacfba54c9771f624f271298393d829ea5e5b","user":{"login":"JingsongLi","id":9601882,"avatar_url":"https://avatars.githubusercontent.com/u/9601882?v=3","gravatar_id":"","url":"https://api.github.com/users/JingsongLi","html_url":"https://github.com/JingsongLi","followers_url":"https://api.github.com/users/JingsongLi/followers","following_url":"https://api.github.com/users/JingsongLi/following{/other_user}","gists_url":"https://api.github.com/users/JingsongLi/gists{/gist_id}","starred_url":"https://api.github.com/users/JingsongLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JingsongLi/subscriptions","organizations_url":"https://api.github.com/users/JingsongLi/orgs","repos_url":"https://api.github.com/users/JingsongLi/repos","events_url":"https://api.github.com/users/JingsongLi/events{/privacy}","received_events_url":"https://api.github.com/users/JingsongLi/received_events","type":"User","site_admin":false},"body":"Yes, you are right. My oldest idea was to create a per-window StateInternals to faster GC. But in most scenes it should be useless, because the state is not so big.\r\n","created_at":"2017-02-28T01:33:49Z","updated_at":"2017-02-28T01:33:49Z","html_url":"https://github.com/apache/beam/pull/2114#discussion_r103357478","pull_request_url":"https://api.github.com/repos/apache/beam/pulls/2114","_links":{"self":{"href":"https://api.github.com/repos/apache/beam/pulls/comments/103357478"},"html":{"href":"https://github.com/apache/beam/pull/2114#discussion_r103357478"},"pull_request":{"href":"https://api.github.com/repos/apache/beam/pulls/2114"}}},"pull_request":{"url":"https://api.github.com/repos/apache/beam/pulls/2114","id":108169875,"html_url":"https://github.com/apache/beam/pull/2114","diff_url":"https://github.com/apache/beam/pull/2114.diff","patch_url":"https://github.com/apache/beam/pull/2114.patch","issue_url":"https://api.github.com/repos/apache/beam/issues/2114","number":2114,"state":"open","locked":false,"title":"[BEAM-1036] Support for new State API in Flink Batch Runner","user":{"login":"JingsongLi","id":9601882,"avatar_url":"https://avatars.githubusercontent.com/u/9601882?v=3","gravatar_id":"","url":"https://api.github.com/users/JingsongLi","html_url":"https://github.com/JingsongLi","followers_url":"https://api.github.com/users/JingsongLi/followers","following_url":"https://api.github.com/users/JingsongLi/following{/other_user}","gists_url":"https://api.github.com/users/JingsongLi/gists{/gist_id}","starred_url":"https://api.github.com/users/JingsongLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JingsongLi/subscriptions","organizations_url":"https://api.github.com/users/JingsongLi/orgs","repos_url":"https://api.github.com/users/JingsongLi/repos","events_url":"https://api.github.com/users/JingsongLi/events{/privacy}","received_events_url":"https://api.github.com/users/JingsongLi/received_events","type":"User","site_admin":false},"body":"Be sure to do all of the following to help us incorporate your contribution\r\nquickly and easily:\r\n\r\n - [ ] Make sure the PR title is formatted like:\r\n   `[BEAM-<Jira issue #>] Description of pull request`\r\n - [ ] Make sure tests pass via `mvn clean verify`. (Even better, enable\r\n       Travis-CI on your fork and ensure the whole test matrix passes).\r\n - [ ] Replace `<Jira issue #>` in the title with the actual Jira issue\r\n       number, if there is one.\r\n - [ ] If this contribution is large, please file an Apache\r\n       [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.txt).\r\n\r\n---\r\n","created_at":"2017-02-27T18:08:37Z","updated_at":"2017-02-28T01:33:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"334e21e281752389ed7f28042cffce169a36a7b8","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/beam/pulls/2114/commits","review_comments_url":"https://api.github.com/repos/apache/beam/pulls/2114/comments","review_comment_url":"https://api.github.com/repos/apache/beam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/beam/issues/2114/comments","statuses_url":"https://api.github.com/repos/apache/beam/statuses/879aacfba54c9771f624f271298393d829ea5e5b","head":{"label":"JingsongLi:BEAM-1036-batch","ref":"BEAM-1036-batch","sha":"879aacfba54c9771f624f271298393d829ea5e5b","user":{"login":"JingsongLi","id":9601882,"avatar_url":"https://avatars.githubusercontent.com/u/9601882?v=3","gravatar_id":"","url":"https://api.github.com/users/JingsongLi","html_url":"https://github.com/JingsongLi","followers_url":"https://api.github.com/users/JingsongLi/followers","following_url":"https://api.github.com/users/JingsongLi/following{/other_user}","gists_url":"https://api.github.com/users/JingsongLi/gists{/gist_id}","starred_url":"https://api.github.com/users/JingsongLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JingsongLi/subscriptions","organizations_url":"https://api.github.com/users/JingsongLi/orgs","repos_url":"https://api.github.com/users/JingsongLi/repos","events_url":"https://api.github.com/users/JingsongLi/events{/privacy}","received_events_url":"https://api.github.com/users/JingsongLi/received_events","type":"User","site_admin":false},"repo":{"id":80848315,"name":"beam","full_name":"JingsongLi/beam","owner":{"login":"JingsongLi","id":9601882,"avatar_url":"https://avatars.githubusercontent.com/u/9601882?v=3","gravatar_id":"","url":"https://api.github.com/users/JingsongLi","html_url":"https://github.com/JingsongLi","followers_url":"https://api.github.com/users/JingsongLi/followers","following_url":"https://api.github.com/users/JingsongLi/following{/other_user}","gists_url":"https://api.github.com/users/JingsongLi/gists{/gist_id}","starred_url":"https://api.github.com/users/JingsongLi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JingsongLi/subscriptions","organizations_url":"https://api.github.com/users/JingsongLi/orgs","repos_url":"https://api.github.com/users/JingsongLi/repos","events_url":"https://api.github.com/users/JingsongLi/events{/privacy}","received_events_url":"https://api.github.com/users/JingsongLi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JingsongLi/beam","description":"Mirror of Apache Beam","fork":true,"url":"https://api.github.com/repos/JingsongLi/beam","forks_url":"https://api.github.com/repos/JingsongLi/beam/forks","keys_url":"https://api.github.com/repos/JingsongLi/beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JingsongLi/beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JingsongLi/beam/teams","hooks_url":"https://api.github.com/repos/JingsongLi/beam/hooks","issue_events_url":"https://api.github.com/repos/JingsongLi/beam/issues/events{/number}","events_url":"https://api.github.com/repos/JingsongLi/beam/events","assignees_url":"https://api.github.com/repos/JingsongLi/beam/assignees{/user}","branches_url":"https://api.github.com/repos/JingsongLi/beam/branches{/branch}","tags_url":"https://api.github.com/repos/JingsongLi/beam/tags","blobs_url":"https://api.github.com/repos/JingsongLi/beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JingsongLi/beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JingsongLi/beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/JingsongLi/beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JingsongLi/beam/statuses/{sha}","languages_url":"https://api.github.com/repos/JingsongLi/beam/languages","stargazers_url":"https://api.github.com/repos/JingsongLi/beam/stargazers","contributors_url":"https://api.github.com/repos/JingsongLi/beam/contributors","subscribers_url":"https://api.github.com/repos/JingsongLi/beam/subscribers","subscription_url":"https://api.github.com/repos/JingsongLi/beam/subscription","commits_url":"https://api.github.com/repos/JingsongLi/beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/JingsongLi/beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/JingsongLi/beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/JingsongLi/beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/JingsongLi/beam/contents/{+path}","compare_url":"https://api.github.com/repos/JingsongLi/beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JingsongLi/beam/merges","archive_url":"https://api.github.com/repos/JingsongLi/beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JingsongLi/beam/downloads","issues_url":"https://api.github.com/repos/JingsongLi/beam/issues{/number}","pulls_url":"https://api.github.com/repos/JingsongLi/beam/pulls{/number}","milestones_url":"https://api.github.com/repos/JingsongLi/beam/milestones{/number}","notifications_url":"https://api.github.com/repos/JingsongLi/beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JingsongLi/beam/labels{/name}","releases_url":"https://api.github.com/repos/JingsongLi/beam/releases{/id}","deployments_url":"https://api.github.com/repos/JingsongLi/beam/deployments","created_at":"2017-02-03T16:45:04Z","updated_at":"2017-02-03T16:45:12Z","pushed_at":"2017-02-27T18:08:01Z","git_url":"git://github.com/JingsongLi/beam.git","ssh_url":"git@github.com:JingsongLi/beam.git","clone_url":"https://github.com/JingsongLi/beam.git","svn_url":"https://github.com/JingsongLi/beam","homepage":"","size":28877,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"063fbd4ed4ed34dece6490e791f0e5c91ec52895","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":50904245,"name":"beam","full_name":"apache/beam","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/beam","description":"Mirror of Apache Beam","fork":false,"url":"https://api.github.com/repos/apache/beam","forks_url":"https://api.github.com/repos/apache/beam/forks","keys_url":"https://api.github.com/repos/apache/beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/beam/teams","hooks_url":"https://api.github.com/repos/apache/beam/hooks","issue_events_url":"https://api.github.com/repos/apache/beam/issues/events{/number}","events_url":"https://api.github.com/repos/apache/beam/events","assignees_url":"https://api.github.com/repos/apache/beam/assignees{/user}","branches_url":"https://api.github.com/repos/apache/beam/branches{/branch}","tags_url":"https://api.github.com/repos/apache/beam/tags","blobs_url":"https://api.github.com/repos/apache/beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/beam/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/beam/languages","stargazers_url":"https://api.github.com/repos/apache/beam/stargazers","contributors_url":"https://api.github.com/repos/apache/beam/contributors","subscribers_url":"https://api.github.com/repos/apache/beam/subscribers","subscription_url":"https://api.github.com/repos/apache/beam/subscription","commits_url":"https://api.github.com/repos/apache/beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/beam/contents/{+path}","compare_url":"https://api.github.com/repos/apache/beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/beam/merges","archive_url":"https://api.github.com/repos/apache/beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/beam/downloads","issues_url":"https://api.github.com/repos/apache/beam/issues{/number}","pulls_url":"https://api.github.com/repos/apache/beam/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/beam/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/beam/labels{/name}","releases_url":"https://api.github.com/repos/apache/beam/releases{/id}","deployments_url":"https://api.github.com/repos/apache/beam/deployments","created_at":"2016-02-02T08:00:06Z","updated_at":"2017-02-27T21:46:01Z","pushed_at":"2017-02-28T01:32:23Z","git_url":"git://github.com/apache/beam.git","ssh_url":"git@github.com:apache/beam.git","clone_url":"https://github.com/apache/beam.git","svn_url":"https://github.com/apache/beam","homepage":"","size":28947,"stargazers_count":927,"watchers_count":927,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":483,"mirror_url":"git://git.apache.org/beam.git","open_issues_count":62,"forks":483,"open_issues":62,"watchers":927,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/beam/pulls/2114"},"html":{"href":"https://github.com/apache/beam/pull/2114"},"issue":{"href":"https://api.github.com/repos/apache/beam/issues/2114"},"comments":{"href":"https://api.github.com/repos/apache/beam/issues/2114/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/beam/pulls/2114/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/beam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/beam/pulls/2114/commits"},"statuses":{"href":"https://api.github.com/repos/apache/beam/statuses/879aacfba54c9771f624f271298393d829ea5e5b"}}}}
{"actor":{"display_login":"JingsongLi"}}