Skip to content

[SPARK-13976][SQL] do not remove sub-queries added by user when generate SQL #11786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

We haven't figured out the corrected logical to add sub-queries yet, so we should not clear all sub-queries before generate SQL. This PR changed the logic to only remove sub-queries above table relation.

an example for this bug, original SQL: SELECT a FROM (SELECT a FROM tbl) t WHERE a = 1
before this PR, we will generate:

SELECT attr_1 AS a FROM
  SELECT attr_1 FROM (
    SELECT a AS attr_1 FROM tbl 
  ) AS sub_q0
  WHERE attr_1 = 1

We missed a sub-query and this SQL string is illegal.

After this PR, we will generate:

SELECT attr_1 AS a FROM (
  SELECT attr_1 FROM (
    SELECT a AS attr_1 FROM tbl 
  ) AS sub_q0
  WHERE attr_1 = 1
) AS t

TODO: for long term, we should find a way to add sub-queries correctly, so that arbitrary logical plans can be converted to SQL string.

How was this patch tested?

LogicalPlanToSQLSuite

@cloud-fan
Copy link
Contributor Author

cc @liancheng @yhuai

@SparkQA
Copy link

SparkQA commented Mar 17, 2016

Test build #53435 has finished for PR 11786 at commit ee5a437.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@yhuai
Copy link
Contributor

yhuai commented Mar 17, 2016

How about we add a before/after comparison in the description (show the difference of the generated query)?

@yhuai
Copy link
Contributor

yhuai commented Mar 18, 2016

LGTM

@cloud-fan
Copy link
Contributor Author

merging to master!

@asfgit asfgit closed this in 6037ed0 Mar 18, 2016
roygao94 pushed a commit to roygao94/spark that referenced this pull request Mar 22, 2016
…ate SQL

## What changes were proposed in this pull request?

We haven't figured out the corrected logical to add sub-queries yet, so we should not clear all sub-queries before generate SQL. This PR changed the logic to only remove sub-queries above table relation.

an example for this bug, original SQL: `SELECT a FROM (SELECT a FROM tbl) t WHERE a = 1`
before this PR, we will generate:
```
SELECT attr_1 AS a FROM
  SELECT attr_1 FROM (
    SELECT a AS attr_1 FROM tbl
  ) AS sub_q0
  WHERE attr_1 = 1
```
We missed a sub-query and this SQL string is illegal.

After this PR, we will generate:
```
SELECT attr_1 AS a FROM (
  SELECT attr_1 FROM (
    SELECT a AS attr_1 FROM tbl
  ) AS sub_q0
  WHERE attr_1 = 1
) AS t
```

TODO: for long term, we should find a way to add sub-queries correctly, so that arbitrary logical plans can be converted to SQL string.

## How was this patch tested?

`LogicalPlanToSQLSuite`

Author: Wenchen Fan <wenchen@databricks.com>

Closes apache#11786 from cloud-fan/bug-fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants