{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/15546","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/15546/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/15546/comments","events_url":"https://api.github.com/repos/apache/spark/issues/15546/events","html_url":"https://github.com/apache/spark/pull/15546","id":183858698,"number":15546,"title":"[SPARK-17982][SQL] SQLBuilder should wrap the generated SQL with parenthesis for LIMIT","user":{"login":"dongjoon-hyun","id":9700541,"avatar_url":"https://avatars.githubusercontent.com/u/9700541?v=3","gravatar_id":"","url":"https://api.github.com/users/dongjoon-hyun","html_url":"https://github.com/dongjoon-hyun","followers_url":"https://api.github.com/users/dongjoon-hyun/followers","following_url":"https://api.github.com/users/dongjoon-hyun/following{/other_user}","gists_url":"https://api.github.com/users/dongjoon-hyun/gists{/gist_id}","starred_url":"https://api.github.com/users/dongjoon-hyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongjoon-hyun/subscriptions","organizations_url":"https://api.github.com/users/dongjoon-hyun/orgs","repos_url":"https://api.github.com/users/dongjoon-hyun/repos","events_url":"https://api.github.com/users/dongjoon-hyun/events{/privacy}","received_events_url":"https://api.github.com/users/dongjoon-hyun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-10-19T03:43:12Z","updated_at":"2016-10-19T09:32:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15546","html_url":"https://github.com/apache/spark/pull/15546","diff_url":"https://github.com/apache/spark/pull/15546.diff","patch_url":"https://github.com/apache/spark/pull/15546.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nCurrently, `SQLBuilder` handles `LIMIT` by always adding `LIMIT` at the end of the generated subSQL. It makes `RuntimeException`s like the following. This PR adds a parenthesis if the subquery expression is a `Project`.\r\n\r\n**Before**\r\n```scala\r\nscala> sql(\"CREATE TABLE tbl(id INT)\")\r\nscala> sql(\"CREATE VIEW v1(id2) AS SELECT id FROM tbl LIMIT 2\")\r\njava.lang.RuntimeException: Failed to analyze the canonicalized SQL: ...\r\n```\r\n\r\n**After**\r\n```scala\r\nscala> sql(\"CREATE TABLE tbl(id INT)\")\r\nscala> sql(\"CREATE VIEW v1(id2) AS SELECT id FROM tbl LIMIT 2\")\r\nscala> sql(\"SELECT id2 FROM v1\")\r\nres4: org.apache.spark.sql.DataFrame = [id2: int]\r\n```\r\n\r\n## How was this patch tested?\r\n\r\nPass the Jenkins test with a newly added test case."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/254762572","html_url":"https://github.com/apache/spark/pull/15546#issuecomment-254762572","issue_url":"https://api.github.com/repos/apache/spark/issues/15546","id":254762572,"user":{"login":"SparkQA","id":8108735,"avatar_url":"https://avatars.githubusercontent.com/u/8108735?v=3","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2016-10-19T09:32:32Z","updated_at":"2016-10-19T09:32:32Z","body":"**[Test build #67185 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/67185/consoleFull)** for PR 15546 at commit [`05d9475`](https://github.com/apache/spark/commit/05d947586218605e61c62e420e3f0064f05f5ce5)."}}
{"actor":{"display_login":"SparkQA"}}