{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/19747","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/19747/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/19747/comments","events_url":"https://api.github.com/repos/apache/spark/issues/19747/events","html_url":"https://github.com/apache/spark/pull/19747","id":273869629,"number":19747,"title":"[Spark-22431][SQL]  Ensure that the datatype in the schema for the table/view metadata is parseable by Spark before persisting it","user":{"login":"skambha","id":16563220,"avatar_url":"https://avatars3.githubusercontent.com/u/16563220?v=4","gravatar_id":"","url":"https://api.github.com/users/skambha","html_url":"https://github.com/skambha","followers_url":"https://api.github.com/users/skambha/followers","following_url":"https://api.github.com/users/skambha/following{/other_user}","gists_url":"https://api.github.com/users/skambha/gists{/gist_id}","starred_url":"https://api.github.com/users/skambha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skambha/subscriptions","organizations_url":"https://api.github.com/users/skambha/orgs","repos_url":"https://api.github.com/users/skambha/repos","events_url":"https://api.github.com/users/skambha/events{/privacy}","received_events_url":"https://api.github.com/users/skambha/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-11-14T17:04:44Z","updated_at":"2017-11-15T06:25:33Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/19747","html_url":"https://github.com/apache/spark/pull/19747","diff_url":"https://github.com/apache/spark/pull/19747.diff","patch_url":"https://github.com/apache/spark/pull/19747.patch"},"body":"## What changes were proposed in this pull request?\r\n* JIRA:  [SPARK-22431](https://issues.apache.org/jira/browse/SPARK-22431)  : Creating Permanent view with illegal type\r\n\r\n**Description:** \r\n- It is possible in Spark SQL to create a permanent view that uses an nested field with an illegal name.\r\n- For example if we create the following view:\r\n```create view x as select struct('a' as `$q`, 1 as b) q```\r\n- A simple select fails with the following exception:\r\n\r\n```\r\nselect * from x;\r\n\r\norg.apache.spark.SparkException: Cannot recognize hive type string: struct<$q:string,b:int>\r\n  at org.apache.spark.sql.hive.client.HiveClientImpl$.fromHiveColumn(HiveClientImpl.scala:812)\r\n  at org.apache.spark.sql.hive.client.HiveClientImpl$$anonfun$getTableOption$1$$anonfun$apply$11$$anonfun$7.apply(HiveClientImpl.scala:378)\r\n  at org.apache.spark.sql.hive.client.HiveClientImpl$$anonfun$getTableOption$1$$anonfun$apply$11$$anonfun$7.apply(HiveClientImpl.scala:378)\r\n...\r\n```\r\n**Issue/Analysis**: Right now, we can create a view with a schema that cannot be read back by Spark from the Hive metastore.  For more details, please see the discussion about the analysis and proposed fix options in comment 1 and comment 2 in the [SPARK-22431](https://issues.apache.org/jira/browse/SPARK-22431) \r\n\r\n**Proposed changes**: \r\n - Fix the hive table/view codepath to check whether the schema datatype is parseable by Spark before persisting it in the metastore. This change is localized to HiveClientImpl to do the check similar to the check in FromHiveColumn. This is fail-fast and we will avoid the scenario where we write something to the metastore that we are unable to read it back.  \r\n- Added new unit tests\r\n- Ran the sql related unit test suites ( hive/test, sql/test, catalyst/test) OK\r\n\r\nWith the fix: \r\n```\r\ncreate view x as select struct('a' as `$q`, 1 as b) q;\r\n17/11/14 19:16:03 ERROR SparkSQLDriver: Failed in [create view x as select struct('a' as `$q`, 1 as b) q]\r\norg.apache.spark.SparkException: Cannot recognize the data type: struct<$q:string,b:int>\r\n\tat org.apache.spark.sql.hive.client.HiveClientImpl$$anonfun$org$apache$spark$sql$hive$client$HiveClientImpl$$verifyColumnDataType$1.apply(HiveClientImpl.scala:907)\r\n\tat org.apache.spark.sql.hive.client.HiveClientImpl$$anonfun$org$apache$spark$sql$hive$client$HiveClientImpl$$verifyColumnDataType$1.apply(HiveClientImpl.scala:901)\r\n\tat scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)\r\n\tat scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)\r\n```\r\n## How was this patch tested?\r\n- New unit tests have been added. \r\n\r\n@hvanhovell, Please review and share your thoughts/comments.  Thank you so much."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/344497917","html_url":"https://github.com/apache/spark/pull/19747#issuecomment-344497917","issue_url":"https://api.github.com/repos/apache/spark/issues/19747","id":344497917,"user":{"login":"AmplabJenkins","id":4031291,"avatar_url":"https://avatars3.githubusercontent.com/u/4031291?v=4","gravatar_id":"","url":"https://api.github.com/users/AmplabJenkins","html_url":"https://github.com/AmplabJenkins","followers_url":"https://api.github.com/users/AmplabJenkins/followers","following_url":"https://api.github.com/users/AmplabJenkins/following{/other_user}","gists_url":"https://api.github.com/users/AmplabJenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/AmplabJenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AmplabJenkins/subscriptions","organizations_url":"https://api.github.com/users/AmplabJenkins/orgs","repos_url":"https://api.github.com/users/AmplabJenkins/repos","events_url":"https://api.github.com/users/AmplabJenkins/events{/privacy}","received_events_url":"https://api.github.com/users/AmplabJenkins/received_events","type":"User","site_admin":false},"created_at":"2017-11-15T06:25:33Z","updated_at":"2017-11-15T06:25:33Z","author_association":"NONE","body":"Merged build finished. Test PASSed."}}
{"actor":{"display_login":"AmplabJenkins"}}