{"action":"created","comment":{"url":"https://api.github.com/repos/apache/drill/pulls/comments/54923238","id":54923238,"diff_hunk":"@@ -0,0 +1,568 @@\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.drill.exec.planner.sql;\n+\n+import com.google.common.collect.ImmutableMap;\n+import com.google.common.collect.Lists;\n+\n+import com.google.common.collect.Maps;\n+import org.apache.calcite.avatica.util.TimeUnit;\n+import org.apache.calcite.rel.type.RelDataType;\n+import org.apache.calcite.rel.type.RelDataTypeFactory;\n+import org.apache.calcite.sql.SqlCallBinding;\n+import org.apache.calcite.sql.SqlCharStringLiteral;\n+import org.apache.calcite.sql.SqlDynamicParam;\n+import org.apache.calcite.sql.SqlLiteral;\n+import org.apache.calcite.sql.SqlNode;\n+import org.apache.calcite.sql.SqlOperatorBinding;\n+import org.apache.calcite.sql.type.SqlReturnTypeInference;\n+import org.apache.calcite.sql.type.SqlTypeName;\n+\n+import org.apache.drill.common.expression.ExpressionPosition;\n+import org.apache.drill.common.expression.FunctionCall;\n+import org.apache.drill.common.expression.LogicalExpression;\n+import org.apache.drill.common.expression.MajorTypeInLogicalExpression;\n+import org.apache.drill.common.exceptions.UserException;\n+import org.apache.drill.common.types.TypeProtos;\n+import org.apache.drill.common.types.Types;\n+import org.apache.drill.exec.expr.TypeHelper;\n+import org.apache.drill.exec.expr.fn.DrillFuncHolder;\n+import org.apache.drill.exec.planner.logical.DrillConstExecutor;\n+import org.apache.drill.exec.resolver.FunctionResolver;\n+import org.apache.drill.exec.resolver.FunctionResolverFactory;\n+import org.apache.drill.exec.resolver.TypeCastRules;\n+\n+import java.util.List;\n+import java.util.Map;\n+\n+public class TypeInferenceUtils {\n+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(TypeInferenceUtils.class);\n+\n+  public static final TypeProtos.MajorType UNKNOWN_TYPE = TypeProtos.MajorType.getDefaultInstance();\n+  private static ImmutableMap<TypeProtos.MinorType, SqlTypeName> DRILL_TO_CALCITE_TYPE_MAPPING =\n+      ImmutableMap.<TypeProtos.MinorType, SqlTypeName> builder()\n+          .put(TypeProtos.MinorType.INT, SqlTypeName.INTEGER)\n+          .put(TypeProtos.MinorType.BIGINT, SqlTypeName.BIGINT)\n+          .put(TypeProtos.MinorType.FLOAT4, SqlTypeName.FLOAT)\n+          .put(TypeProtos.MinorType.FLOAT8, SqlTypeName.DOUBLE)\n+          .put(TypeProtos.MinorType.VARCHAR, SqlTypeName.VARCHAR)\n+          .put(TypeProtos.MinorType.BIT, SqlTypeName.BOOLEAN)\n+          .put(TypeProtos.MinorType.DATE, SqlTypeName.DATE)\n+          .put(TypeProtos.MinorType.DECIMAL9, SqlTypeName.DECIMAL)\n+          .put(TypeProtos.MinorType.DECIMAL18, SqlTypeName.DECIMAL)\n+          .put(TypeProtos.MinorType.DECIMAL28SPARSE, SqlTypeName.DECIMAL)\n+          .put(TypeProtos.MinorType.DECIMAL38SPARSE, SqlTypeName.DECIMAL)\n+          .put(TypeProtos.MinorType.TIME, SqlTypeName.TIME)\n+          .put(TypeProtos.MinorType.TIMESTAMP, SqlTypeName.TIMESTAMP)\n+          .put(TypeProtos.MinorType.VARBINARY, SqlTypeName.VARBINARY)\n+          .put(TypeProtos.MinorType.INTERVALYEAR, SqlTypeName.INTERVAL_YEAR_MONTH)\n+          .put(TypeProtos.MinorType.INTERVALDAY, SqlTypeName.INTERVAL_DAY_TIME)\n+          .put(TypeProtos.MinorType.MAP, SqlTypeName.MAP)\n+          .put(TypeProtos.MinorType.LIST, SqlTypeName.ARRAY)\n+          .put(TypeProtos.MinorType.LATE, SqlTypeName.ANY)\n+          .build();\n+\n+  private static ImmutableMap<SqlTypeName, TypeProtos.MinorType> CALCITE_TO_DRILL_MAPPING =","path":"exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/TypeInferenceUtils.java","position":80,"original_position":80,"commit_id":"192bd42d659c1a9a0b9a9263051c0eac360f6404","original_commit_id":"192bd42d659c1a9a0b9a9263051c0eac360f6404","user":{"login":"sudheeshkatkam","id":3272600,"avatar_url":"https://avatars.githubusercontent.com/u/3272600?v=3","gravatar_id":"","url":"https://api.github.com/users/sudheeshkatkam","html_url":"https://github.com/sudheeshkatkam","followers_url":"https://api.github.com/users/sudheeshkatkam/followers","following_url":"https://api.github.com/users/sudheeshkatkam/following{/other_user}","gists_url":"https://api.github.com/users/sudheeshkatkam/gists{/gist_id}","starred_url":"https://api.github.com/users/sudheeshkatkam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sudheeshkatkam/subscriptions","organizations_url":"https://api.github.com/users/sudheeshkatkam/orgs","repos_url":"https://api.github.com/users/sudheeshkatkam/repos","events_url":"https://api.github.com/users/sudheeshkatkam/events{/privacy}","received_events_url":"https://api.github.com/users/sudheeshkatkam/received_events","type":"User","site_admin":false},"body":"final","created_at":"2016-03-03T18:24:57Z","updated_at":"2016-03-03T18:24:57Z","html_url":"https://github.com/apache/drill/pull/397#discussion_r54923238","pull_request_url":"https://api.github.com/repos/apache/drill/pulls/397","_links":{"self":{"href":"https://api.github.com/repos/apache/drill/pulls/comments/54923238"},"html":{"href":"https://github.com/apache/drill/pull/397#discussion_r54923238"},"pull_request":{"href":"https://api.github.com/repos/apache/drill/pulls/397"}}},"pull_request":{"url":"https://api.github.com/repos/apache/drill/pulls/397","id":61036456,"html_url":"https://github.com/apache/drill/pull/397","diff_url":"https://github.com/apache/drill/pull/397.diff","patch_url":"https://github.com/apache/drill/pull/397.patch","issue_url":"https://api.github.com/repos/apache/drill/issues/397","number":397,"state":"open","locked":false,"title":"Drill 4372 review","user":{"login":"hsuanyi","id":4021621,"avatar_url":"https://avatars.githubusercontent.com/u/4021621?v=3","gravatar_id":"","url":"https://api.github.com/users/hsuanyi","html_url":"https://github.com/hsuanyi","followers_url":"https://api.github.com/users/hsuanyi/followers","following_url":"https://api.github.com/users/hsuanyi/following{/other_user}","gists_url":"https://api.github.com/users/hsuanyi/gists{/gist_id}","starred_url":"https://api.github.com/users/hsuanyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hsuanyi/subscriptions","organizations_url":"https://api.github.com/users/hsuanyi/orgs","repos_url":"https://api.github.com/users/hsuanyi/repos","events_url":"https://api.github.com/users/hsuanyi/events{/privacy}","received_events_url":"https://api.github.com/users/hsuanyi/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-29T07:04:10Z","updated_at":"2016-03-03T18:24:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2a49fb042259b6f7497dcc837dabc1baa711f4de","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/drill/pulls/397/commits","review_comments_url":"https://api.github.com/repos/apache/drill/pulls/397/comments","review_comment_url":"https://api.github.com/repos/apache/drill/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/drill/issues/397/comments","statuses_url":"https://api.github.com/repos/apache/drill/statuses/192bd42d659c1a9a0b9a9263051c0eac360f6404","head":{"label":"hsuanyi:DRILL-4372_Review","ref":"DRILL-4372_Review","sha":"192bd42d659c1a9a0b9a9263051c0eac360f6404","user":{"login":"hsuanyi","id":4021621,"avatar_url":"https://avatars.githubusercontent.com/u/4021621?v=3","gravatar_id":"","url":"https://api.github.com/users/hsuanyi","html_url":"https://github.com/hsuanyi","followers_url":"https://api.github.com/users/hsuanyi/followers","following_url":"https://api.github.com/users/hsuanyi/following{/other_user}","gists_url":"https://api.github.com/users/hsuanyi/gists{/gist_id}","starred_url":"https://api.github.com/users/hsuanyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hsuanyi/subscriptions","organizations_url":"https://api.github.com/users/hsuanyi/orgs","repos_url":"https://api.github.com/users/hsuanyi/repos","events_url":"https://api.github.com/users/hsuanyi/events{/privacy}","received_events_url":"https://api.github.com/users/hsuanyi/received_events","type":"User","site_admin":false},"repo":{"id":25934037,"name":"incubator-drill","full_name":"hsuanyi/incubator-drill","owner":{"login":"hsuanyi","id":4021621,"avatar_url":"https://avatars.githubusercontent.com/u/4021621?v=3","gravatar_id":"","url":"https://api.github.com/users/hsuanyi","html_url":"https://github.com/hsuanyi","followers_url":"https://api.github.com/users/hsuanyi/followers","following_url":"https://api.github.com/users/hsuanyi/following{/other_user}","gists_url":"https://api.github.com/users/hsuanyi/gists{/gist_id}","starred_url":"https://api.github.com/users/hsuanyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hsuanyi/subscriptions","organizations_url":"https://api.github.com/users/hsuanyi/orgs","repos_url":"https://api.github.com/users/hsuanyi/repos","events_url":"https://api.github.com/users/hsuanyi/events{/privacy}","received_events_url":"https://api.github.com/users/hsuanyi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hsuanyi/incubator-drill","description":"Mirror of Apache Drill (Incubating)","fork":true,"url":"https://api.github.com/repos/hsuanyi/incubator-drill","forks_url":"https://api.github.com/repos/hsuanyi/incubator-drill/forks","keys_url":"https://api.github.com/repos/hsuanyi/incubator-drill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hsuanyi/incubator-drill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hsuanyi/incubator-drill/teams","hooks_url":"https://api.github.com/repos/hsuanyi/incubator-drill/hooks","issue_events_url":"https://api.github.com/repos/hsuanyi/incubator-drill/issues/events{/number}","events_url":"https://api.github.com/repos/hsuanyi/incubator-drill/events","assignees_url":"https://api.github.com/repos/hsuanyi/incubator-drill/assignees{/user}","branches_url":"https://api.github.com/repos/hsuanyi/incubator-drill/branches{/branch}","tags_url":"https://api.github.com/repos/hsuanyi/incubator-drill/tags","blobs_url":"https://api.github.com/repos/hsuanyi/incubator-drill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hsuanyi/incubator-drill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hsuanyi/incubator-drill/git/refs{/sha}","trees_url":"https://api.github.com/repos/hsuanyi/incubator-drill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hsuanyi/incubator-drill/statuses/{sha}","languages_url":"https://api.github.com/repos/hsuanyi/incubator-drill/languages","stargazers_url":"https://api.github.com/repos/hsuanyi/incubator-drill/stargazers","contributors_url":"https://api.github.com/repos/hsuanyi/incubator-drill/contributors","subscribers_url":"https://api.github.com/repos/hsuanyi/incubator-drill/subscribers","subscription_url":"https://api.github.com/repos/hsuanyi/incubator-drill/subscription","commits_url":"https://api.github.com/repos/hsuanyi/incubator-drill/commits{/sha}","git_commits_url":"https://api.github.com/repos/hsuanyi/incubator-drill/git/commits{/sha}","comments_url":"https://api.github.com/repos/hsuanyi/incubator-drill/comments{/number}","issue_comment_url":"https://api.github.com/repos/hsuanyi/incubator-drill/issues/comments{/number}","contents_url":"https://api.github.com/repos/hsuanyi/incubator-drill/contents/{+path}","compare_url":"https://api.github.com/repos/hsuanyi/incubator-drill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hsuanyi/incubator-drill/merges","archive_url":"https://api.github.com/repos/hsuanyi/incubator-drill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hsuanyi/incubator-drill/downloads","issues_url":"https://api.github.com/repos/hsuanyi/incubator-drill/issues{/number}","pulls_url":"https://api.github.com/repos/hsuanyi/incubator-drill/pulls{/number}","milestones_url":"https://api.github.com/repos/hsuanyi/incubator-drill/milestones{/number}","notifications_url":"https://api.github.com/repos/hsuanyi/incubator-drill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hsuanyi/incubator-drill/labels{/name}","releases_url":"https://api.github.com/repos/hsuanyi/incubator-drill/releases{/id}","deployments_url":"https://api.github.com/repos/hsuanyi/incubator-drill/deployments","created_at":"2014-10-29T17:59:38Z","updated_at":"2016-01-12T00:04:40Z","pushed_at":"2016-03-03T17:29:31Z","git_url":"git://github.com/hsuanyi/incubator-drill.git","ssh_url":"git@github.com:hsuanyi/incubator-drill.git","clone_url":"https://github.com/hsuanyi/incubator-drill.git","svn_url":"https://github.com/hsuanyi/incubator-drill","homepage":null,"size":35967,"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":"c98edbafb9bdf8ed83e9b2df7b9bf09d7e07987b","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":5683653,"name":"drill","full_name":"apache/drill","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/drill","description":"Mirror of Apache Drill","fork":false,"url":"https://api.github.com/repos/apache/drill","forks_url":"https://api.github.com/repos/apache/drill/forks","keys_url":"https://api.github.com/repos/apache/drill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/drill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/drill/teams","hooks_url":"https://api.github.com/repos/apache/drill/hooks","issue_events_url":"https://api.github.com/repos/apache/drill/issues/events{/number}","events_url":"https://api.github.com/repos/apache/drill/events","assignees_url":"https://api.github.com/repos/apache/drill/assignees{/user}","branches_url":"https://api.github.com/repos/apache/drill/branches{/branch}","tags_url":"https://api.github.com/repos/apache/drill/tags","blobs_url":"https://api.github.com/repos/apache/drill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/drill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/drill/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/drill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/drill/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/drill/languages","stargazers_url":"https://api.github.com/repos/apache/drill/stargazers","contributors_url":"https://api.github.com/repos/apache/drill/contributors","subscribers_url":"https://api.github.com/repos/apache/drill/subscribers","subscription_url":"https://api.github.com/repos/apache/drill/subscription","commits_url":"https://api.github.com/repos/apache/drill/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/drill/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/drill/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/drill/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/drill/contents/{+path}","compare_url":"https://api.github.com/repos/apache/drill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/drill/merges","archive_url":"https://api.github.com/repos/apache/drill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/drill/downloads","issues_url":"https://api.github.com/repos/apache/drill/issues{/number}","pulls_url":"https://api.github.com/repos/apache/drill/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/drill/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/drill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/drill/labels{/name}","releases_url":"https://api.github.com/repos/apache/drill/releases{/id}","deployments_url":"https://api.github.com/repos/apache/drill/deployments","created_at":"2012-09-05T07:00:26Z","updated_at":"2016-03-03T13:01:41Z","pushed_at":"2016-03-03T18:08:10Z","git_url":"git://github.com/apache/drill.git","ssh_url":"git@github.com:apache/drill.git","clone_url":"https://github.com/apache/drill.git","svn_url":"https://github.com/apache/drill","homepage":"","size":49550,"stargazers_count":573,"watchers_count":573,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":393,"mirror_url":"git://git.apache.org/drill.git","open_issues_count":89,"forks":393,"open_issues":89,"watchers":573,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/drill/pulls/397"},"html":{"href":"https://github.com/apache/drill/pull/397"},"issue":{"href":"https://api.github.com/repos/apache/drill/issues/397"},"comments":{"href":"https://api.github.com/repos/apache/drill/issues/397/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/drill/pulls/397/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/drill/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/drill/pulls/397/commits"},"statuses":{"href":"https://api.github.com/repos/apache/drill/statuses/192bd42d659c1a9a0b9a9263051c0eac360f6404"}}}}