{"action":"created","comment":{"url":"https://api.github.com/repos/apache/flink/pulls/comments/60728611","id":60728611,"diff_hunk":"@@ -0,0 +1,188 @@\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.flink.api.table.plan.logical\n+\n+import scala.collection.JavaConverters._\n+\n+import org.apache.calcite.rel.RelNode\n+import org.apache.calcite.rel.`type`.RelDataTypeFactory\n+import org.apache.calcite.rel.core.JoinRelType\n+import org.apache.calcite.rel.logical.LogicalProject\n+import org.apache.calcite.schema.{Table => CTable}\n+import org.apache.calcite.tools.RelBuilder\n+\n+import org.apache.flink.api.common.typeinfo.BasicTypeInfo\n+import org.apache.flink.api.java.operators.join.JoinType\n+import org.apache.flink.api.table.expressions._\n+import org.apache.flink.api.table.typeutils.TypeConverter\n+import org.apache.flink.api.table.validate.ValidationException\n+\n+case class Project(projectList: Seq[NamedExpression], child: LogicalNode) extends UnaryNode {\n+  override def output: Seq[Attribute] = projectList.map(_.toAttribute)\n+\n+  override def toRelNode(relBuilder: RelBuilder): RelBuilder = {\n+    def allAlias: Boolean = {\n+      projectList.forall { proj =>\n+        proj match {\n+          case Alias(r: ResolvedFieldReference, name) => true\n+          case _ => false\n+        }\n+      }\n+    }\n+    child.toRelNode(relBuilder)\n+    if (allAlias) {\n+      relBuilder.push(\n+        LogicalProject.create(relBuilder.peek(),\n+          projectList.map(_.toRexNode(relBuilder)).asJava,\n+          projectList.map(_.name).asJava))\n+    } else {\n+      relBuilder.project(projectList.map(_.toRexNode(relBuilder)): _*)\n+    }\n+  }\n+}\n+\n+case class AliasNode(aliasList: Seq[Expression], child: LogicalNode) extends UnaryNode {\n+  override def output: Seq[Attribute] =\n+    throw new UnresolvedException(\"Invalid call to output on AliasNode\")\n+\n+  override def toRelNode(relBuilder: RelBuilder): RelBuilder =\n+    throw new UnresolvedException(\"Invalid call to toRelNode on AliasNode\")\n+\n+  override lazy val resolved: Boolean = false\n+}\n+\n+case class Distinct(child: LogicalNode) extends UnaryNode {\n+  override def output: Seq[Attribute] = child.output\n+\n+  override def toRelNode(relBuilder: RelBuilder): RelBuilder = {\n+    child.toRelNode(relBuilder)\n+    relBuilder.distinct()\n+  }\n+}\n+\n+case class Filter(condition: Expression, child: LogicalNode) extends UnaryNode {\n+  override def output: Seq[Attribute] = child.output\n+\n+  override def toRelNode(relBuilder: RelBuilder): RelBuilder = {\n+    child.toRelNode(relBuilder)\n+    relBuilder.filter(condition.toRexNode(relBuilder))\n+  }\n+}\n+\n+case class Aggregate(\n+    groupingExpressions: Seq[Expression],\n+    aggregateExpressions: Seq[NamedExpression],\n+    child: LogicalNode) extends UnaryNode {\n+\n+  override def output: Seq[Attribute] = {\n+    (groupingExpressions ++ aggregateExpressions) map { agg =>\n+      agg match {\n+        case ne: NamedExpression => ne.toAttribute\n+        case e => Alias(e, e.toString).toAttribute\n+      }\n+    }\n+  }\n+\n+  override def toRelNode(relBuilder: RelBuilder): RelBuilder = {\n+    child.toRelNode(relBuilder)\n+    relBuilder.aggregate(\n+      relBuilder.groupKey(groupingExpressions.map(_.toRexNode(relBuilder)).asJava),\n+      aggregateExpressions.filter(_.isInstanceOf[Alias]).map { e =>\n+        e match {\n+          case Alias(agg: Aggregation, name) => agg.toAggCall(name)(relBuilder)\n+          case _ => null // this should never happen\n+        }\n+      }.asJava)\n+  }\n+}\n+\n+case class Union(left: LogicalNode, right: LogicalNode) extends BinaryNode {\n+  override def output: Seq[Attribute] = left.output\n+\n+  override def toRelNode(relBuilder: RelBuilder): RelBuilder = {\n+    left.toRelNode(relBuilder)\n+    right.toRelNode(relBuilder)\n+    relBuilder.union(true)\n+  }\n+}","path":"flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/plan/logical/operators.scala","position":122,"original_position":122,"commit_id":"d43fa4224f0e2b94e8517d5cd009f08eaf36b552","original_commit_id":"d43fa4224f0e2b94e8517d5cd009f08eaf36b552","user":{"login":"yjshen","id":1387718,"avatar_url":"https://avatars.githubusercontent.com/u/1387718?v=3","gravatar_id":"","url":"https://api.github.com/users/yjshen","html_url":"https://github.com/yjshen","followers_url":"https://api.github.com/users/yjshen/followers","following_url":"https://api.github.com/users/yjshen/following{/other_user}","gists_url":"https://api.github.com/users/yjshen/gists{/gist_id}","starred_url":"https://api.github.com/users/yjshen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjshen/subscriptions","organizations_url":"https://api.github.com/users/yjshen/orgs","repos_url":"https://api.github.com/users/yjshen/repos","events_url":"https://api.github.com/users/yjshen/events{/privacy}","received_events_url":"https://api.github.com/users/yjshen/received_events","type":"User","site_admin":false},"body":"Need to override the `resolved` field to check equality of `left` and `right` output schema. Will do in next commit.","created_at":"2016-04-22T12:07:07Z","updated_at":"2016-04-22T12:07:07Z","html_url":"https://github.com/apache/flink/pull/1916#discussion_r60728611","pull_request_url":"https://api.github.com/repos/apache/flink/pulls/1916","_links":{"self":{"href":"https://api.github.com/repos/apache/flink/pulls/comments/60728611"},"html":{"href":"https://github.com/apache/flink/pull/1916#discussion_r60728611"},"pull_request":{"href":"https://api.github.com/repos/apache/flink/pulls/1916"}}},"pull_request":{"url":"https://api.github.com/repos/apache/flink/pulls/1916","id":67199257,"html_url":"https://github.com/apache/flink/pull/1916","diff_url":"https://github.com/apache/flink/pull/1916.diff","patch_url":"https://github.com/apache/flink/pull/1916.patch","issue_url":"https://api.github.com/repos/apache/flink/issues/1916","number":1916,"state":"open","locked":false,"title":"[FLINK-3754][Table]Add a validation phase before construct RelNode using TableAPI","user":{"login":"yjshen","id":1387718,"avatar_url":"https://avatars.githubusercontent.com/u/1387718?v=3","gravatar_id":"","url":"https://api.github.com/users/yjshen","html_url":"https://github.com/yjshen","followers_url":"https://api.github.com/users/yjshen/followers","following_url":"https://api.github.com/users/yjshen/following{/other_user}","gists_url":"https://api.github.com/users/yjshen/gists{/gist_id}","starred_url":"https://api.github.com/users/yjshen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjshen/subscriptions","organizations_url":"https://api.github.com/users/yjshen/orgs","repos_url":"https://api.github.com/users/yjshen/repos","events_url":"https://api.github.com/users/yjshen/events{/privacy}","received_events_url":"https://api.github.com/users/yjshen/received_events","type":"User","site_admin":false},"body":"This PR aims at adding an extra phase of **validation** for plans generated from Table API, matches the functionality of Calcite's Validator that are called during we execute an query expressed in SQL String.\r\n\r\nIn order to do this, I inserted a new layer between TableAPI and `RelNode` construction: The `Logical Plan`.\r\n\r\nAnd the main procedure of validation and RelNode construction work as follows:\r\n\r\n1. Constructing logical plan in flight\r\n2. When we are about to execute the plan:\r\n3. Do resolution using table/dataset/datastream schema\r\n4. Do validation on the type annotated logical plan tree\r\n5. Translate logical plan into `RelNode` once we successfully finished validation.","created_at":"2016-04-20T14:42:39Z","updated_at":"2016-04-22T12:07:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c189e24e42435a6344bf926b8733718b4ef97502","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/flink/pulls/1916/commits","review_comments_url":"https://api.github.com/repos/apache/flink/pulls/1916/comments","review_comment_url":"https://api.github.com/repos/apache/flink/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/flink/issues/1916/comments","statuses_url":"https://api.github.com/repos/apache/flink/statuses/d43fa4224f0e2b94e8517d5cd009f08eaf36b552","head":{"label":"yjshen:extra_validation","ref":"extra_validation","sha":"d43fa4224f0e2b94e8517d5cd009f08eaf36b552","user":{"login":"yjshen","id":1387718,"avatar_url":"https://avatars.githubusercontent.com/u/1387718?v=3","gravatar_id":"","url":"https://api.github.com/users/yjshen","html_url":"https://github.com/yjshen","followers_url":"https://api.github.com/users/yjshen/followers","following_url":"https://api.github.com/users/yjshen/following{/other_user}","gists_url":"https://api.github.com/users/yjshen/gists{/gist_id}","starred_url":"https://api.github.com/users/yjshen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjshen/subscriptions","organizations_url":"https://api.github.com/users/yjshen/orgs","repos_url":"https://api.github.com/users/yjshen/repos","events_url":"https://api.github.com/users/yjshen/events{/privacy}","received_events_url":"https://api.github.com/users/yjshen/received_events","type":"User","site_admin":false},"repo":{"id":49318317,"name":"flink","full_name":"yjshen/flink","owner":{"login":"yjshen","id":1387718,"avatar_url":"https://avatars.githubusercontent.com/u/1387718?v=3","gravatar_id":"","url":"https://api.github.com/users/yjshen","html_url":"https://github.com/yjshen","followers_url":"https://api.github.com/users/yjshen/followers","following_url":"https://api.github.com/users/yjshen/following{/other_user}","gists_url":"https://api.github.com/users/yjshen/gists{/gist_id}","starred_url":"https://api.github.com/users/yjshen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yjshen/subscriptions","organizations_url":"https://api.github.com/users/yjshen/orgs","repos_url":"https://api.github.com/users/yjshen/repos","events_url":"https://api.github.com/users/yjshen/events{/privacy}","received_events_url":"https://api.github.com/users/yjshen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yjshen/flink","description":"Mirror of Apache Flink","fork":true,"url":"https://api.github.com/repos/yjshen/flink","forks_url":"https://api.github.com/repos/yjshen/flink/forks","keys_url":"https://api.github.com/repos/yjshen/flink/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yjshen/flink/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yjshen/flink/teams","hooks_url":"https://api.github.com/repos/yjshen/flink/hooks","issue_events_url":"https://api.github.com/repos/yjshen/flink/issues/events{/number}","events_url":"https://api.github.com/repos/yjshen/flink/events","assignees_url":"https://api.github.com/repos/yjshen/flink/assignees{/user}","branches_url":"https://api.github.com/repos/yjshen/flink/branches{/branch}","tags_url":"https://api.github.com/repos/yjshen/flink/tags","blobs_url":"https://api.github.com/repos/yjshen/flink/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yjshen/flink/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yjshen/flink/git/refs{/sha}","trees_url":"https://api.github.com/repos/yjshen/flink/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yjshen/flink/statuses/{sha}","languages_url":"https://api.github.com/repos/yjshen/flink/languages","stargazers_url":"https://api.github.com/repos/yjshen/flink/stargazers","contributors_url":"https://api.github.com/repos/yjshen/flink/contributors","subscribers_url":"https://api.github.com/repos/yjshen/flink/subscribers","subscription_url":"https://api.github.com/repos/yjshen/flink/subscription","commits_url":"https://api.github.com/repos/yjshen/flink/commits{/sha}","git_commits_url":"https://api.github.com/repos/yjshen/flink/git/commits{/sha}","comments_url":"https://api.github.com/repos/yjshen/flink/comments{/number}","issue_comment_url":"https://api.github.com/repos/yjshen/flink/issues/comments{/number}","contents_url":"https://api.github.com/repos/yjshen/flink/contents/{+path}","compare_url":"https://api.github.com/repos/yjshen/flink/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yjshen/flink/merges","archive_url":"https://api.github.com/repos/yjshen/flink/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yjshen/flink/downloads","issues_url":"https://api.github.com/repos/yjshen/flink/issues{/number}","pulls_url":"https://api.github.com/repos/yjshen/flink/pulls{/number}","milestones_url":"https://api.github.com/repos/yjshen/flink/milestones{/number}","notifications_url":"https://api.github.com/repos/yjshen/flink/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yjshen/flink/labels{/name}","releases_url":"https://api.github.com/repos/yjshen/flink/releases{/id}","deployments_url":"https://api.github.com/repos/yjshen/flink/deployments","created_at":"2016-01-09T09:25:54Z","updated_at":"2016-01-25T03:22:21Z","pushed_at":"2016-04-21T03:49:21Z","git_url":"git://github.com/yjshen/flink.git","ssh_url":"git@github.com:yjshen/flink.git","clone_url":"https://github.com/yjshen/flink.git","svn_url":"https://github.com/yjshen/flink","homepage":null,"size":88203,"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":"a43bade0d87d373ff236152d13d8d56e17220605","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":20587599,"name":"flink","full_name":"apache/flink","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/flink","description":"Mirror of Apache Flink","fork":false,"url":"https://api.github.com/repos/apache/flink","forks_url":"https://api.github.com/repos/apache/flink/forks","keys_url":"https://api.github.com/repos/apache/flink/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/flink/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/flink/teams","hooks_url":"https://api.github.com/repos/apache/flink/hooks","issue_events_url":"https://api.github.com/repos/apache/flink/issues/events{/number}","events_url":"https://api.github.com/repos/apache/flink/events","assignees_url":"https://api.github.com/repos/apache/flink/assignees{/user}","branches_url":"https://api.github.com/repos/apache/flink/branches{/branch}","tags_url":"https://api.github.com/repos/apache/flink/tags","blobs_url":"https://api.github.com/repos/apache/flink/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/flink/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/flink/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/flink/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/flink/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/flink/languages","stargazers_url":"https://api.github.com/repos/apache/flink/stargazers","contributors_url":"https://api.github.com/repos/apache/flink/contributors","subscribers_url":"https://api.github.com/repos/apache/flink/subscribers","subscription_url":"https://api.github.com/repos/apache/flink/subscription","commits_url":"https://api.github.com/repos/apache/flink/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/flink/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/flink/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/flink/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/flink/contents/{+path}","compare_url":"https://api.github.com/repos/apache/flink/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/flink/merges","archive_url":"https://api.github.com/repos/apache/flink/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/flink/downloads","issues_url":"https://api.github.com/repos/apache/flink/issues{/number}","pulls_url":"https://api.github.com/repos/apache/flink/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/flink/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/flink/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/flink/labels{/name}","releases_url":"https://api.github.com/repos/apache/flink/releases{/id}","deployments_url":"https://api.github.com/repos/apache/flink/deployments","created_at":"2014-06-07T07:00:10Z","updated_at":"2016-04-22T11:23:32Z","pushed_at":"2016-04-22T11:05:57Z","git_url":"git://github.com/apache/flink.git","ssh_url":"git@github.com:apache/flink.git","clone_url":"https://github.com/apache/flink.git","svn_url":"https://github.com/apache/flink","homepage":null,"size":114894,"stargazers_count":1241,"watchers_count":1241,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":773,"mirror_url":"git://git.apache.org/flink.git","open_issues_count":85,"forks":773,"open_issues":85,"watchers":1241,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/flink/pulls/1916"},"html":{"href":"https://github.com/apache/flink/pull/1916"},"issue":{"href":"https://api.github.com/repos/apache/flink/issues/1916"},"comments":{"href":"https://api.github.com/repos/apache/flink/issues/1916/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/flink/pulls/1916/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/flink/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/flink/pulls/1916/commits"},"statuses":{"href":"https://api.github.com/repos/apache/flink/statuses/d43fa4224f0e2b94e8517d5cd009f08eaf36b552"}}}}