Skip to content
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

[SPARK-10960][SQL] SQL with windowing function should be able to refer column in inner select #9011

Closed
wants to merge 2 commits into from

Conversation

viirya
Copy link
Member

@viirya viirya commented Oct 7, 2015

JIRA: https://issues.apache.org/jira/browse/SPARK-10960

When accessing a column in inner select from a select with window function, AnalysisException will be thrown. For example, an query like this:

 select area, rank() over (partition by area order by tmp.month) + tmp.tmp1 as c1 from (select month, area, product, 1 as tmp1 from windowData) tmp

Currently, the rule ExtractWindowExpressions in Analyzer only extracts regular expressions from WindowFunction, WindowSpecDefinition and AggregateExpression. We need to also extract other attributes as the one in Alias as shown in the above query.

@SparkQA
Copy link

SparkQA commented Oct 7, 2015

Test build #43331 has finished for PR 9011 at commit 15b40ee.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
    • class AFTSurvivalRegression(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredictionCol,
    • class AFTSurvivalRegressionModel(JavaModel):

@rxin
Copy link
Contributor

rxin commented Oct 8, 2015

cc @cloud-fan can you take a look at this?

@cloud-fan
Copy link
Contributor

Hi @viirya , can you add more description about the reason of this bug? e.g. why does this bug exist and how do you handle it, so that other people can understand your fix easily. Thanks!

@viirya
Copy link
Member Author

viirya commented Oct 9, 2015

@cloud-fan Thanks for suggesting. I've updated it.

case e: NamedExpression => extractExpr(e)
})
ne

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A one-line change can fix this and pass your test: case attr: Attribute => extractExpr(attr)

I think the missing case is Attribute, not Alias.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've updated it according to your suggestion.

@SparkQA
Copy link

SparkQA commented Oct 10, 2015

Test build #43507 has finished for PR 9011 at commit 23f106d.

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

@viirya
Copy link
Member Author

viirya commented Oct 11, 2015

ping @cloud-fan Any other comments?

@cloud-fan
Copy link
Contributor

cc @yhuai to take another look.

@yhuai
Copy link
Contributor

yhuai commented Oct 12, 2015

LGTM. @viirya Thank you for fixing this bug.

@yhuai
Copy link
Contributor

yhuai commented Oct 12, 2015

Merging to master and 1.5 branch.

WindowData(5, "c", 9),
WindowData(6, "c", 10)
)
sparkContext.parallelize(data).toDF().registerTempTable("windowData")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, you can use withTempTable in future to let our test infra automatically drop the temp table created at here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for suggesting it.

@asfgit asfgit closed this in fcb37a0 Oct 12, 2015
asfgit pushed a commit that referenced this pull request Oct 12, 2015
…er column in inner select

JIRA: https://issues.apache.org/jira/browse/SPARK-10960

When accessing a column in inner select from a select with window function, `AnalysisException` will be thrown. For example, an query like this:

     select area, rank() over (partition by area order by tmp.month) + tmp.tmp1 as c1 from (select month, area, product, 1 as tmp1 from windowData) tmp

Currently, the rule `ExtractWindowExpressions` in `Analyzer` only extracts regular expressions from `WindowFunction`, `WindowSpecDefinition` and `AggregateExpression`. We need to also extract other attributes as the one in `Alias` as shown in the above query.

Author: Liang-Chi Hsieh <viirya@appier.com>

Closes #9011 from viirya/fix-window-inner-column.

(cherry picked from commit fcb37a0)
Signed-off-by: Yin Huai <yhuai@databricks.com>
asfgit pushed a commit that referenced this pull request Oct 12, 2015
…er column in inner select

JIRA: https://issues.apache.org/jira/browse/SPARK-10960

When accessing a column in inner select from a select with window function, `AnalysisException` will be thrown. For example, an query like this:

     select area, rank() over (partition by area order by tmp.month) + tmp.tmp1 as c1 from (select month, area, product, 1 as tmp1 from windowData) tmp

Currently, the rule `ExtractWindowExpressions` in `Analyzer` only extracts regular expressions from `WindowFunction`, `WindowSpecDefinition` and `AggregateExpression`. We need to also extract other attributes as the one in `Alias` as shown in the above query.

Author: Liang-Chi Hsieh <viirya@appier.com>

Closes #9011 from viirya/fix-window-inner-column.

(cherry picked from commit fcb37a0)
Signed-off-by: Yin Huai <yhuai@databricks.com>
@viirya viirya deleted the fix-window-inner-column branch December 27, 2023 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants