{"action":"created","comment":{"url":"https://api.github.com/repos/crate/crate/pulls/comments/152995885","pull_request_review_id":78947070,"id":152995885,"diff_hunk":"@@ -0,0 +1,170 @@\n+/*\n+ * Licensed to Crate under one or more contributor license agreements.\n+ * See the NOTICE file distributed with this work for additional\n+ * information regarding copyright ownership.  Crate licenses this file\n+ * to you under the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.  You may\n+ * 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\n+ * implied.  See the License for the specific language governing\n+ * permissions and limitations under the License.\n+ *\n+ * However, if you have executed another commercial license agreement\n+ * with Crate these terms will supersede the license and you may use the\n+ * software solely pursuant to the terms of the relevant commercial\n+ * agreement.\n+ */\n+\n+package io.crate.planner;\n+\n+import com.google.common.base.Preconditions;\n+import io.crate.planner.distribution.DistributionInfo;\n+import io.crate.planner.node.dql.MergePhase;\n+import io.crate.planner.projection.Projection;\n+import io.crate.types.DataType;\n+\n+import javax.annotation.Nullable;\n+import java.util.Collection;\n+import java.util.List;\n+import java.util.UUID;\n+\n+/**\n+ * Plan for Union which uses a MergePhase to combine the results of two plans (= two inputs).\n+ */\n+public class UnionPlan implements Plan, ResultDescription {\n+\n+    private final Plan left;\n+    private final Plan right;\n+\n+    private final MergePhase mergePhase;\n+\n+    private int unfinishedLimit;\n+    private int unfinishedOffset;\n+    private int numOutputs;\n+\n+    private final int maxRowsPerNode;\n+\n+    @Nullable\n+    private PositionalOrderBy orderBy;\n+\n+    /**\n+     * Create a Union Plan\n+     *\n+     * @param unfinishedLimit the limit a parent must apply after a merge to get the correct result\n+     * @param unfinishedOffset the offset a parent must apply after a merge to get the correct result\n+     *\n+     * If the data should be limited as part of the Merge, add a {@link io.crate.planner.projection.TopNProjection},\n+     * if possible. If the limit of the TopNProjection is final, unfinishedLimit here should be set to NO_LIMIT (-1)\n+     *\n+     * See also: {@link ResultDescription}\n+     *\n+     */\n+    public UnionPlan(Plan left,\n+                     Plan right,\n+                     MergePhase mergePhase,\n+                     int unfinishedLimit,\n+                     int unfinishedOffset,\n+                     int numOutputs,\n+                     int maxRowsPerNode) {\n+        this.left = left;\n+        this.right = right;\n+        Preconditions.checkArgument(mergePhase.numInputs() == 2,\n+            \"Number of inputs of MergePhase needs to be two.\");\n+        this.mergePhase = mergePhase;\n+        this.unfinishedLimit = unfinishedLimit;\n+        this.unfinishedOffset = unfinishedOffset;\n+        this.numOutputs = numOutputs;\n+        this.maxRowsPerNode = maxRowsPerNode;\n+    }\n+\n+    @Override\n+    public <C, R> R accept(PlanVisitor<C, R> visitor, C context) {\n+        return visitor.visitUnionPlan(this, context);\n+    }\n+\n+    @Override\n+    public UUID jobId() {\n+        return mergePhase.jobId();\n+    }\n+\n+    @Override\n+    public void addProjection(Projection projection) {\n+        mergePhase.addProjection(projection);\n+        numOutputs = projection.outputs().size();\n+    }\n+\n+    @Override\n+    public void addProjection(Projection projection,\n+                              int unfinishedLimit,\n+                              int unfinishedOffset,\n+                              @Nullable PositionalOrderBy unfinishedOrderBy) {\n+        addProjection(projection);\n+        this.unfinishedLimit = unfinishedLimit;\n+        this.unfinishedOffset = unfinishedOffset;\n+        this.orderBy = unfinishedOrderBy;\n+    }\n+\n+    @Override\n+    public ResultDescription resultDescription() {\n+        return this;\n+    }\n+\n+    @Override\n+    public void setDistributionInfo(DistributionInfo distributionInfo) {\n+        mergePhase.distributionInfo(distributionInfo);\n+    }\n+\n+    public MergePhase mergePhase() {","path":"sql/src/main/java/io/crate/planner/UnionPlan.java","position":122,"original_position":122,"commit_id":"34df022fc273b729f48d6ace2914a1ad1bdcf709","original_commit_id":"b00f1e4d95e18c6a827084c86eacddec3aca044c","user":{"login":"matriv","id":5058131,"avatar_url":"https://avatars1.githubusercontent.com/u/5058131?v=4","gravatar_id":"","url":"https://api.github.com/users/matriv","html_url":"https://github.com/matriv","followers_url":"https://api.github.com/users/matriv/followers","following_url":"https://api.github.com/users/matriv/following{/other_user}","gists_url":"https://api.github.com/users/matriv/gists{/gist_id}","starred_url":"https://api.github.com/users/matriv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matriv/subscriptions","organizations_url":"https://api.github.com/users/matriv/orgs","repos_url":"https://api.github.com/users/matriv/repos","events_url":"https://api.github.com/users/matriv/events{/privacy}","received_events_url":"https://api.github.com/users/matriv/received_events","type":"User","site_admin":false},"body":"very Minor: I would move these 3 methods to the end to keep all the Overriden methods together","created_at":"2017-11-24T15:50:13Z","updated_at":"2017-11-24T15:50:13Z","html_url":"https://github.com/crate/crate/pull/6535#discussion_r152995885","pull_request_url":"https://api.github.com/repos/crate/crate/pulls/6535","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/crate/crate/pulls/comments/152995885"},"html":{"href":"https://github.com/crate/crate/pull/6535#discussion_r152995885"},"pull_request":{"href":"https://api.github.com/repos/crate/crate/pulls/6535"}}},"pull_request":{"url":"https://api.github.com/repos/crate/crate/pulls/6535","id":152570103,"html_url":"https://github.com/crate/crate/pull/6535","diff_url":"https://github.com/crate/crate/pull/6535.diff","patch_url":"https://github.com/crate/crate/pull/6535.patch","issue_url":"https://api.github.com/repos/crate/crate/issues/6535","number":6535,"state":"open","locked":false,"title":"Implement Planner support for Union ALL ","user":{"login":"mxm","id":837221,"avatar_url":"https://avatars1.githubusercontent.com/u/837221?v=4","gravatar_id":"","url":"https://api.github.com/users/mxm","html_url":"https://github.com/mxm","followers_url":"https://api.github.com/users/mxm/followers","following_url":"https://api.github.com/users/mxm/following{/other_user}","gists_url":"https://api.github.com/users/mxm/gists{/gist_id}","starred_url":"https://api.github.com/users/mxm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxm/subscriptions","organizations_url":"https://api.github.com/users/mxm/orgs","repos_url":"https://api.github.com/users/mxm/repos","events_url":"https://api.github.com/users/mxm/events{/privacy}","received_events_url":"https://api.github.com/users/mxm/received_events","type":"User","site_admin":false},"body":"The Union ALL planner support uses a `Union` operator in the `LogicalPlanner`\r\nwhich generates a `UnionPlan`. The plan consists of a sub plan for each side of\r\nthe union. When the union is planned, both sides are executed as a branch of the\r\nexecution tree. The result is fed to the `MergePhase` which receives data from\r\nboth sub plans and merges them into buckets encoded by the node id and the input\r\nid set during planning.\r\n\r\nIn `MergePhase` the number of different inputs was added to ensure that a merge\r\nwith multiple inputs can be detected. The input id is encoded at the beginning\r\nof the 32bit bucket id.","created_at":"2017-11-14T17:34:22Z","updated_at":"2017-11-24T15:50:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"87d7d734d33455e3cb5a4977bd58b6b8a19e1e7a","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/crate/crate/pulls/6535/commits","review_comments_url":"https://api.github.com/repos/crate/crate/pulls/6535/comments","review_comment_url":"https://api.github.com/repos/crate/crate/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crate/crate/issues/6535/comments","statuses_url":"https://api.github.com/repos/crate/crate/statuses/34df022fc273b729f48d6ace2914a1ad1bdcf709","head":{"label":"crate:mxm/union-planner","ref":"mxm/union-planner","sha":"34df022fc273b729f48d6ace2914a1ad1bdcf709","user":{"login":"crate","id":4048232,"avatar_url":"https://avatars3.githubusercontent.com/u/4048232?v=4","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"repo":{"id":9342529,"name":"crate","full_name":"crate/crate","owner":{"login":"crate","id":4048232,"avatar_url":"https://avatars3.githubusercontent.com/u/4048232?v=4","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crate/crate","description":"CrateDB is a distributed SQL database that makes it simple to store and analyze massive amounts of machine data in real-time.","fork":false,"url":"https://api.github.com/repos/crate/crate","forks_url":"https://api.github.com/repos/crate/crate/forks","keys_url":"https://api.github.com/repos/crate/crate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crate/crate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crate/crate/teams","hooks_url":"https://api.github.com/repos/crate/crate/hooks","issue_events_url":"https://api.github.com/repos/crate/crate/issues/events{/number}","events_url":"https://api.github.com/repos/crate/crate/events","assignees_url":"https://api.github.com/repos/crate/crate/assignees{/user}","branches_url":"https://api.github.com/repos/crate/crate/branches{/branch}","tags_url":"https://api.github.com/repos/crate/crate/tags","blobs_url":"https://api.github.com/repos/crate/crate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crate/crate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crate/crate/git/refs{/sha}","trees_url":"https://api.github.com/repos/crate/crate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crate/crate/statuses/{sha}","languages_url":"https://api.github.com/repos/crate/crate/languages","stargazers_url":"https://api.github.com/repos/crate/crate/stargazers","contributors_url":"https://api.github.com/repos/crate/crate/contributors","subscribers_url":"https://api.github.com/repos/crate/crate/subscribers","subscription_url":"https://api.github.com/repos/crate/crate/subscription","commits_url":"https://api.github.com/repos/crate/crate/commits{/sha}","git_commits_url":"https://api.github.com/repos/crate/crate/git/commits{/sha}","comments_url":"https://api.github.com/repos/crate/crate/comments{/number}","issue_comment_url":"https://api.github.com/repos/crate/crate/issues/comments{/number}","contents_url":"https://api.github.com/repos/crate/crate/contents/{+path}","compare_url":"https://api.github.com/repos/crate/crate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crate/crate/merges","archive_url":"https://api.github.com/repos/crate/crate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crate/crate/downloads","issues_url":"https://api.github.com/repos/crate/crate/issues{/number}","pulls_url":"https://api.github.com/repos/crate/crate/pulls{/number}","milestones_url":"https://api.github.com/repos/crate/crate/milestones{/number}","notifications_url":"https://api.github.com/repos/crate/crate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crate/crate/labels{/name}","releases_url":"https://api.github.com/repos/crate/crate/releases{/id}","deployments_url":"https://api.github.com/repos/crate/crate/deployments","created_at":"2013-04-10T09:17:16Z","updated_at":"2017-11-24T13:28:27Z","pushed_at":"2017-11-24T15:46:09Z","git_url":"git://github.com/crate/crate.git","ssh_url":"git@github.com:crate/crate.git","clone_url":"https://github.com/crate/crate.git","svn_url":"https://github.com/crate/crate","homepage":"https://crate.io","size":81891,"stargazers_count":1842,"watchers_count":1842,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":237,"mirror_url":null,"archived":false,"open_issues_count":81,"forks":237,"open_issues":81,"watchers":1842,"default_branch":"master"}},"base":{"label":"crate:union-new","ref":"union-new","sha":"1e8eaa25314cddbb5580cfc50c612a87f89698f2","user":{"login":"crate","id":4048232,"avatar_url":"https://avatars3.githubusercontent.com/u/4048232?v=4","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"repo":{"id":9342529,"name":"crate","full_name":"crate/crate","owner":{"login":"crate","id":4048232,"avatar_url":"https://avatars3.githubusercontent.com/u/4048232?v=4","gravatar_id":"","url":"https://api.github.com/users/crate","html_url":"https://github.com/crate","followers_url":"https://api.github.com/users/crate/followers","following_url":"https://api.github.com/users/crate/following{/other_user}","gists_url":"https://api.github.com/users/crate/gists{/gist_id}","starred_url":"https://api.github.com/users/crate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crate/subscriptions","organizations_url":"https://api.github.com/users/crate/orgs","repos_url":"https://api.github.com/users/crate/repos","events_url":"https://api.github.com/users/crate/events{/privacy}","received_events_url":"https://api.github.com/users/crate/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crate/crate","description":"CrateDB is a distributed SQL database that makes it simple to store and analyze massive amounts of machine data in real-time.","fork":false,"url":"https://api.github.com/repos/crate/crate","forks_url":"https://api.github.com/repos/crate/crate/forks","keys_url":"https://api.github.com/repos/crate/crate/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crate/crate/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crate/crate/teams","hooks_url":"https://api.github.com/repos/crate/crate/hooks","issue_events_url":"https://api.github.com/repos/crate/crate/issues/events{/number}","events_url":"https://api.github.com/repos/crate/crate/events","assignees_url":"https://api.github.com/repos/crate/crate/assignees{/user}","branches_url":"https://api.github.com/repos/crate/crate/branches{/branch}","tags_url":"https://api.github.com/repos/crate/crate/tags","blobs_url":"https://api.github.com/repos/crate/crate/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crate/crate/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crate/crate/git/refs{/sha}","trees_url":"https://api.github.com/repos/crate/crate/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crate/crate/statuses/{sha}","languages_url":"https://api.github.com/repos/crate/crate/languages","stargazers_url":"https://api.github.com/repos/crate/crate/stargazers","contributors_url":"https://api.github.com/repos/crate/crate/contributors","subscribers_url":"https://api.github.com/repos/crate/crate/subscribers","subscription_url":"https://api.github.com/repos/crate/crate/subscription","commits_url":"https://api.github.com/repos/crate/crate/commits{/sha}","git_commits_url":"https://api.github.com/repos/crate/crate/git/commits{/sha}","comments_url":"https://api.github.com/repos/crate/crate/comments{/number}","issue_comment_url":"https://api.github.com/repos/crate/crate/issues/comments{/number}","contents_url":"https://api.github.com/repos/crate/crate/contents/{+path}","compare_url":"https://api.github.com/repos/crate/crate/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crate/crate/merges","archive_url":"https://api.github.com/repos/crate/crate/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crate/crate/downloads","issues_url":"https://api.github.com/repos/crate/crate/issues{/number}","pulls_url":"https://api.github.com/repos/crate/crate/pulls{/number}","milestones_url":"https://api.github.com/repos/crate/crate/milestones{/number}","notifications_url":"https://api.github.com/repos/crate/crate/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crate/crate/labels{/name}","releases_url":"https://api.github.com/repos/crate/crate/releases{/id}","deployments_url":"https://api.github.com/repos/crate/crate/deployments","created_at":"2013-04-10T09:17:16Z","updated_at":"2017-11-24T13:28:27Z","pushed_at":"2017-11-24T15:46:09Z","git_url":"git://github.com/crate/crate.git","ssh_url":"git@github.com:crate/crate.git","clone_url":"https://github.com/crate/crate.git","svn_url":"https://github.com/crate/crate","homepage":"https://crate.io","size":81891,"stargazers_count":1842,"watchers_count":1842,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":237,"mirror_url":null,"archived":false,"open_issues_count":81,"forks":237,"open_issues":81,"watchers":1842,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crate/crate/pulls/6535"},"html":{"href":"https://github.com/crate/crate/pull/6535"},"issue":{"href":"https://api.github.com/repos/crate/crate/issues/6535"},"comments":{"href":"https://api.github.com/repos/crate/crate/issues/6535/comments"},"review_comments":{"href":"https://api.github.com/repos/crate/crate/pulls/6535/comments"},"review_comment":{"href":"https://api.github.com/repos/crate/crate/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crate/crate/pulls/6535/commits"},"statuses":{"href":"https://api.github.com/repos/crate/crate/statuses/34df022fc273b729f48d6ace2914a1ad1bdcf709"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"matriv"}}