{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/6032","labels_url":"https://api.github.com/repos/apache/spark/issues/6032/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/6032/comments","events_url":"https://api.github.com/repos/apache/spark/issues/6032/events","html_url":"https://github.com/apache/spark/pull/6032","id":74726146,"number":6032,"title":"[SPARK-7345][SQL] Spark cannot detect renamed columns using JDBC connector","user":{"login":"osidorkin","id":1208732,"avatar_url":"https://avatars.githubusercontent.com/u/1208732?v=3","gravatar_id":"","url":"https://api.github.com/users/osidorkin","html_url":"https://github.com/osidorkin","followers_url":"https://api.github.com/users/osidorkin/followers","following_url":"https://api.github.com/users/osidorkin/following{/other_user}","gists_url":"https://api.github.com/users/osidorkin/gists{/gist_id}","starred_url":"https://api.github.com/users/osidorkin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/osidorkin/subscriptions","organizations_url":"https://api.github.com/users/osidorkin/orgs","repos_url":"https://api.github.com/users/osidorkin/repos","events_url":"https://api.github.com/users/osidorkin/events{/privacy}","received_events_url":"https://api.github.com/users/osidorkin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-09T18:09:42Z","updated_at":"2015-05-09T20:16:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6032","html_url":"https://github.com/apache/spark/pull/6032","diff_url":"https://github.com/apache/spark/pull/6032.diff","patch_url":"https://github.com/apache/spark/pull/6032.patch"},"body":"Issue appears when one tries to create DataFrame using sqlContext.load(\"jdbc\"...) statement when \"dbtable\" contains query with renamed columns.\r\nIf original column is used in SQL query once the resulting DataFrame will contain non-renamed column.\r\nIf original column is used in SQL query several times with different aliases, sqlContext.load will fail.\r\nOriginal implementation of JDBCRDD.resolveTable uses getColumnName to detect column names in RDD schema.\r\nSuggested implementation uses getColumnLabel to handle column renames in SQL statement which is aware of SQL \"AS\" statement.\r\n\r\nReadings:\r\nhttp://stackoverflow.com/questions/4271152/getcolumnlabel-vs-getcolumnname\r\nhttp://stackoverflow.com/questions/12259829/jdbc-getcolumnname-getcolumnlabel-db2\r\n\r\nOfficial documentation unfortunately a bit misleading in definition of \"suggested title\" purpose however clearly defines behavior of AS keyword in SQL statement.\r\nhttp://docs.oracle.com/javase/7/docs/api/java/sql/ResultSetMetaData.html\r\ngetColumnLabel - Gets the designated column's suggested title for use in printouts and displays. The suggested title is usually specified by the SQL AS clause. If a SQL AS is not specified, the value returned from getColumnLabel will be the same as the value returned by the getColumnName method."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/100540464","html_url":"https://github.com/apache/spark/pull/6032#issuecomment-100540464","issue_url":"https://api.github.com/repos/apache/spark/issues/6032","id":100540464,"user":{"login":"marmbrus","id":527,"avatar_url":"https://avatars.githubusercontent.com/u/527?v=3","gravatar_id":"","url":"https://api.github.com/users/marmbrus","html_url":"https://github.com/marmbrus","followers_url":"https://api.github.com/users/marmbrus/followers","following_url":"https://api.github.com/users/marmbrus/following{/other_user}","gists_url":"https://api.github.com/users/marmbrus/gists{/gist_id}","starred_url":"https://api.github.com/users/marmbrus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmbrus/subscriptions","organizations_url":"https://api.github.com/users/marmbrus/orgs","repos_url":"https://api.github.com/users/marmbrus/repos","events_url":"https://api.github.com/users/marmbrus/events{/privacy}","received_events_url":"https://api.github.com/users/marmbrus/received_events","type":"User","site_admin":false},"created_at":"2015-05-09T20:16:00Z","updated_at":"2015-05-09T20:16:00Z","body":"ok to test"}}