{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/14207","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/14207/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/14207/comments","events_url":"https://api.github.com/repos/apache/spark/issues/14207/events","html_url":"https://github.com/apache/spark/pull/14207","id":165647960,"number":14207,"title":"[SPARK-16552] [SQL] Store the Inferred Schemas into External Catalog Tables when Creating Tables","user":{"login":"gatorsmile","id":11567269,"avatar_url":"https://avatars.githubusercontent.com/u/11567269?v=3","gravatar_id":"","url":"https://api.github.com/users/gatorsmile","html_url":"https://github.com/gatorsmile","followers_url":"https://api.github.com/users/gatorsmile/followers","following_url":"https://api.github.com/users/gatorsmile/following{/other_user}","gists_url":"https://api.github.com/users/gatorsmile/gists{/gist_id}","starred_url":"https://api.github.com/users/gatorsmile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatorsmile/subscriptions","organizations_url":"https://api.github.com/users/gatorsmile/orgs","repos_url":"https://api.github.com/users/gatorsmile/repos","events_url":"https://api.github.com/users/gatorsmile/events{/privacy}","received_events_url":"https://api.github.com/users/gatorsmile/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":23,"created_at":"2016-07-14T20:11:40Z","updated_at":"2016-07-25T08:17:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/14207","html_url":"https://github.com/apache/spark/pull/14207","diff_url":"https://github.com/apache/spark/pull/14207.diff","patch_url":"https://github.com/apache/spark/pull/14207.patch"},"body":"#### What changes were proposed in this pull request?\r\n\r\nCurrently, in Spark SQL, the initial creation of schema can be classified into two groups. It is applicable to both Hive tables and Data Source tables:\r\n\r\n**Group A. Users specify the schema.** \r\n\r\n_Case 1 CREATE TABLE AS SELECT_: the schema is determined by the result schema of the SELECT clause. For example,\r\n```SQL\r\nCREATE TABLE tab STORED AS TEXTFILE\r\nAS SELECT * from input\r\n```\r\n\r\n_Case 2 CREATE TABLE_: users explicitly specify the schema. For example,\r\n```SQL\r\nCREATE TABLE jsonTable (_1 string, _2 string)\r\nUSING org.apache.spark.sql.json\r\n```\r\n\r\n**Group B. Spark SQL infers the schema at runtime.**\r\n\r\n_Case 3 CREATE TABLE_. Users do not specify the schema but the path to the file location. For example,\r\n```SQL\r\nCREATE TABLE jsonTable \r\nUSING org.apache.spark.sql.json\r\nOPTIONS (path '${tempDir.getCanonicalPath}')\r\n```\r\n\r\nBefore this PR, Spark SQL does not store the inferred schema in the external catalog for the cases in Group B. When users refreshing the metadata cache, accessing the table at the first time after (re-)starting Spark, Spark SQL will infer the schema and store the info in the metadata cache for improving the performance of subsequent metadata requests. However, the runtime schema inference could cause undesirable schema changes after each reboot of Spark.\r\n\r\nThis PR is to store the inferred schema in the external catalog when creating the table. When users intend to refresh the schema after possible changes on external files (table location), they issue `REFRESH TABLE`. Spark SQL will infer the schema again based on the previously specified table location and update/refresh the schema in the external catalog and metadata cache. \r\n\r\nIn this PR, we do not use the inferred schema to replace the user specified schema for avoiding external behavior changes . Based on the design, user-specified schemas (as described in Group A) can be changed by ALTER TABLE commands, although we do not support them now. \r\n\r\n\r\n#### How was this patch tested?\r\nTODO: add more cases to cover the changes."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/234881171","html_url":"https://github.com/apache/spark/pull/14207#issuecomment-234881171","issue_url":"https://api.github.com/repos/apache/spark/issues/14207","id":234881171,"user":{"login":"cloud-fan","id":3182036,"avatar_url":"https://avatars.githubusercontent.com/u/3182036?v=3","gravatar_id":"","url":"https://api.github.com/users/cloud-fan","html_url":"https://github.com/cloud-fan","followers_url":"https://api.github.com/users/cloud-fan/followers","following_url":"https://api.github.com/users/cloud-fan/following{/other_user}","gists_url":"https://api.github.com/users/cloud-fan/gists{/gist_id}","starred_url":"https://api.github.com/users/cloud-fan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloud-fan/subscriptions","organizations_url":"https://api.github.com/users/cloud-fan/orgs","repos_url":"https://api.github.com/users/cloud-fan/repos","events_url":"https://api.github.com/users/cloud-fan/events{/privacy}","received_events_url":"https://api.github.com/users/cloud-fan/received_events","type":"User","site_admin":false},"created_at":"2016-07-25T08:17:17Z","updated_at":"2016-07-25T08:17:17Z","body":"retest this please"}}
{"actor":{"display_login":"cloud-fan"}}