{"action":"created","comment":{"url":"https://api.github.com/repos/apache/calcite/pulls/comments/76840380","id":76840380,"diff_hunk":"@@ -0,0 +1,147 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to you under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * 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.calcite.rel.rules;\n+\n+import org.apache.calcite.plan.RelOptPredicateList;\n+import org.apache.calcite.plan.RelOptRule;\n+import org.apache.calcite.plan.RelOptRuleCall;\n+import org.apache.calcite.plan.RelOptUtil;\n+import org.apache.calcite.rel.RelNode;\n+import org.apache.calcite.rel.core.RelFactories;\n+import org.apache.calcite.rel.core.Union;\n+import org.apache.calcite.rel.metadata.RelMetadataQuery;\n+import org.apache.calcite.rel.type.RelDataTypeField;\n+import org.apache.calcite.rex.RexBuilder;\n+import org.apache.calcite.rex.RexNode;\n+import org.apache.calcite.rex.RexUtil;\n+import org.apache.calcite.tools.RelBuilder;\n+import org.apache.calcite.tools.RelBuilderFactory;\n+import org.apache.calcite.util.ImmutableBitSet;\n+import org.apache.calcite.util.Pair;\n+import org.apache.calcite.util.mapping.Mappings;\n+\n+import com.google.common.collect.ImmutableList;\n+\n+import java.util.ArrayList;\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+\n+/**\n+ * Planner rule that pulls up constants through a Union operator.\n+ */\n+public class UnionPullUpConstantsRule extends RelOptRule {\n+\n+  public static final UnionPullUpConstantsRule INSTANCE =\n+          new UnionPullUpConstantsRule(Union.class, RelFactories.LOGICAL_BUILDER);\n+\n+  protected UnionPullUpConstantsRule(\n+      Class<? extends Union> unionClass,\n+      RelBuilderFactory relBuilderFactory) {\n+    super(operand(unionClass, any()),\n+            relBuilderFactory, null);\n+  }\n+\n+  @Override public void onMatch(RelOptRuleCall call) {\n+    final Union union = call.rel(0);\n+\n+    final int count = union.getRowType().getFieldCount();\n+    if (count == 1) {\n+      // No room for optimization since we cannot create an empty\n+      // Project operator.\n+      return;\n+    }\n+","path":"core/src/main/java/org/apache/calcite/rel/rules/UnionPullUpConstantsRule.java","position":68,"original_position":68,"commit_id":"c2783f85a4c66493a369f087c8eb4ac302deb3f4","original_commit_id":"1447519b786c87c6a385cbd9fdfe4025c7f10fcd","user":{"login":"jcamachor","id":222949,"avatar_url":"https://avatars.githubusercontent.com/u/222949?v=3","gravatar_id":"","url":"https://api.github.com/users/jcamachor","html_url":"https://github.com/jcamachor","followers_url":"https://api.github.com/users/jcamachor/followers","following_url":"https://api.github.com/users/jcamachor/following{/other_user}","gists_url":"https://api.github.com/users/jcamachor/gists{/gist_id}","starred_url":"https://api.github.com/users/jcamachor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcamachor/subscriptions","organizations_url":"https://api.github.com/users/jcamachor/orgs","repos_url":"https://api.github.com/users/jcamachor/repos","events_url":"https://api.github.com/users/jcamachor/events{/privacy}","received_events_url":"https://api.github.com/users/jcamachor/received_events","type":"User","site_admin":false},"body":"I have just realized while running the testsuite that it also serves as a bail out condition so the rule is not triggered indefinitely. For instance, for the given query `select 1, 2 ... union all select 1, 2 ...`, the rule would continue firing, as there will always be a constant below the Union. Thus, it seems to me we need to leave the condition there.","created_at":"2016-08-30T17:25:45Z","updated_at":"2016-08-30T17:25:45Z","html_url":"https://github.com/apache/calcite/pull/275#discussion_r76840380","pull_request_url":"https://api.github.com/repos/apache/calcite/pulls/275","_links":{"self":{"href":"https://api.github.com/repos/apache/calcite/pulls/comments/76840380"},"html":{"href":"https://github.com/apache/calcite/pull/275#discussion_r76840380"},"pull_request":{"href":"https://api.github.com/repos/apache/calcite/pulls/275"}}},"pull_request":{"url":"https://api.github.com/repos/apache/calcite/pulls/275","id":83291339,"html_url":"https://github.com/apache/calcite/pull/275","diff_url":"https://github.com/apache/calcite/pull/275.diff","patch_url":"https://github.com/apache/calcite/pull/275.patch","issue_url":"https://api.github.com/repos/apache/calcite/issues/275","number":275,"state":"open","locked":false,"title":"[CALCITE-1365] Introduce UnionPullUpConstantsRule","user":{"login":"jcamachor","id":222949,"avatar_url":"https://avatars.githubusercontent.com/u/222949?v=3","gravatar_id":"","url":"https://api.github.com/users/jcamachor","html_url":"https://github.com/jcamachor","followers_url":"https://api.github.com/users/jcamachor/followers","following_url":"https://api.github.com/users/jcamachor/following{/other_user}","gists_url":"https://api.github.com/users/jcamachor/gists{/gist_id}","starred_url":"https://api.github.com/users/jcamachor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcamachor/subscriptions","organizations_url":"https://api.github.com/users/jcamachor/orgs","repos_url":"https://api.github.com/users/jcamachor/repos","events_url":"https://api.github.com/users/jcamachor/events{/privacy}","received_events_url":"https://api.github.com/users/jcamachor/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-30T15:16:52Z","updated_at":"2016-08-30T17:25:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4b7795fb7b0f56097a56120576c1679bba99df60","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/calcite/pulls/275/commits","review_comments_url":"https://api.github.com/repos/apache/calcite/pulls/275/comments","review_comment_url":"https://api.github.com/repos/apache/calcite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/calcite/issues/275/comments","statuses_url":"https://api.github.com/repos/apache/calcite/statuses/c2783f85a4c66493a369f087c8eb4ac302deb3f4","head":{"label":"jcamachor:CALCITE-1365","ref":"CALCITE-1365","sha":"c2783f85a4c66493a369f087c8eb4ac302deb3f4","user":{"login":"jcamachor","id":222949,"avatar_url":"https://avatars.githubusercontent.com/u/222949?v=3","gravatar_id":"","url":"https://api.github.com/users/jcamachor","html_url":"https://github.com/jcamachor","followers_url":"https://api.github.com/users/jcamachor/followers","following_url":"https://api.github.com/users/jcamachor/following{/other_user}","gists_url":"https://api.github.com/users/jcamachor/gists{/gist_id}","starred_url":"https://api.github.com/users/jcamachor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcamachor/subscriptions","organizations_url":"https://api.github.com/users/jcamachor/orgs","repos_url":"https://api.github.com/users/jcamachor/repos","events_url":"https://api.github.com/users/jcamachor/events{/privacy}","received_events_url":"https://api.github.com/users/jcamachor/received_events","type":"User","site_admin":false},"repo":{"id":45401433,"name":"calcite","full_name":"jcamachor/calcite","owner":{"login":"jcamachor","id":222949,"avatar_url":"https://avatars.githubusercontent.com/u/222949?v=3","gravatar_id":"","url":"https://api.github.com/users/jcamachor","html_url":"https://github.com/jcamachor","followers_url":"https://api.github.com/users/jcamachor/followers","following_url":"https://api.github.com/users/jcamachor/following{/other_user}","gists_url":"https://api.github.com/users/jcamachor/gists{/gist_id}","starred_url":"https://api.github.com/users/jcamachor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcamachor/subscriptions","organizations_url":"https://api.github.com/users/jcamachor/orgs","repos_url":"https://api.github.com/users/jcamachor/repos","events_url":"https://api.github.com/users/jcamachor/events{/privacy}","received_events_url":"https://api.github.com/users/jcamachor/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jcamachor/calcite","description":"Mirror of Apache Calcite","fork":true,"url":"https://api.github.com/repos/jcamachor/calcite","forks_url":"https://api.github.com/repos/jcamachor/calcite/forks","keys_url":"https://api.github.com/repos/jcamachor/calcite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jcamachor/calcite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jcamachor/calcite/teams","hooks_url":"https://api.github.com/repos/jcamachor/calcite/hooks","issue_events_url":"https://api.github.com/repos/jcamachor/calcite/issues/events{/number}","events_url":"https://api.github.com/repos/jcamachor/calcite/events","assignees_url":"https://api.github.com/repos/jcamachor/calcite/assignees{/user}","branches_url":"https://api.github.com/repos/jcamachor/calcite/branches{/branch}","tags_url":"https://api.github.com/repos/jcamachor/calcite/tags","blobs_url":"https://api.github.com/repos/jcamachor/calcite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jcamachor/calcite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jcamachor/calcite/git/refs{/sha}","trees_url":"https://api.github.com/repos/jcamachor/calcite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jcamachor/calcite/statuses/{sha}","languages_url":"https://api.github.com/repos/jcamachor/calcite/languages","stargazers_url":"https://api.github.com/repos/jcamachor/calcite/stargazers","contributors_url":"https://api.github.com/repos/jcamachor/calcite/contributors","subscribers_url":"https://api.github.com/repos/jcamachor/calcite/subscribers","subscription_url":"https://api.github.com/repos/jcamachor/calcite/subscription","commits_url":"https://api.github.com/repos/jcamachor/calcite/commits{/sha}","git_commits_url":"https://api.github.com/repos/jcamachor/calcite/git/commits{/sha}","comments_url":"https://api.github.com/repos/jcamachor/calcite/comments{/number}","issue_comment_url":"https://api.github.com/repos/jcamachor/calcite/issues/comments{/number}","contents_url":"https://api.github.com/repos/jcamachor/calcite/contents/{+path}","compare_url":"https://api.github.com/repos/jcamachor/calcite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jcamachor/calcite/merges","archive_url":"https://api.github.com/repos/jcamachor/calcite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jcamachor/calcite/downloads","issues_url":"https://api.github.com/repos/jcamachor/calcite/issues{/number}","pulls_url":"https://api.github.com/repos/jcamachor/calcite/pulls{/number}","milestones_url":"https://api.github.com/repos/jcamachor/calcite/milestones{/number}","notifications_url":"https://api.github.com/repos/jcamachor/calcite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jcamachor/calcite/labels{/name}","releases_url":"https://api.github.com/repos/jcamachor/calcite/releases{/id}","deployments_url":"https://api.github.com/repos/jcamachor/calcite/deployments","created_at":"2015-11-02T15:01:57Z","updated_at":"2016-02-26T17:48:25Z","pushed_at":"2016-08-30T17:22:02Z","git_url":"git://github.com/jcamachor/calcite.git","ssh_url":"git@github.com:jcamachor/calcite.git","clone_url":"https://github.com/jcamachor/calcite.git","svn_url":"https://github.com/jcamachor/calcite","homepage":"","size":28117,"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":"e872959797de16ef856d76526da484e094ef0a10","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":21193524,"name":"calcite","full_name":"apache/calcite","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/calcite","description":"Mirror of Apache Calcite","fork":false,"url":"https://api.github.com/repos/apache/calcite","forks_url":"https://api.github.com/repos/apache/calcite/forks","keys_url":"https://api.github.com/repos/apache/calcite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/calcite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/calcite/teams","hooks_url":"https://api.github.com/repos/apache/calcite/hooks","issue_events_url":"https://api.github.com/repos/apache/calcite/issues/events{/number}","events_url":"https://api.github.com/repos/apache/calcite/events","assignees_url":"https://api.github.com/repos/apache/calcite/assignees{/user}","branches_url":"https://api.github.com/repos/apache/calcite/branches{/branch}","tags_url":"https://api.github.com/repos/apache/calcite/tags","blobs_url":"https://api.github.com/repos/apache/calcite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/calcite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/calcite/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/calcite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/calcite/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/calcite/languages","stargazers_url":"https://api.github.com/repos/apache/calcite/stargazers","contributors_url":"https://api.github.com/repos/apache/calcite/contributors","subscribers_url":"https://api.github.com/repos/apache/calcite/subscribers","subscription_url":"https://api.github.com/repos/apache/calcite/subscription","commits_url":"https://api.github.com/repos/apache/calcite/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/calcite/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/calcite/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/calcite/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/calcite/contents/{+path}","compare_url":"https://api.github.com/repos/apache/calcite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/calcite/merges","archive_url":"https://api.github.com/repos/apache/calcite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/calcite/downloads","issues_url":"https://api.github.com/repos/apache/calcite/issues{/number}","pulls_url":"https://api.github.com/repos/apache/calcite/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/calcite/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/calcite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/calcite/labels{/name}","releases_url":"https://api.github.com/repos/apache/calcite/releases{/id}","deployments_url":"https://api.github.com/repos/apache/calcite/deployments","created_at":"2014-06-25T07:00:07Z","updated_at":"2016-08-30T09:23:11Z","pushed_at":"2016-08-30T17:22:02Z","git_url":"git://github.com/apache/calcite.git","ssh_url":"git@github.com:apache/calcite.git","clone_url":"https://github.com/apache/calcite.git","svn_url":"https://github.com/apache/calcite","homepage":"","size":31729,"stargazers_count":266,"watchers_count":266,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":227,"mirror_url":"git://git.apache.org/calcite.git","open_issues_count":10,"forks":227,"open_issues":10,"watchers":266,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/calcite/pulls/275"},"html":{"href":"https://github.com/apache/calcite/pull/275"},"issue":{"href":"https://api.github.com/repos/apache/calcite/issues/275"},"comments":{"href":"https://api.github.com/repos/apache/calcite/issues/275/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/calcite/pulls/275/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/calcite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/calcite/pulls/275/commits"},"statuses":{"href":"https://api.github.com/repos/apache/calcite/statuses/c2783f85a4c66493a369f087c8eb4ac302deb3f4"}}}}
{"actor":{"display_login":"jcamachor"}}