Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,10 @@ class Analyzer(
val withName = Alias(agg, s"_w${extractedExprBuffer.length}")()
extractedExprBuffer += withName
withName.toAttribute

// Extracts other attributes
case attr: Attribute => extractExpr(attr)

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.

}.asInstanceOf[NamedExpression]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,33 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
).map(i => Row(i._1, i._2, i._3)))
}

test("window function: refer column in inner select block") {
val data = Seq(
WindowData(1, "a", 5),
WindowData(2, "a", 6),
WindowData(3, "b", 7),
WindowData(4, "b", 8),
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.


checkAnswer(
sql(
"""
|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
""".stripMargin),
Seq(
("a", 2),
("a", 3),
("b", 2),
("b", 3),
("c", 2),
("c", 3)
).map(i => Row(i._1, i._2)))
}

test("window function: partition and order expressions") {
val data = Seq(
WindowData(1, "a", 5),
Expand Down